{"version":3,"sources":["../../../src/singlestore-core/query-builders/select.types.ts"],"sourcesContent":["import type {\n\tSelectedFields as SelectedFieldsBase,\n\tSelectedFieldsFlat as SelectedFieldsFlatBase,\n\tSelectedFieldsOrdered as SelectedFieldsOrderedBase,\n} from '~/operations.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type {\n\tAppendToNullabilityMap,\n\tAppendToResult,\n\tBuildSubquerySelection,\n\tGetSelectTableName,\n\tJoinNullability,\n\tJoinType,\n\tMapColumnsToTableAlias,\n\tSelectMode,\n\tSelectResult,\n\tSetOperator,\n} from '~/query-builders/select.types.ts';\nimport type { SingleStoreColumn } from '~/singlestore-core/columns/index.ts';\nimport type { SingleStoreTable, SingleStoreTableWithColumns } from '~/singlestore-core/table.ts';\nimport type { ColumnsSelection, Placeholder, SQL, View } from '~/sql/sql.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport type { Table, UpdateTableConfig } from '~/table.ts';\nimport type { Assume, ValidateShape } from '~/utils.ts';\nimport type { PreparedQueryHKTBase, PreparedQueryKind, SingleStorePreparedQueryConfig } from '../session.ts';\n/* import type { SingleStoreViewBase } from '../view-base.ts'; */\n/* import type { SingleStoreViewWithSelection } from '../view.ts'; */\nimport type { SingleStoreSelectBase, SingleStoreSelectQueryBuilderBase } from './select.ts';\n\nexport interface SingleStoreSelectJoinConfig {\n\ton: SQL | undefined;\n\ttable: SingleStoreTable | Subquery | SQL; // SingleStoreViewBase |\n\talias: string | undefined;\n\tjoinType: JoinType;\n\tlateral?: boolean;\n}\n\nexport type BuildAliasTable = TTable extends Table\n\t? SingleStoreTableWithColumns<\n\t\tUpdateTableConfig;\n\t\t}>\n\t>\n\t/* : TTable extends View ? SingleStoreViewWithSelection<\n\t\t\tTAlias,\n\t\t\tTTable['_']['existing'],\n\t\t\tMapColumnsToTableAlias\n\t\t> */\n\t: never;\n\nexport interface SingleStoreSelectConfig {\n\twithList?: Subquery[];\n\tfields: Record;\n\tfieldsFlat?: SelectedFieldsOrdered;\n\twhere?: SQL;\n\thaving?: SQL;\n\ttable: SingleStoreTable | Subquery | SQL; // | SingleStoreViewBase\n\tlimit?: number | Placeholder;\n\toffset?: number | Placeholder;\n\tjoins?: SingleStoreSelectJoinConfig[];\n\torderBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\tgroupBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\tlockingClause?: {\n\t\tstrength: LockStrength;\n\t\tconfig: LockConfig;\n\t};\n\tdistinct?: boolean;\n\tsetOperators: {\n\t\trightSelect: TypedQueryBuilder;\n\t\ttype: SetOperator;\n\t\tisAll: boolean;\n\t\torderBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\t\tlimit?: number | Placeholder;\n\t\toffset?: number | Placeholder;\n\t}[];\n}\n\nexport type SingleStoreJoin<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tTJoinType extends JoinType,\n\tTJoinedTable extends SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase\n\tTJoinedName extends GetSelectTableName = GetSelectTableName,\n> = T extends any ? SingleStoreSelectWithout<\n\t\tSingleStoreSelectKind<\n\t\t\tT['_']['hkt'],\n\t\t\tT['_']['tableName'],\n\t\t\tAppendToResult<\n\t\t\t\tT['_']['tableName'],\n\t\t\t\tT['_']['selection'],\n\t\t\t\tTJoinedName,\n\t\t\t\tTJoinedTable extends SingleStoreTable ? TJoinedTable['_']['columns']\n\t\t\t\t\t: TJoinedTable extends Subquery ? Assume\n\t\t\t\t\t: never,\n\t\t\t\tT['_']['selectMode']\n\t\t\t>,\n\t\t\tT['_']['selectMode'] extends 'partial' ? T['_']['selectMode'] : 'multiple',\n\t\t\tT['_']['preparedQueryHKT'],\n\t\t\tAppendToNullabilityMap,\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods']\n\t\t>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>\n\t: never;\n\nexport type SingleStoreJoinFn<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tTJoinType extends JoinType,\n\tTIsLateral extends boolean,\n> = <\n\tTJoinedTable extends (TIsLateral extends true ? Subquery | SQL\n\t\t: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),\n\tTJoinedName extends GetSelectTableName = GetSelectTableName,\n>(\n\ttable: TJoinedTable,\n\ton: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,\n) => SingleStoreJoin;\n\nexport type SingleStoreCrossJoinFn<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tTIsLateral extends boolean,\n> = <\n\tTJoinedTable extends (TIsLateral extends true ? Subquery | SQL\n\t\t: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),\n\tTJoinedName extends GetSelectTableName = GetSelectTableName,\n>(table: TJoinedTable) => SingleStoreJoin;\n\nexport type SelectedFieldsFlat = SelectedFieldsFlatBase;\n\nexport type SelectedFields = SelectedFieldsBase;\n\nexport type SelectedFieldsOrdered = SelectedFieldsOrderedBase;\n\nexport type LockStrength = 'update' | 'share';\n\nexport type LockConfig = {\n\tnoWait: true;\n\tskipLocked?: undefined;\n} | {\n\tnoWait?: undefined;\n\tskipLocked: true;\n} | {\n\tnoWait?: undefined;\n\tskipLocked?: undefined;\n};\n\nexport interface SingleStoreSelectHKTBase {\n\ttableName: string | undefined;\n\tselection: unknown;\n\tselectMode: SelectMode;\n\tpreparedQueryHKT: unknown;\n\tnullabilityMap: unknown;\n\tdynamic: boolean;\n\texcludedMethods: string;\n\tresult: unknown;\n\tselectedFields: unknown;\n\t_type: unknown;\n}\n\nexport type SingleStoreSelectKind<\n\tT extends SingleStoreSelectHKTBase,\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record,\n\tTDynamic extends boolean,\n\tTExcludedMethods extends string,\n\tTResult = SelectResult[],\n\tTSelectedFields = BuildSubquerySelection,\n> = (T & {\n\ttableName: TTableName;\n\tselection: TSelection;\n\tselectMode: TSelectMode;\n\tpreparedQueryHKT: TPreparedQueryHKT;\n\tnullabilityMap: TNullabilityMap;\n\tdynamic: TDynamic;\n\texcludedMethods: TExcludedMethods;\n\tresult: TResult;\n\tselectedFields: TSelectedFields;\n})['_type'];\n\nexport interface SingleStoreSelectQueryBuilderHKT extends SingleStoreSelectHKTBase {\n\t_type: SingleStoreSelectQueryBuilderBase<\n\t\tSingleStoreSelectQueryBuilderHKT,\n\t\tthis['tableName'],\n\t\tAssume,\n\t\tthis['selectMode'],\n\t\tAssume,\n\t\tAssume>,\n\t\tthis['dynamic'],\n\t\tthis['excludedMethods'],\n\t\tAssume,\n\t\tAssume\n\t>;\n}\n\nexport interface SingleStoreSelectHKT extends SingleStoreSelectHKTBase {\n\t_type: SingleStoreSelectBase<\n\t\tthis['tableName'],\n\t\tAssume,\n\t\tthis['selectMode'],\n\t\tAssume,\n\t\tAssume>,\n\t\tthis['dynamic'],\n\t\tthis['excludedMethods'],\n\t\tAssume,\n\t\tAssume\n\t>;\n}\n\nexport type SingleStoreSetOperatorExcludedMethods =\n\t| 'where'\n\t| 'having'\n\t| 'groupBy'\n\t| 'session'\n\t| 'leftJoin'\n\t| 'rightJoin'\n\t| 'innerJoin'\n\t| 'fullJoin'\n\t| 'for';\n\nexport type SingleStoreSelectWithout<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n\tTResetExcluded extends boolean = false,\n> = TDynamic extends true ? T : Omit<\n\tSingleStoreSelectKind<\n\t\tT['_']['hkt'],\n\t\tT['_']['tableName'],\n\t\tT['_']['selection'],\n\t\tT['_']['selectMode'],\n\t\tT['_']['preparedQueryHKT'],\n\t\tT['_']['nullabilityMap'],\n\t\tTDynamic,\n\t\tTResetExcluded extends true ? K : T['_']['excludedMethods'] | K,\n\t\tT['_']['result'],\n\t\tT['_']['selectedFields']\n\t>,\n\tTResetExcluded extends true ? K : T['_']['excludedMethods'] | K\n>;\n\nexport type SingleStoreSelectPrepare = PreparedQueryKind<\n\tT['_']['preparedQueryHKT'],\n\tSingleStorePreparedQueryConfig & {\n\t\texecute: T['_']['result'];\n\t\titerator: T['_']['result'][number];\n\t},\n\ttrue\n>;\n\nexport type SingleStoreSelectDynamic = SingleStoreSelectKind<\n\tT['_']['hkt'],\n\tT['_']['tableName'],\n\tT['_']['selection'],\n\tT['_']['selectMode'],\n\tT['_']['preparedQueryHKT'],\n\tT['_']['nullabilityMap'],\n\ttrue,\n\tnever,\n\tT['_']['result'],\n\tT['_']['selectedFields']\n>;\n\nexport type CreateSingleStoreSelectFromBuilderMode<\n\tTBuilderMode extends 'db' | 'qb',\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n> = TBuilderMode extends 'db' ? SingleStoreSelectBase\n\t: SingleStoreSelectQueryBuilderBase<\n\t\tSingleStoreSelectQueryBuilderHKT,\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT\n\t>;\n\nexport type SingleStoreSelectQueryBuilder<\n\tTHKT extends SingleStoreSelectHKTBase = SingleStoreSelectQueryBuilderHKT,\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = ColumnsSelection,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record = Record,\n\tTResult extends any[] = unknown[],\n\tTSelectedFields extends ColumnsSelection = ColumnsSelection,\n> = SingleStoreSelectQueryBuilderBase<\n\tTHKT,\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\ttrue,\n\tnever,\n\tTResult,\n\tTSelectedFields\n>;\n\nexport type AnySingleStoreSelectQueryBuilder = SingleStoreSelectQueryBuilderBase<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany\n>;\n\nexport type AnySingleStoreSetOperatorInterface = SingleStoreSetOperatorInterface<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany\n>;\n\nexport interface SingleStoreSetOperatorInterface<\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record = TTableName extends string ? Record\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection,\n> {\n\t_: {\n\t\treadonly hkt: SingleStoreSelectHKT;\n\t\treadonly tableName: TTableName;\n\t\treadonly selection: TSelection;\n\t\treadonly selectMode: TSelectMode;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly nullabilityMap: TNullabilityMap;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TResult;\n\t\treadonly selectedFields: TSelectedFields;\n\t};\n}\n\nexport type SingleStoreSetOperatorWithResult = SingleStoreSetOperatorInterface<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tTResult,\n\tany\n>;\n\nexport type SingleStoreSelect<\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = Record,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTNullabilityMap extends Record = Record,\n> = SingleStoreSelectBase;\n\nexport type AnySingleStoreSelect = SingleStoreSelectBase;\n\nexport type SingleStoreSetOperator<\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = Record,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record = Record,\n> = SingleStoreSelectBase<\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\ttrue,\n\tSingleStoreSetOperatorExcludedMethods\n>;\n\nexport type SetOperatorRightSelect<\n\tTValue extends SingleStoreSetOperatorWithResult,\n\tTResult extends any[],\n> = TValue extends SingleStoreSetOperatorInterface\n\t? ValidateShape<\n\t\tTValueResult[number],\n\t\tTResult[number],\n\t\tTypedQueryBuilder\n\t>\n\t: TValue;\n\nexport type SetOperatorRestSelect<\n\tTValue extends readonly SingleStoreSetOperatorWithResult[],\n\tTResult extends any[],\n> = TValue extends [infer First, ...infer Rest]\n\t? First extends SingleStoreSetOperatorInterface\n\t\t? Rest extends AnySingleStoreSetOperatorInterface[] ? [\n\t\t\t\tValidateShape>,\n\t\t\t\t...SetOperatorRestSelect,\n\t\t\t]\n\t\t: ValidateShape[]>\n\t: never\n\t: TValue;\n\nexport type SingleStoreCreateSetOperatorFn = <\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTValue extends SingleStoreSetOperatorWithResult,\n\tTRest extends SingleStoreSetOperatorWithResult[],\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record = TTableName extends string ? Record\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection,\n>(\n\tleftSelect: SingleStoreSetOperatorInterface<\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\trightSelect: SetOperatorRightSelect,\n\t...restSelects: SetOperatorRestSelect\n) => SingleStoreSelectWithout<\n\tSingleStoreSelectBase<\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\tfalse,\n\tSingleStoreSetOperatorExcludedMethods,\n\ttrue\n>;\n\nexport type GetSingleStoreSetOperators = {\n\tunion: SingleStoreCreateSetOperatorFn;\n\tintersect: SingleStoreCreateSetOperatorFn;\n\texcept: SingleStoreCreateSetOperatorFn;\n\tunionAll: SingleStoreCreateSetOperatorFn;\n\tminus: SingleStoreCreateSetOperatorFn;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}