import { type HasQuery, type HasSelection, type HasSql, type HasTarget, internalData, internalQuery, internalSelection, internalSql } from '../Internal.js'; import type { IsMysql, IsPostgres, QueryMeta } from '../MetaData.js'; import { type QueryData, SingleQuery } from '../Queries.js'; import { type IsNullable, type MakeNullable, type Selection, type SelectionRecord, type SelectionRow } from '../Selection.js'; import { Sql } from '../Sql.js'; import type { Table, TableDefinition, TableFields } from '../Table.js'; import type { Expand } from '../Types.js'; import type { Field, StripFieldMeta } from '../expr/Field.js'; import type { Input as UserInput } from '../expr/Input.js'; import { type CTE } from './CTE.js'; import type { CompoundSelect, SelectQuery, UnionQuery } from './Query.js'; type UnionTarget = UnionBase | ((self: Input & HasTarget) => UnionBase); export declare class SelectFirst extends SingleQuery, Meta> implements HasQuery> { readonly [internalData]: QueryData & SelectQuery; constructor(data: QueryData & SelectQuery); get [internalSelection](): Selection; get [internalQuery](): Sql>; get [internalSql](): Sql>; } export declare abstract class UnionBase extends SingleQuery>, Meta> implements HasSelection { #private; readonly [internalData]: QueryData; abstract [internalSelection]: Selection; constructor(data: QueryData & { compound: CompoundSelect; }); as(alias: Name): SubQuery; union(target: UnionTarget): Union; unionAll(target: UnionTarget): Union; intersect(target: UnionTarget): Union; intersectAll(this: UnionBase, target: UnionTarget): Union; except(target: UnionTarget): Union; exceptAll(this: UnionBase, target: UnionTarget): Union; } export declare class Select extends UnionBase, Meta> implements HasSelection, SelectBase, HasQuery>> { #private; readonly [internalData]: QueryData & SelectQuery; constructor(data: QueryData & SelectQuery); from(from: HasTarget | Sql): Select; leftJoin(leftJoin: HasTarget | Sql, on: HasSql): Select; rightJoin(rightJoin: HasTarget | Sql, on: HasSql): Select; innerJoin(innerJoin: HasTarget | Sql, on: HasSql): Select; fullJoin(fullJoin: HasTarget | Sql, on: HasSql): Select; crossJoin(crossJoin: HasTarget | Sql, on: HasSql): Select; where(...where: Array | undefined>): Select; groupBy(...groupBy: Array): Select; having(having: HasSql | ((self: Input) => HasSql)): Select; orderBy(...orderBy: Array): Select; limit(limit: UserInput): Select; offset(offset: UserInput): Select; $dynamic(): this; $first(): SelectFirst; get [internalSelection](): Selection; get [internalQuery](): Sql>>; get [internalSql](): Sql>; } export type SubQuery = Input & HasTarget & HasSelection; export interface SelectBase extends UnionBase, Meta>, HasSql> { where(...where: Array | undefined>): Select; groupBy(...exprs: Array): Select; having(having: HasSql): Select; orderBy(...exprs: Array): Select; limit(limit: UserInput): Select; offset(offset: UserInput): Select; $dynamic(): this; } export interface WithoutSelection { from(from: Table): AllFrom, Meta, Record>>; from(from: SubQuery): SelectionFrom; from(from: CTE): SelectionFrom; } export interface WithSelection extends SelectBase, HasSql> { from(from: Table): SelectionFrom; from(from: HasTarget): SelectionFrom; from(from: SubQuery): SelectionFrom; from(from: HasSql): Select; } export interface AllFrom extends SelectBase { leftJoin(right: Table, on: HasSql): AllFrom>>>, Meta>; leftJoin(right: SubQuery, on: HasSql): AllFrom>>, Meta>; rightJoin(right: Table, on: HasSql): AllFrom & Record>>, Meta>; rightJoin(right: SubQuery, on: HasSql): AllFrom & Record>, Meta>; innerJoin(right: Table, on: HasSql): AllFrom>>, Meta>; innerJoin(right: SubQuery, on: HasSql): AllFrom>, Meta>; fullJoin(right: Table, on: HasSql): AllFrom & MakeNullable>>>, Meta>; fullJoin(right: SubQuery, on: HasSql): AllFrom & MakeNullable>>, Meta>; } type MarkFieldsAsNullable = Expand<{ [K in keyof Input]: Input[K] extends Field ? HasSql : Input[K] extends Table ? TableFields & IsNullable : Input[K] extends Record | HasSql> ? Input[K] & IsNullable : Input[K] extends SelectionRecord ? MarkFieldsAsNullable : Input[K]; }>; export interface SelectionFrom extends SelectBase { leftJoin(right: Table, on: HasSql): SelectionFrom, Meta>; leftJoin(right: HasTarget, on: HasSql): SelectionFrom; rightJoin(right: Table, on: HasSql): SelectionFrom; rightJoin(right: HasTarget, on: HasSql): SelectionFrom; innerJoin(right: Table, on: HasSql): SelectionFrom; innerJoin(right: HasTarget, on: HasSql): SelectionFrom; crossJoin(right: Table, on: HasSql): SelectionFrom; crossJoin(right: HasTarget, on: HasSql): SelectionFrom; fullJoin(right: Table, on: HasSql): SelectionFrom; fullJoin(right: HasTarget, on: HasSql): SelectionFrom; } export declare function querySelection({ select, from }: SelectQuery): Selection; export declare function selectQuery(query: SelectQuery): Sql; export declare class Union extends UnionBase implements HasSelection { readonly [internalData]: QueryData & UnionQuery; constructor(data: QueryData & UnionQuery); get [internalQuery](): Sql; get [internalSelection](): Selection; orderBy(...orderBy: Array): Union; limit(limit: UserInput): Union; offset(offset: UserInput): Union; } export declare function union(left: UnionBase, right: UnionBase, ...rest: Array>): Union; export declare function unionAll(left: UnionBase, right: UnionBase, ...rest: Array>): Union; export declare function intersect(left: UnionBase, right: UnionBase, ...rest: Array>): Union; export declare function intersectAll(left: UnionBase, right: UnionBase, ...rest: Array>): Union; export declare function except(left: UnionBase, right: UnionBase, ...rest: Array>): Union; export declare function exceptAll(left: UnionBase, right: UnionBase, ...rest: Array>): Union; export declare function unionQuery(query: UnionQuery): Sql; export {};