import type { ColumnsSelection, Placeholder, SQL, View } from "../../sql/sql.js"; import type { SQLiteColumn } from "../columns/index.js"; import type { SQLiteTable, SQLiteTableWithColumns } from "../table.js"; import type { Assume, ValidateShape } from "../../utils.js"; import type { SelectedFields as SelectFieldsBase, SelectedFieldsFlat as SelectFieldsFlatBase, SelectedFieldsOrdered as SelectFieldsOrderedBase } from "../../operations.js"; import type { TypedQueryBuilder } from "../../query-builders/query-builder.js"; import type { AppendToNullabilityMap, AppendToResult, BuildSubquerySelection, GetSelectTableName, JoinNullability, JoinType, MapColumnsToTableAlias, SelectMode, SelectResult, SetOperator } from "../../query-builders/select.types.js"; import type { Subquery } from "../../subquery.js"; import type { Table, UpdateTableConfig } from "../../table.js"; import type { SQLitePreparedQuery } from "../session.js"; import type { SQLiteViewBase } from "../view-base.js"; import type { SQLiteViewWithSelection } from "../view.js"; import type { SQLiteSelectBase, SQLiteSelectQueryBuilderBase } from "./select.js"; export interface SQLiteSelectJoinConfig { on: SQL | undefined; table: SQLiteTable | Subquery | SQLiteViewBase | SQL; alias: string | undefined; joinType: JoinType; } export type BuildAliasTable = TTable extends Table ? SQLiteTableWithColumns; }>> : TTable extends View ? SQLiteViewWithSelection> : never; export interface SQLiteSelectConfig { withList?: Subquery[]; fields: Record; fieldsFlat?: SelectedFieldsOrdered; where?: SQL; having?: SQL; table: SQLiteTable | Subquery | SQLiteViewBase | SQL; limit?: number | Placeholder; offset?: number | Placeholder; joins?: SQLiteSelectJoinConfig[]; orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[]; groupBy?: (SQLiteColumn | SQL | SQL.Aliased)[]; distinct?: boolean; setOperators: { rightSelect: TypedQueryBuilder; type: SetOperator; isAll: boolean; orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[]; limit?: number | Placeholder; offset?: number | Placeholder; }[]; } export type SQLiteSelectJoin = GetSelectTableName> = T extends any ? SQLiteSelectWithout : never, T['_']['selectMode']>, T['_']['selectMode'] extends 'partial' ? T['_']['selectMode'] : 'multiple', AppendToNullabilityMap, T['_']['dynamic'], T['_']['excludedMethods']>, TDynamic, T['_']['excludedMethods']> : never; export type SQLiteSelectJoinFn = = GetSelectTableName>(table: TJoinedTable, on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined) => SQLiteSelectJoin; export type SQLiteSelectCrossJoinFn = = GetSelectTableName>(table: TJoinedTable) => SQLiteSelectJoin; export type SelectedFieldsFlat = SelectFieldsFlatBase; export type SelectedFields = SelectFieldsBase; export type SelectedFieldsOrdered = SelectFieldsOrderedBase; export interface SQLiteSelectHKTBase { tableName: string | undefined; resultType: 'sync' | 'async'; runResult: unknown; selection: unknown; selectMode: SelectMode; nullabilityMap: unknown; dynamic: boolean; excludedMethods: string; result: unknown; selectedFields: unknown; _type: unknown; } export type SQLiteSelectKind, TDynamic extends boolean, TExcludedMethods extends string, TResult = SelectResult[], TSelectedFields = BuildSubquerySelection> = (T & { tableName: TTableName; resultType: TResultType; runResult: TRunResult; selection: TSelection; selectMode: TSelectMode; nullabilityMap: TNullabilityMap; dynamic: TDynamic; excludedMethods: TExcludedMethods; result: TResult; selectedFields: TSelectedFields; })['_type']; export interface SQLiteSelectQueryBuilderHKT extends SQLiteSelectHKTBase { _type: SQLiteSelectQueryBuilderBase, this['selectMode'], Assume>, this['dynamic'], this['excludedMethods'], Assume, Assume>; } export interface SQLiteSelectHKT extends SQLiteSelectHKTBase { _type: SQLiteSelectBase, this['selectMode'], Assume>, this['dynamic'], this['excludedMethods'], Assume, Assume>; } export type SQLiteSetOperatorExcludedMethods = 'config' | 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin' | 'where' | 'having' | 'groupBy'; export type CreateSQLiteSelectFromBuilderMode = TBuilderMode extends 'db' ? SQLiteSelectBase : SQLiteSelectQueryBuilderBase; export type SQLiteSelectWithout = TDynamic extends true ? T : Omit, TResetExcluded extends true ? K : T['_']['excludedMethods'] | K>; export type SQLiteSelectExecute = T['_']['result']; export type SQLiteSelectPrepare = SQLitePreparedQuery<{ type: T['_']['resultType']; run: T['_']['runResult']; all: T['_']['result']; get: T['_']['result'][number] | undefined; values: any[][]; execute: SQLiteSelectExecute; }>; export type SQLiteSelectDynamic = SQLiteSelectKind; export type SQLiteSelectQueryBuilder = Record, TResult extends any[] = unknown[], TSelectedFields extends ColumnsSelection = ColumnsSelection> = SQLiteSelectQueryBuilderBase; export type AnySQLiteSelectQueryBuilder = SQLiteSelectQueryBuilderBase; export type AnySQLiteSetOperatorInterface = SQLiteSetOperatorInterface; export interface SQLiteSetOperatorInterface = TTableName extends string ? Record : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection> { _: { readonly hkt: SQLiteSelectHKTBase; readonly tableName: TTableName; readonly resultType: TResultType; readonly runResult: TRunResult; readonly selection: TSelection; readonly selectMode: TSelectMode; readonly nullabilityMap: TNullabilityMap; readonly dynamic: TDynamic; readonly excludedMethods: TExcludedMethods; readonly result: TResult; readonly selectedFields: TSelectedFields; }; } export type SQLiteSetOperatorWithResult = SQLiteSetOperatorInterface; export type SQLiteSelect, TSelectMode extends SelectMode = SelectMode, TNullabilityMap extends Record = Record> = SQLiteSelectBase; export type AnySQLiteSelect = SQLiteSelectBase; export type SQLiteSetOperator, TSelectMode extends SelectMode = SelectMode, TNullabilityMap extends Record = Record> = SQLiteSelectBase; export type SetOperatorRightSelect, TResult extends any[]> = TValue extends SQLiteSetOperatorInterface ? ValidateShape> : TValue; export type SetOperatorRestSelect[], TResult extends any[]> = TValue extends [infer First, ...infer Rest] ? First extends SQLiteSetOperatorInterface ? Rest extends AnySQLiteSetOperatorInterface[] ? [ ValidateShape>, ...SetOperatorRestSelect ] : ValidateShape[]> : never : TValue; export type SQLiteCreateSetOperatorFn = , TRest extends SQLiteSetOperatorWithResult[], TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record = TTableName extends string ? Record : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection>(leftSelect: SQLiteSetOperatorInterface, rightSelect: SetOperatorRightSelect, ...restSelects: SetOperatorRestSelect) => SQLiteSelectWithout, false, SQLiteSetOperatorExcludedMethods, true>; export type GetSQLiteSetOperators = { union: SQLiteCreateSetOperatorFn; intersect: SQLiteCreateSetOperatorFn; except: SQLiteCreateSetOperatorFn; unionAll: SQLiteCreateSetOperatorFn; };