import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan'; import type { AggregateFunctions, Expression, ExpressionBuilder, ExtractScopeFields, FieldProxy, TraitExpression, WithField, WithFields, } from '../expression'; import type { ResolveRow } from '../resolve'; import type { EmptyRow, Expand, GatedMethod, JoinOuterScope, JoinSource, MergeScopes, NullableScope, QueryContext, Scope, ScopeField, ScopeTable, Subquery, } from '../scope'; import type { JoinedTables } from './joined-tables'; import type { SelectQuery } from './select-query'; export interface LateralBuilder { from>( other: Other, ): SelectQuery, EmptyRow>; } export interface WithSelect< QC extends QueryContext, AvailableScope extends Scope, RowType extends Record = EmptyRow, > { select( ...columns: Columns ): SelectQuery>; select( alias: Alias, expr: (fields: FieldProxy, fns: AggregateFunctions) => Expression, ): SelectQuery>; select>>( callback: (fields: FieldProxy, fns: AggregateFunctions) => Result, ): SelectQuery>>; } export interface WithJoin { innerJoin>( other: Other, on: ExpressionBuilder, QC>, ): JoinedTables>; outerLeftJoin>( other: Other, on: ExpressionBuilder, QC>, ): JoinedTables>>; outerRightJoin>( other: Other, on: ExpressionBuilder, QC>, ): JoinedTables, Other[typeof JoinOuterScope]>>; outerFullJoin>( other: Other, on: ExpressionBuilder, QC>, ): JoinedTables< QC, MergeScopes, NullableScope> >; lateralJoin: GatedMethod< Capabilities, { sql: { lateral: true } }, >( alias: Alias, builder: (lateral: LateralBuilder) => Subquery, ) => JoinedTables< QC, MergeScopes }> > >; outerLateralJoin: GatedMethod< Capabilities, { sql: { lateral: true } }, >( alias: Alias, builder: (lateral: LateralBuilder) => Subquery, ) => JoinedTables< QC, MergeScopes< AvailableScope, NullableScope<{ topLevel: LateralRow; namespaces: Record }> > > >; } export type PaginationValue = | number | TraitExpression; export interface WithPagination { limit(count: PaginationValue): this; offset(count: PaginationValue): this; } export interface WithDistinct { distinct(): this; } export interface WithAlias> { as(newAlias: Alias): JoinSource; } export interface WithBuild> { build(): SqlQueryPlan>; }