pqb 0.27.7 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as orchid_core from 'orchid-core';
2
- import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, QueryColumn, MaybeArray, SelectableBase, TemplateLiteralArgs, PickOutputTypeAndOperators, PickQueryResult, OperatorToSQL, ColumnsShapeBase, ColumnsParsers, RecordString, PickQueryTable, getValueKey, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, QueryCatch, PickQueryMetaShape, PickQueryTableMetaResultShape, QueryColumnBooleanOrNull, SQLQueryArgs, ColumnSchemaConfig, DateColumnData, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, StringTypeData, StaticSQLArgs, PickColumnBaseData, PrimaryKeyColumn, RawSQLBase, ColumnTypeBase, ForeignKeyTable, QueryColumnsInit, TimestampHelpers, ColumnNameOfTable, ConstraintOptions, BaseNumberData, ColumnWithDefault, ParseColumn, EncodeColumn, PickQueryMetaResult, ColumnShapeOutput, DefaultSelectColumns, CoreQueryScopes, DbBase, TransactionState, PickQueryMetaResultWindows, CoreBaseOperators, IsQuery, PickQueryMetaShapeResultReturnType, MergeObjects, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, QueryInternalBase, PickQueryReturnType, PickType, PickOutputType, Spread, ColumnDataCheckBase, PickQueryTableMetaShape } from 'orchid-core';
2
+ import { QueryResultRow, AdapterConfigBase, AdapterBase, QueryInput, Sql, RecordUnknown, RecordKeyTrue, EmptyObject, QueryBaseCommon, QueryColumns, QueryMetaBase, QueryReturnType, QueryThen, Expression, QueryColumn, MaybeArray, SelectableBase, TemplateLiteralArgs, PickOutputTypeAndOperators, PickQueryResult, OperatorToSQL, ColumnsShapeBase, ColumnsParsers, RecordString, PickQueryTable, getValueKey, PickQueryShape, PickQueryTableMetaResult, EmptyTuple, PickQueryMeta, PickQueryMetaResultReturnType, QueryColumnToNullable, PickQueryMetaShape, PickQueryTableMetaResultShape, QueryColumnBooleanOrNull, SQLQueryArgs, ColumnSchemaConfig, DateColumnData, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, StaticSQLArgs, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ParseColumn, EncodeColumn, PickQueryMetaResult, QueryColumnsInit, DefaultSelectColumns, CoreQueryScopes, DbBase, QueryCatch, TransactionState, ColumnTypeBase, PickQueryMetaResultWindows, CoreBaseOperators, PickQueryUniqueProperties, IsQuery, PickQueryMetaShapeResultReturnType, MergeObjects, PickQueryResultUniqueColumns, QueryInternalBase, PickQueryReturnType, PickType, ColumnShapeOutput, PickOutputType, Spread, UniqueColumn, TimestampHelpers, Codes, ColumnDataCheckBase, PickQueryTableMetaShape } from 'orchid-core';
3
3
  import { PoolConfig, Pool, PoolClient } from 'pg';
4
4
  import { inspect } from 'node:util';
5
5
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -54,7 +54,6 @@ declare class TransactionAdapter implements Adapter {
54
54
  close(): Promise<void>;
55
55
  }
56
56
 
57
- type RelationsChain = (Query | RelationQuery)[];
58
57
  type RelationJoinQuery = (joiningQuery: Query, baseQuery: Query) => Query;
59
58
  interface RelationConfigBase {
60
59
  query: Query;
@@ -185,7 +184,7 @@ type QuerySourceItem = {
185
184
  }) & ({
186
185
  text: string | Expression;
187
186
  } | {
188
- in: MaybeArray<string> | Record<string, SearchWeight>;
187
+ in: MaybeArray<string> | SearchWeightRecord;
189
188
  } | {
190
189
  vector: string;
191
190
  }) & ({
@@ -198,7 +197,9 @@ type QuerySourceItem = {
198
197
  tsQuery: string | Expression;
199
198
  });
200
199
  type JoinItem = SimpleJoinItem | JoinLateralItem;
201
- type SimpleJoinItemNonSubQueryArgs = [Record<string, string | Expression> | Expression | true] | [leftColumn: string | Expression, rightColumn: string | Expression] | [
200
+ type SimpleJoinItemNonSubQueryArgs = [{
201
+ [K: string]: string | Expression;
202
+ } | Expression | true] | [leftColumn: string | Expression, rightColumn: string | Expression] | [
202
203
  leftColumn: string | Expression,
203
204
  op: string,
204
205
  rightColumn: string | Expression
@@ -232,7 +233,9 @@ interface SimpleJoinItem {
232
233
  }
233
234
  type JoinLateralItem = [type: string, joined: Query, as: string];
234
235
  type WhereItem = {
235
- [K: string]: unknown | Record<string, unknown | Query | Expression> | Expression;
236
+ [K: string]: unknown | {
237
+ [K: string]: unknown | Query | Expression;
238
+ } | Expression;
236
239
  NOT?: MaybeArray<WhereItem>;
237
240
  AND?: MaybeArray<WhereItem>;
238
241
  OR?: MaybeArray<WhereItem>[];
@@ -263,25 +266,37 @@ type WhereOnJoinItem = {
263
266
  };
264
267
  } | string;
265
268
  type SearchWeight = 'A' | 'B' | 'C' | 'D';
269
+ type SearchWeightRecord = {
270
+ [K: string]: SearchWeight;
271
+ };
266
272
  interface WhereSearchItem {
267
273
  as: string;
268
274
  vectorSQL: string;
269
275
  }
270
276
  type SortDir = 'ASC' | 'DESC' | 'ASC NULLS FIRST' | 'DESC NULLS LAST';
271
- type OrderItem = string | Record<string, SortDir> | Expression;
277
+ type OrderItem = string | {
278
+ [K: string]: SortDir;
279
+ } | Expression;
272
280
  type ColumnOperators<S extends SelectableBase, Column extends keyof S> = {
273
281
  [O in keyof S[Column]['column']['operators']]?: S[Column]['column']['operators'][O]['_opType'];
274
282
  };
275
283
  type HavingItem = TemplateLiteralArgs | Expression[];
276
- type WindowItem = Record<string, WindowDeclaration | Expression>;
284
+ type WindowItem = {
285
+ [K: string]: WindowDeclaration | Expression;
286
+ };
277
287
  interface WindowDeclaration {
278
288
  partitionBy?: SelectableOrExpression | SelectableOrExpression[];
279
289
  order?: OrderItem;
280
290
  }
281
291
  type UnionItem = Query | Expression;
282
292
  type UnionKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'INTERSECT ALL' | 'EXCEPT' | 'EXCEPT ALL';
283
- type OnConflictItem = string | string[] | Expression;
284
- type OnConflictMergeUpdate = string | string[] | RecordUnknown | Expression;
293
+ type OnConflictTarget = string | string[] | Expression | {
294
+ constraint: string;
295
+ };
296
+ type OnConflictSet = RecordUnknown | Expression;
297
+ type OnConflictMerge = string | string[] | {
298
+ except: string | string[];
299
+ };
285
300
 
286
301
  interface Operator<Value, Column extends PickOutputTypeAndOperators = PickOutputTypeAndOperators> {
287
302
  <T extends PickQueryResult>(this: T, arg: Value): Omit<SetQueryReturnsColumnOrThrow<T, Column>, keyof T['result']['value']['operators']> & Column['operators'];
@@ -353,13 +368,20 @@ declare const Operators: {
353
368
  array: OperatorsArray;
354
369
  };
355
370
 
356
- type JoinedShapes = Record<string, ColumnsShapeBase>;
357
- type JoinedParsers = Record<string, ColumnsParsers>;
371
+ interface RecordOfColumnsShapeBase {
372
+ [K: string]: ColumnsShapeBase;
373
+ }
374
+ type JoinedShapes = RecordOfColumnsShapeBase;
375
+ interface JoinedParsers {
376
+ [K: string]: ColumnsParsers;
377
+ }
358
378
  type JoinOverrides = RecordString;
359
379
  type QueryBeforeHook = (query: Query) => void | Promise<void>;
360
380
  type QueryAfterHook<Data = unknown> = (data: Data, query: Query) => void | Promise<void>;
361
381
  type QueryHookSelect = string[];
362
- type QueryScopes = Record<string, QueryScopeData>;
382
+ interface QueryScopes {
383
+ [K: string]: QueryScopeData;
384
+ }
363
385
  type QueryScopeData = {
364
386
  and?: WhereItem[];
365
387
  or?: WhereItem[][];
@@ -375,7 +397,7 @@ type CommonQueryData = {
375
397
  wrapInTransaction?: boolean;
376
398
  throwOnNotFound?: boolean;
377
399
  with?: WithItem[];
378
- withShapes?: Record<string, ColumnsShapeBase>;
400
+ withShapes?: RecordOfColumnsShapeBase;
379
401
  joinTo?: QueryDataJoinTo;
380
402
  joinedShapes?: JoinedShapes;
381
403
  joinedParsers?: JoinedParsers;
@@ -387,7 +409,9 @@ type CommonQueryData = {
387
409
  expr?: Expression;
388
410
  as?: string;
389
411
  from?: string | Query | Expression;
390
- sources?: Record<string, QuerySourceItem>;
412
+ sources?: {
413
+ [K: string]: QuerySourceItem;
414
+ };
391
415
  and?: WhereItem[];
392
416
  or?: WhereItem[][];
393
417
  coalesceValue?: unknown | Expression;
@@ -415,7 +439,7 @@ type CommonQueryData = {
415
439
  transform?: ((input: unknown) => unknown)[];
416
440
  language?: string;
417
441
  isSubQuery?: true;
418
- relChain?: RelationsChain;
442
+ relChain?: (Query | RelationQuery)[];
419
443
  /**
420
444
  * Stores current operator functions available for the query.
421
445
  * Is needed to remove these operators from query object when changing the query type, see {@link setQueryOperators}.
@@ -425,7 +449,9 @@ type CommonQueryData = {
425
449
  * Used by {@link setQueryOperators} to store the original `baseQuery` before extending it with operators.
426
450
  */
427
451
  originalQuery?: Query;
428
- scopes: Record<string, QueryScopeData>;
452
+ scopes: {
453
+ [K: string]: QueryScopeData;
454
+ };
429
455
  all?: true;
430
456
  };
431
457
  type SelectQueryData = CommonQueryData & {
@@ -464,18 +490,17 @@ type InsertQueryData = CommonQueryData & {
464
490
  using?: JoinItem[];
465
491
  join?: JoinItem[];
466
492
  onConflict?: {
467
- type: 'ignore';
468
- expr?: OnConflictItem;
469
- } | {
470
- type: 'merge';
471
- expr?: OnConflictItem;
472
- update?: OnConflictMergeUpdate;
493
+ target?: OnConflictTarget;
494
+ set?: OnConflictSet;
495
+ merge?: OnConflictMerge;
473
496
  };
474
497
  };
475
- type UpdateQueryDataObject = Record<string, Expression | {
476
- op: string;
477
- arg: unknown;
478
- } | unknown>;
498
+ interface UpdateQueryDataObject {
499
+ [K: string]: Expression | {
500
+ op: string;
501
+ arg: unknown;
502
+ } | unknown;
503
+ }
479
504
  type UpdatedAtDataInjector = (data: UpdateQueryDataItem[]) => UpdateQueryDataItem | void;
480
505
  type UpdateQueryDataItem = UpdateQueryDataObject | Expression | UpdatedAtDataInjector;
481
506
  type UpdateQueryData = CommonQueryData & {
@@ -701,7 +726,7 @@ type JoinOptionalMain<T extends PickQueryMetaResultReturnType, Selectable extend
701
726
  column: QueryColumnToNullable<T['meta']['selectable'][K]['column']>;
702
727
  };
703
728
  } & Selectable : T['meta'][K];
704
- } : K extends 'result' ? NullableResult<T> : K extends 'then' ? QueryThen<GetQueryResult<T, NullableResult<T>>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, NullableResult<T>>> : T[K];
729
+ } : K extends 'result' ? NullableResult<T> : K extends 'then' ? QueryThen<GetQueryResult<T, NullableResult<T>>> : T[K];
705
730
  };
706
731
  type NullableResult<T extends PickQueryResult> = {
707
732
  [K in keyof T['result']]: QueryColumnToNullable<T['result'][K]>;
@@ -2223,6 +2248,287 @@ declare class JSONTextColumn<Schema extends ColumnSchemaConfig> extends ColumnTy
2223
2248
  toCode(t: string, m?: boolean): Code;
2224
2249
  }
2225
2250
 
2251
+ declare const templateLiteralToSQL: (template: TemplateLiteralArgs, ctx: ToSQLCtx, quotedAs?: string) => string;
2252
+ declare class RawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>> extends RawSQLBase<T, ColumnTypes> {
2253
+ columnTypes: ColumnTypes;
2254
+ constructor(sql: string | TemplateLiteralArgs, values?: RawSQLValues, type?: T);
2255
+ makeSQL(ctx: ToSQLCtx, quotedAs?: string): string;
2256
+ }
2257
+ interface DynamicRawSQL<T extends QueryColumn> extends Expression<T>, ExpressionTypeMethod {
2258
+ }
2259
+ declare class DynamicRawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>> extends Expression<T> {
2260
+ fn: DynamicSQLArg;
2261
+ _type: T;
2262
+ columnTypes: ColumnTypes;
2263
+ constructor(fn: DynamicSQLArg);
2264
+ makeSQL(ctx: ToSQLCtx, quotedAs?: string): string;
2265
+ }
2266
+ declare function raw<T = unknown>(...args: StaticSQLArgs): RawSQL<QueryColumn<T>>;
2267
+ declare function raw<T = unknown>(...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>>;
2268
+ declare const countSelect: RawSQL<QueryColumn<unknown, orchid_core.CoreBaseOperators>, DefaultColumnTypes<ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>>>[];
2269
+ declare function sqlQueryArgsToExpression(args: SQLQueryArgs): RawSQL<QueryColumn>;
2270
+ type SqlFn = <T, Args extends [sql: TemplateStringsArray, ...values: unknown[]] | [sql: string] | [values: RecordUnknown, sql?: string]>(this: T, ...args: Args) => Args extends [RecordUnknown] ? (...sql: TemplateLiteralArgs) => RawSQLBase<QueryColumn, T> : RawSQLBase<QueryColumn, T>;
2271
+ declare const sqlFn: SqlFn;
2272
+
2273
+ interface TableData {
2274
+ primaryKey?: TableData.PrimaryKey;
2275
+ indexes?: TableData.Index[];
2276
+ constraints?: TableData.Constraint[];
2277
+ }
2278
+ declare namespace TableData {
2279
+ export type DropMode = 'CASCADE' | 'RESTRICT';
2280
+ export interface PrimaryKey {
2281
+ columns: string[];
2282
+ name?: string;
2283
+ }
2284
+ export interface ColumnIndex {
2285
+ options: Index.ColumnArg & Index.Options;
2286
+ name?: string;
2287
+ }
2288
+ export interface Index {
2289
+ columns: Index.ColumnOrExpressionOptions[];
2290
+ options: Index.Options;
2291
+ name?: string;
2292
+ }
2293
+ export interface Constraint {
2294
+ name?: string;
2295
+ check?: Check;
2296
+ identity?: Identity;
2297
+ references?: References;
2298
+ dropMode?: TableData.DropMode;
2299
+ }
2300
+ export type Check = RawSQLBase;
2301
+ export interface ColumnReferences {
2302
+ fnOrTable: TableData.References.FnOrTable;
2303
+ foreignColumns: string[];
2304
+ options?: References.Options;
2305
+ }
2306
+ export interface References extends ColumnReferences {
2307
+ columns: string[];
2308
+ }
2309
+ export interface Identity extends SequenceBaseOptions {
2310
+ always?: boolean;
2311
+ }
2312
+ interface SequenceBaseOptions {
2313
+ increment?: number;
2314
+ start?: number;
2315
+ min?: number;
2316
+ max?: number;
2317
+ cache?: number;
2318
+ cycle?: boolean;
2319
+ }
2320
+ export interface SequenceOptions extends SequenceBaseOptions {
2321
+ dataType?: 'smallint' | 'integer' | 'bigint';
2322
+ ownedBy?: string;
2323
+ }
2324
+ export namespace Index {
2325
+ export interface ColumnOptions {
2326
+ collate?: string;
2327
+ opclass?: string;
2328
+ order?: string;
2329
+ weight?: SearchWeight;
2330
+ }
2331
+ export interface UniqueOptionsArg {
2332
+ nullsNotDistinct?: boolean;
2333
+ using?: string;
2334
+ include?: MaybeArray<string>;
2335
+ with?: string;
2336
+ tablespace?: string;
2337
+ where?: string;
2338
+ dropMode?: 'CASCADE' | 'RESTRICT';
2339
+ }
2340
+ export interface OptionsArg extends UniqueOptionsArg {
2341
+ unique?: boolean;
2342
+ }
2343
+ export interface TsVectorArg extends OptionsArg, TsVectorOptions {
2344
+ }
2345
+ export type Options = TsVectorArg;
2346
+ export interface UniqueColumnArg extends ColumnOptions, UniqueOptionsArg {
2347
+ expression?: string;
2348
+ }
2349
+ export interface ColumnArg extends UniqueColumnArg {
2350
+ unique?: boolean;
2351
+ }
2352
+ interface TsVectorOptions {
2353
+ language?: string;
2354
+ languageColumn?: string;
2355
+ tsVector?: boolean;
2356
+ }
2357
+ export interface TsVectorColumnArg extends ColumnArg, TsVectorOptions {
2358
+ }
2359
+ export interface ExpressionOptions extends ColumnOptions {
2360
+ expression: string;
2361
+ }
2362
+ export interface ColumnOptionsForColumn<Column extends PropertyKey> extends ColumnOptions {
2363
+ column: Column;
2364
+ }
2365
+ export type ColumnOrExpressionOptions<Column extends PropertyKey = string> = ColumnOptionsForColumn<Column> | ExpressionOptions;
2366
+ export {};
2367
+ }
2368
+ export namespace References {
2369
+ type FnOrTable = (() => ForeignKeyTable) | string;
2370
+ /**
2371
+ * - MATCH FULL will not allow one column of a multicolumn foreign key to be null unless all foreign key columns are null;
2372
+ * if they are all null, the row is not required to have a match in the referenced table.
2373
+ * - MATCH SIMPLE (default) allows any of the foreign key columns to be null; if any of them are null, the row is not required to have a match in the referenced table.
2374
+ * - MATCH PARTIAL - PG docs say it's not implemented.
2375
+ */
2376
+ type Match = 'FULL' | 'PARTIAL' | 'SIMPLE';
2377
+ /**
2378
+ * - NO ACTION Produce an error indicating that the deletion or update would create a foreign key constraint violation. If the constraint is deferred, this error will be produced at constraint check time if there still exist any referencing rows. This is the default action.
2379
+ * - RESTRICT Produce an error indicating that the deletion or update would create a foreign key constraint violation. This is the same as NO ACTION except that the check is not deferrable.
2380
+ * - CASCADE Delete any rows referencing the deleted row, or update the values of the referencing column(s) to the new values of the referenced columns, respectively.
2381
+ * - SET NULL Set all the referencing columns, or a specified subset of the referencing columns, to null. A subset of columns can only be specified for ON DELETE actions.
2382
+ * - SET DEFAULT Set all the referencing columns, or a specified subset of the referencing columns, to their default values. A subset of columns can only be specified for ON DELETE actions. (There must be a row in the referenced table matching the default values, if they are not null, or the operation will fail.)
2383
+ */
2384
+ type Action = 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
2385
+ interface Options {
2386
+ name?: string;
2387
+ match?: Match;
2388
+ onUpdate?: Action;
2389
+ onDelete?: Action;
2390
+ dropMode?: TableData.DropMode;
2391
+ }
2392
+ }
2393
+ export {};
2394
+ }
2395
+ type TableDataInput = {
2396
+ primaryKey?: TableData.PrimaryKey;
2397
+ index?: TableData.Index;
2398
+ constraint?: TableData.Constraint;
2399
+ };
2400
+ interface TableDataItem {
2401
+ columns: unknown;
2402
+ name: unknown;
2403
+ }
2404
+ interface UniqueTableDataItem<Shape extends QueryColumns = QueryColumns> {
2405
+ columns: (keyof Shape)[];
2406
+ name: string;
2407
+ }
2408
+ interface TableDataMethods<Key extends PropertyKey> {
2409
+ primaryKey<Columns extends [Key, ...Key[]], Name extends string>(columns: Columns, name?: Name): {
2410
+ columns: Columns;
2411
+ name: string extends Name ? never : Name;
2412
+ };
2413
+ unique<Columns extends [
2414
+ Key | TableData.Index.ColumnOrExpressionOptions<Key>,
2415
+ ...(Key | TableData.Index.ColumnOrExpressionOptions<Key>)[]
2416
+ ], Name extends string>(columns: Columns, ...args: [options?: TableData.Index.UniqueOptionsArg] | [name?: Name, options?: TableData.Index.UniqueOptionsArg]): {
2417
+ columns: Columns extends (Key | TableData.Index.ColumnOptionsForColumn<Key>)[] ? {
2418
+ [I in keyof Columns]: 'column' extends keyof Columns[I] ? Columns[I]['column'] : Columns[I];
2419
+ } : never;
2420
+ name: string extends Name ? never : Name;
2421
+ };
2422
+ index(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], ...args: [options?: TableData.Index.OptionsArg] | [name?: string, options?: TableData.Index.OptionsArg]): TableDataItem;
2423
+ searchIndex(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], ...args: [options?: TableData.Index.TsVectorArg] | [name?: string, options?: TableData.Index.TsVectorArg]): TableDataItem;
2424
+ foreignKey<ForeignTable extends (() => ForeignKeyTable) | string, ForeignColumns extends ForeignTable extends () => ForeignKeyTable ? [
2425
+ ColumnNameOfTable<ReturnType<ForeignTable>>,
2426
+ ...ColumnNameOfTable<ReturnType<ForeignTable>>[]
2427
+ ] : [string, ...string[]]>(columns: [string, ...string[]], fnOrTable: ForeignTable, foreignColumns: ForeignColumns, options?: TableData.References.Options): TableDataItem;
2428
+ check(check: RawSQLBase, name?: string): TableDataItem;
2429
+ sql: SqlFn;
2430
+ }
2431
+ type TableDataItemsUniqueColumns<Shape extends QueryColumns, T extends MaybeArray<TableDataItem>> = MaybeArray<TableDataItem> extends T ? never : T extends UniqueTableDataItem<Shape> ? ItemUniqueColumns<Shape, T> : T extends UniqueTableDataItem<Shape>[] ? {
2432
+ [Item in T[number] as PropertyKey]: ItemUniqueColumns<Shape, Item>;
2433
+ }[PropertyKey] : never;
2434
+ type ItemUniqueColumns<Shape extends QueryColumns, T extends UniqueTableDataItem<Shape>> = {
2435
+ [Column in T['columns'][number]]: UniqueQueryTypeOrExpression<Shape[Column]['queryType']>;
2436
+ };
2437
+ type TableDataItemsUniqueColumnTuples<Shape extends QueryColumns, T extends MaybeArray<TableDataItem>> = MaybeArray<TableDataItem> extends T ? never : T extends UniqueTableDataItem<Shape> ? T['columns'] : T extends UniqueTableDataItem<Shape>[] ? T[number]['columns'] : never;
2438
+ type UniqueQueryTypeOrExpression<T> = T | Expression<QueryColumn<T, EmptyObject>>;
2439
+ type TableDataItemsUniqueConstraints<T extends MaybeArray<TableDataItem>> = MaybeArray<TableDataItem> extends T ? never : T extends UniqueTableDataItem ? T['name'] : T extends UniqueTableDataItem[] ? T[number]['name'] : never;
2440
+ type TableDataFn<Shape, Data extends MaybeArray<TableDataItem>> = (t: TableDataMethods<keyof Shape>) => Data;
2441
+ declare const tableDataMethods: TableDataMethods<string>;
2442
+ declare const parseTableData: (dataFn?: TableDataFn<unknown, any>) => TableData;
2443
+ declare const parseTableDataInput: (tableData: TableData, item: TableDataInput) => void;
2444
+
2445
+ interface NumberColumnData extends BaseNumberData {
2446
+ identity: TableData.Identity;
2447
+ }
2448
+ interface SerialColumnData extends NumberColumnData {
2449
+ default: Expression;
2450
+ }
2451
+ declare abstract class NumberBaseColumn<Schema extends ColumnSchemaConfig, SchemaType extends Schema['type']> extends ColumnType<Schema, number, SchemaType, OperatorsNumber> {
2452
+ data: NumberColumnData;
2453
+ operators: OperatorsNumber;
2454
+ }
2455
+ declare abstract class IntegerBaseColumn<Schema extends ColumnSchemaConfig> extends NumberBaseColumn<Schema, ReturnType<Schema['int']>> {
2456
+ data: NumberColumnData;
2457
+ constructor(schema: Schema);
2458
+ }
2459
+ declare abstract class NumberAsStringBaseColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsNumber> {
2460
+ operators: OperatorsNumber;
2461
+ data: ColumnData;
2462
+ constructor(schema: Schema);
2463
+ }
2464
+ interface DecimalColumnData extends ColumnData {
2465
+ numericPrecision?: number;
2466
+ numericScale?: number;
2467
+ }
2468
+ declare class DecimalColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsNumber> {
2469
+ data: DecimalColumnData;
2470
+ operators: OperatorsNumber;
2471
+ dataType: "numeric";
2472
+ constructor(schema: Schema, numericPrecision?: number, numericScale?: number);
2473
+ toCode(t: string, m?: boolean): Code;
2474
+ toSQL(): string;
2475
+ }
2476
+ type IdentityColumn<T extends PickColumnBaseData> = ColumnWithDefault<T, Expression>;
2477
+ declare class SmallIntColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2478
+ dataType: "int2";
2479
+ constructor(schema: Schema);
2480
+ parseItem: typeof parseInt;
2481
+ toCode(t: string, m?: boolean): Code;
2482
+ identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
2483
+ }
2484
+ declare class IntegerColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2485
+ dataType: "int4";
2486
+ constructor(schema: Schema);
2487
+ parseItem: typeof parseInt;
2488
+ toCode(t: string, m?: boolean): Code;
2489
+ identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
2490
+ }
2491
+ declare class BigIntColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
2492
+ dataType: "int8";
2493
+ constructor(schema: Schema);
2494
+ toCode(t: string, m?: boolean): Code;
2495
+ identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
2496
+ }
2497
+ declare class RealColumn<Schema extends ColumnSchemaConfig> extends NumberBaseColumn<Schema, ReturnType<Schema['number']>> {
2498
+ dataType: "float4";
2499
+ parseItem: typeof parseFloat;
2500
+ constructor(schema: Schema);
2501
+ toCode(t: string, m?: boolean): Code;
2502
+ }
2503
+ declare class DoublePrecisionColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
2504
+ dataType: "float8";
2505
+ constructor(schema: Schema);
2506
+ toCode(t: string, m?: boolean): Code;
2507
+ }
2508
+ declare class SmallSerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2509
+ dataType: "int2";
2510
+ parseItem: typeof parseInt;
2511
+ data: SerialColumnData;
2512
+ constructor(schema: Schema);
2513
+ toSQL(): string;
2514
+ toCode(t: string, m?: boolean): Code;
2515
+ }
2516
+ declare class SerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2517
+ dataType: "int4";
2518
+ parseItem: typeof parseInt;
2519
+ data: SerialColumnData;
2520
+ constructor(schema: Schema);
2521
+ toSQL(): string;
2522
+ toCode(t: string, m?: boolean): Code;
2523
+ }
2524
+ declare class BigSerialColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
2525
+ dataType: "int8";
2526
+ data: SerialColumnData;
2527
+ constructor(schema: Schema);
2528
+ toSQL(): string;
2529
+ toCode(t: string, m?: boolean): Code;
2530
+ }
2531
+
2226
2532
  type TextColumnData = StringTypeData;
2227
2533
  declare abstract class TextBaseColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
2228
2534
  data: TextColumnData;
@@ -2357,7 +2663,7 @@ declare class BitVaryingColumn<Schema extends ColumnSchemaConfig> extends Column
2357
2663
  toCode(t: string, m?: boolean): Code;
2358
2664
  toSQL(): string;
2359
2665
  }
2360
- type TsVectorGeneratedColumns = string[] | Record<string, SearchWeight>;
2666
+ type TsVectorGeneratedColumns = string[] | SearchWeightRecord;
2361
2667
  declare class TsVectorColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
2362
2668
  defaultLanguage: string;
2363
2669
  dataType: "tsvector";
@@ -2400,8 +2706,11 @@ declare class UUIDColumn<Schema extends ColumnSchemaConfig> extends ColumnType<S
2400
2706
  dataType: "uuid";
2401
2707
  operators: OperatorsText;
2402
2708
  constructor(schema: Schema);
2403
- primaryKey<T extends PickColumnBaseData>(this: T): // using & bc otherwise the return type doesn't match `primaryKey` in ColumnType and TS complains
2404
- PrimaryKeyColumn<T> & {
2709
+ /**
2710
+ * see {@link ColumnType.primaryKey}
2711
+ */
2712
+ primaryKey<T extends PickColumnBaseData, Name extends string>(this: T, name?: Name): // using & bc otherwise the return type doesn't match `primaryKey` in ColumnType and TS complains
2713
+ PrimaryKeyColumn<T, Name> & {
2405
2714
  data: {
2406
2715
  default: RawSQLBase;
2407
2716
  };
@@ -2424,248 +2733,6 @@ declare class CitextColumn<Schema extends ColumnSchemaConfig> extends TextBaseCo
2424
2733
  toCode(t: string, m?: boolean): Code;
2425
2734
  }
2426
2735
 
2427
- declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, boolean, ReturnType<Schema['boolean']>, OperatorsBoolean> {
2428
- dataType: "bool";
2429
- operators: OperatorsBoolean;
2430
- constructor(schema: Schema);
2431
- toCode(t: string, m?: boolean): Code;
2432
- parseItem: (input: string) => boolean;
2433
- }
2434
-
2435
- declare class CustomTypeColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, unknown, ReturnType<Schema['unknown']>, typeof Operators.any> {
2436
- dataType: string;
2437
- operators: OperatorsAny;
2438
- constructor(schema: Schema, dataType: string);
2439
- toCode(t: string, m?: boolean): Code;
2440
- as<T extends Pick<ColumnTypeBase, 'inputType' | 'outputType' | 'data'>, C extends Omit<ColumnTypeBase, 'inputType' | 'outputType'> & Pick<T, 'inputType' | 'outputType'>>(this: T, column: C): C;
2441
- }
2442
- declare class DomainColumn<Schema extends ColumnSchemaConfig> extends CustomTypeColumn<Schema> {
2443
- toCode(t: string, m?: boolean): Code;
2444
- }
2445
-
2446
- interface TableData {
2447
- primaryKey?: TableData.PrimaryKey;
2448
- indexes?: TableData.Index[];
2449
- constraints?: TableData.Constraint[];
2450
- }
2451
- declare namespace TableData {
2452
- export interface PrimaryKey {
2453
- columns: string[];
2454
- options?: {
2455
- name?: string;
2456
- };
2457
- }
2458
- export interface Index {
2459
- columns: IndexColumnOptions[];
2460
- options: IndexOptions;
2461
- }
2462
- export interface Constraint {
2463
- name?: string;
2464
- check?: Check;
2465
- identity?: Identity;
2466
- references?: References;
2467
- dropMode?: DropMode;
2468
- }
2469
- export type Check = RawSQLBase;
2470
- export interface References {
2471
- columns: string[];
2472
- fnOrTable: (() => ForeignKeyTable) | string;
2473
- foreignColumns: string[];
2474
- options?: ForeignKeyOptions;
2475
- }
2476
- export interface Identity extends SequenceBaseOptions {
2477
- always?: boolean;
2478
- }
2479
- interface SequenceBaseOptions {
2480
- increment?: number;
2481
- start?: number;
2482
- min?: number;
2483
- max?: number;
2484
- cache?: number;
2485
- cycle?: boolean;
2486
- }
2487
- export interface SequenceOptions extends SequenceBaseOptions {
2488
- dataType?: 'smallint' | 'integer' | 'bigint';
2489
- ownedBy?: string;
2490
- }
2491
- export {};
2492
- }
2493
- declare const newTableData: () => TableData;
2494
- declare const getTableData: () => TableData;
2495
- declare const resetTableData: (data?: TableData) => void;
2496
- declare const getColumnTypes: <ColumnTypes, Shape extends QueryColumnsInit>(types: ColumnTypes, fn: (t: ColumnTypes) => Shape, nowSQL: string | undefined, language: string | undefined, data?: TableData) => Shape;
2497
- interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends TimestampHelpers {
2498
- schema: SchemaConfig;
2499
- enum: SchemaConfig['enum'];
2500
- array: SchemaConfig['array'];
2501
- name<T>(this: T, name: string): T;
2502
- sql<T, Args extends [sql: TemplateStringsArray, ...values: unknown[]] | [sql: string] | [values: RecordUnknown, sql?: string]>(this: T, ...args: Args): Args extends [RecordUnknown] ? (...sql: TemplateLiteralArgs) => RawSQLBase<QueryColumn, T> : RawSQLBase<QueryColumn, T>;
2503
- smallint: SchemaConfig['smallint'];
2504
- integer: SchemaConfig['integer'];
2505
- bigint: SchemaConfig['bigint'];
2506
- numeric: SchemaConfig['decimal'];
2507
- decimal: SchemaConfig['decimal'];
2508
- real: SchemaConfig['real'];
2509
- doublePrecision: SchemaConfig['doublePrecision'];
2510
- identity(options?: TableData.Identity): IdentityColumn<ReturnType<SchemaConfig['integer']>>;
2511
- smallSerial: SchemaConfig['smallSerial'];
2512
- serial: SchemaConfig['serial'];
2513
- bigSerial: SchemaConfig['bigSerial'];
2514
- money: SchemaConfig['money'];
2515
- varchar: SchemaConfig['varchar'];
2516
- char: SchemaConfig['char'];
2517
- text: SchemaConfig['text'];
2518
- string: SchemaConfig['string'];
2519
- citext: SchemaConfig['citext'];
2520
- bytea(): ByteaColumn<SchemaConfig>;
2521
- date: SchemaConfig['date'];
2522
- timestampNoTZ: SchemaConfig['timestampNoTZ'];
2523
- timestamp: SchemaConfig['timestamp'];
2524
- time(precision?: number): TimeColumn<SchemaConfig>;
2525
- interval(fields?: string, precision?: number): IntervalColumn<SchemaConfig>;
2526
- boolean(): BooleanColumn<SchemaConfig>;
2527
- point(): PointColumn<SchemaConfig>;
2528
- line(): LineColumn<SchemaConfig>;
2529
- lseg(): LsegColumn<SchemaConfig>;
2530
- box(): BoxColumn<SchemaConfig>;
2531
- path(): PathColumn<SchemaConfig>;
2532
- polygon(): PolygonColumn<SchemaConfig>;
2533
- circle(): CircleColumn<SchemaConfig>;
2534
- cidr(): CidrColumn<SchemaConfig>;
2535
- inet(): InetColumn<SchemaConfig>;
2536
- macaddr(): MacAddrColumn<SchemaConfig>;
2537
- macaddr8(): MacAddr8Column<SchemaConfig>;
2538
- bit(length: number): BitColumn<SchemaConfig>;
2539
- bitVarying(length?: number): BitVaryingColumn<SchemaConfig>;
2540
- tsvector(): TsVectorColumn<SchemaConfig>;
2541
- tsquery(): TsQueryColumn<SchemaConfig>;
2542
- uuid(): UUIDColumn<SchemaConfig>;
2543
- xml(): XMLColumn<SchemaConfig>;
2544
- json: SchemaConfig['json'];
2545
- jsonText(): JSONTextColumn<SchemaConfig>;
2546
- type(dataType: string): CustomTypeColumn<SchemaConfig>;
2547
- domain(dataType: string): DomainColumn<SchemaConfig>;
2548
- primaryKey(columns: string[], options?: {
2549
- name?: string;
2550
- }): EmptyObject;
2551
- index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): EmptyObject;
2552
- unique(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): EmptyObject;
2553
- /**
2554
- * See {@link ColumnType.searchIndex}
2555
- */
2556
- searchIndex(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): EmptyObject;
2557
- constraint<Table extends (() => ForeignKeyTable) | string, Columns extends Table extends () => ForeignKeyTable ? [
2558
- ColumnNameOfTable<ReturnType<Table>>,
2559
- ...ColumnNameOfTable<ReturnType<Table>>[]
2560
- ] : [string, ...string[]]>({ name, references, check, dropMode, }: {
2561
- name?: string;
2562
- references?: [
2563
- columns: string[],
2564
- fnOrTable: Table,
2565
- foreignColumns: Columns,
2566
- options?: ForeignKeyOptions
2567
- ];
2568
- check?: RawSQLBase;
2569
- dropMode?: DropMode;
2570
- }): EmptyObject;
2571
- foreignKey<Table extends (() => ForeignKeyTable) | string, Columns extends Table extends () => ForeignKeyTable ? [
2572
- ColumnNameOfTable<ReturnType<Table>>,
2573
- ...ColumnNameOfTable<ReturnType<Table>>[]
2574
- ] : [string, ...string[]]>(columns: string[], fnOrTable: Table, foreignColumns: Columns, options?: ForeignKeyOptions & {
2575
- name?: string;
2576
- dropMode?: DropMode;
2577
- }): EmptyObject;
2578
- check(check: RawSQLBase, options?: ConstraintOptions): EmptyObject;
2579
- }
2580
- declare const makeColumnTypes: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>>(schema: SchemaConfig) => DefaultColumnTypes<SchemaConfig>;
2581
-
2582
- interface NumberColumnData extends BaseNumberData {
2583
- identity: TableData.Identity;
2584
- }
2585
- interface SerialColumnData extends NumberColumnData {
2586
- default: Expression;
2587
- }
2588
- declare abstract class NumberBaseColumn<Schema extends ColumnSchemaConfig, SchemaType extends Schema['type']> extends ColumnType<Schema, number, SchemaType, OperatorsNumber> {
2589
- data: NumberColumnData;
2590
- operators: OperatorsNumber;
2591
- }
2592
- declare abstract class IntegerBaseColumn<Schema extends ColumnSchemaConfig> extends NumberBaseColumn<Schema, ReturnType<Schema['int']>> {
2593
- data: NumberColumnData;
2594
- constructor(schema: Schema);
2595
- }
2596
- declare abstract class NumberAsStringBaseColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsNumber> {
2597
- operators: OperatorsNumber;
2598
- data: ColumnData;
2599
- constructor(schema: Schema);
2600
- }
2601
- interface DecimalColumnData extends ColumnData {
2602
- numericPrecision?: number;
2603
- numericScale?: number;
2604
- }
2605
- declare class DecimalColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsNumber> {
2606
- data: DecimalColumnData;
2607
- operators: OperatorsNumber;
2608
- dataType: "numeric";
2609
- constructor(schema: Schema, numericPrecision?: number, numericScale?: number);
2610
- toCode(t: string, m?: boolean): Code;
2611
- toSQL(): string;
2612
- }
2613
- type IdentityColumn<T extends PickColumnBaseData> = ColumnWithDefault<T, Expression>;
2614
- declare class SmallIntColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2615
- dataType: "int2";
2616
- constructor(schema: Schema);
2617
- parseItem: typeof parseInt;
2618
- toCode(t: string, m?: boolean): Code;
2619
- identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
2620
- }
2621
- declare class IntegerColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2622
- dataType: "int4";
2623
- constructor(schema: Schema);
2624
- parseItem: typeof parseInt;
2625
- toCode(t: string, m?: boolean): Code;
2626
- identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
2627
- }
2628
- declare class BigIntColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
2629
- dataType: "int8";
2630
- constructor(schema: Schema);
2631
- toCode(t: string, m?: boolean): Code;
2632
- identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
2633
- }
2634
- declare class RealColumn<Schema extends ColumnSchemaConfig> extends NumberBaseColumn<Schema, ReturnType<Schema['number']>> {
2635
- dataType: "float4";
2636
- parseItem: typeof parseFloat;
2637
- constructor(schema: Schema);
2638
- toCode(t: string, m?: boolean): Code;
2639
- }
2640
- declare class DoublePrecisionColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
2641
- dataType: "float8";
2642
- constructor(schema: Schema);
2643
- toCode(t: string, m?: boolean): Code;
2644
- }
2645
- declare class SmallSerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2646
- dataType: "int2";
2647
- parseItem: typeof parseInt;
2648
- data: SerialColumnData;
2649
- constructor(schema: Schema);
2650
- toSQL(): string;
2651
- toCode(t: string, m?: boolean): Code;
2652
- }
2653
- declare class SerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2654
- dataType: "int4";
2655
- parseItem: typeof parseInt;
2656
- data: SerialColumnData;
2657
- constructor(schema: Schema);
2658
- toSQL(): string;
2659
- toCode(t: string, m?: boolean): Code;
2660
- }
2661
- declare class BigSerialColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
2662
- dataType: "int8";
2663
- data: SerialColumnData;
2664
- constructor(schema: Schema);
2665
- toSQL(): string;
2666
- toCode(t: string, m?: boolean): Code;
2667
- }
2668
-
2669
2736
  interface DefaultSchemaConfig extends ColumnSchemaConfig<ColumnType> {
2670
2737
  parse<T extends {
2671
2738
  type: unknown;
@@ -2775,6 +2842,19 @@ declare class SoftDeleteMethods {
2775
2842
  hardDelete<T extends QueryWithSoftDelete>(this: T, ..._args: DeleteArgs<T>): DeleteResult<T>;
2776
2843
  }
2777
2844
 
2845
+ type ShapeColumnPrimaryKeys<Shape extends QueryColumnsInit> = {
2846
+ [K in {
2847
+ [K in keyof Shape]: Shape[K]['data']['primaryKey'] extends string ? K : never;
2848
+ }[keyof Shape]]: UniqueQueryTypeOrExpression<Shape[K]['queryType']>;
2849
+ };
2850
+ type ShapeUniqueColumns<Shape extends QueryColumnsInit> = {
2851
+ [K in keyof Shape]: Shape[K]['data']['unique'] extends string ? {
2852
+ [C in K]: UniqueQueryTypeOrExpression<Shape[K]['queryType']>;
2853
+ } : never;
2854
+ }[keyof Shape];
2855
+ type UniqueConstraints<Shape extends QueryColumnsInit> = {
2856
+ [K in keyof Shape]: Shape[K]['data']['primaryKey'] extends string ? string extends Shape[K]['data']['primaryKey'] ? never : Shape[K]['data']['primaryKey'] : Shape[K]['data']['unique'] extends string ? string extends Shape[K]['data']['unique'] ? never : Shape[K]['data']['unique'] : never;
2857
+ }[keyof Shape];
2778
2858
  type NoPrimaryKeyOption = 'error' | 'warning' | 'ignore';
2779
2859
  interface DbSharedOptions extends QueryLogOptions {
2780
2860
  autoPreparedStatements?: boolean;
@@ -2811,17 +2891,18 @@ interface DbTableOptions<Table extends string | undefined, Shape extends QueryCo
2811
2891
  /**
2812
2892
  * See {@link ScopeMethods}
2813
2893
  */
2814
- type DbTableOptionScopes<Table extends string | undefined, Shape extends QueryColumns, Keys extends string = string> = Record<Keys, (q: ScopeArgumentQuery<Table, Shape>) => QueryBase>;
2815
- type QueryDefaultReturnData<Shape extends QueryColumnsInit> = Pick<ColumnShapeOutput<Shape>, DefaultSelectColumns<Shape>[number]>[];
2894
+ type DbTableOptionScopes<Table extends string | undefined, Shape extends QueryColumns, Keys extends string = string> = {
2895
+ [K in Keys]: (q: ScopeArgumentQuery<Table, Shape>) => QueryBase;
2896
+ };
2897
+ type QueryDefaultReturnData<Shape extends QueryColumnsInit> = {
2898
+ [K in DefaultSelectColumns<Shape>[number]]: Shape[K]['outputType'];
2899
+ }[];
2816
2900
  declare const anyShape: QueryColumnsInit;
2817
- interface Db<Table extends string | undefined = undefined, Shape extends QueryColumnsInit = QueryColumnsInit, Relations extends RelationsBase = EmptyObject, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends QueryColumnsInit = Shape, Scopes extends CoreQueryScopes | undefined = EmptyObject> extends DbBase<Adapter, Table, Shape, ColumnTypes, ShapeWithComputed>, QueryMethods<ColumnTypes>, QueryBase {
2818
- new (adapter: Adapter, queryBuilder: Db<Table, Shape, Relations, ColumnTypes>, table?: Table, shape?: Shape, options?: DbTableOptions<Table, ShapeWithComputed>): this;
2901
+ interface Db<Table extends string | undefined = undefined, Shape extends QueryColumnsInit = QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, Relations extends RelationsBase = EmptyObject, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends QueryColumnsInit = Shape, Scopes extends CoreQueryScopes | undefined = EmptyObject> extends DbBase<Adapter, Table, Shape, ColumnTypes, ShapeWithComputed>, QueryMethods<ColumnTypes>, QueryBase {
2819
2902
  result: Pick<Shape, DefaultSelectColumns<Shape>[number]>;
2820
2903
  queryBuilder: Db;
2821
- primaryKeys: Query['primaryKeys'];
2822
2904
  returnType: Query['returnType'];
2823
2905
  then: QueryThen<QueryDefaultReturnData<Shape>>;
2824
- catch: QueryCatch<QueryDefaultReturnData<Shape>>;
2825
2906
  windows: Query['windows'];
2826
2907
  defaultSelectColumns: DefaultSelectColumns<Shape>;
2827
2908
  relations: Relations;
@@ -2832,17 +2913,24 @@ interface Db<Table extends string | undefined = undefined, Shape extends QueryCo
2832
2913
  defaults: {
2833
2914
  [K in keyof Shape as unknown extends Shape[K]['data']['default'] ? never : K]: true;
2834
2915
  };
2835
- scopes: Record<keyof Scopes, true>;
2916
+ scopes: {
2917
+ [K in keyof Scopes]: true;
2918
+ };
2836
2919
  selectable: SelectableFromShape<ShapeWithComputed, Table>;
2837
2920
  };
2838
- }
2839
- declare class Db<Table extends string | undefined = undefined, Shape extends QueryColumnsInit = QueryColumnsInit, Relations extends RelationsBase = EmptyObject, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends QueryColumnsInit = Shape> implements Query {
2921
+ internal: QueryInternal<{
2922
+ [K in keyof PrimaryKeys]: (keyof PrimaryKeys extends K ? never : keyof PrimaryKeys) extends never ? PrimaryKeys[K] : never;
2923
+ }[keyof PrimaryKeys], PrimaryKeys | UniqueColumns, {
2924
+ [K in keyof Shape]: Shape[K]['data']['unique'] extends string ? K : never;
2925
+ }[keyof Shape] | keyof PrimaryKeys, UniqueColumnTuples, UniqueConstraints>;
2926
+ catch: QueryCatch;
2927
+ }
2928
+ declare class Db<Table extends string | undefined = undefined, Shape extends QueryColumnsInit = QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, Relations extends RelationsBase = EmptyObject, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends QueryColumnsInit = Shape> implements Query {
2840
2929
  adapter: Adapter;
2841
2930
  queryBuilder: Db;
2842
2931
  table: Table;
2843
2932
  shape: ShapeWithComputed;
2844
2933
  columnTypes: ColumnTypes;
2845
- tableData: TableData;
2846
2934
  constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: ShapeWithComputed, columnTypes: ColumnTypes, transactionStorage: AsyncLocalStorage<TransactionState>, options: DbTableOptions<Table, ShapeWithComputed>, tableData?: TableData);
2847
2935
  [inspect.custom](): string;
2848
2936
  /**
@@ -2903,11 +2991,11 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Que
2903
2991
  */
2904
2992
  queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryArraysResult<R>>;
2905
2993
  }
2906
- type DbTableConstructor<ColumnTypes> = <Table extends string, Shape extends QueryColumnsInit, Options extends DbTableOptions<Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, options?: Options) => Db<Table, Shape, EmptyObject, ColumnTypes, Shape, MapTableScopesOption<Options['scopes'], Options['softDelete']>>;
2994
+ type DbTableConstructor<ColumnTypes> = <Table extends string, Shape extends QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options) => Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, EmptyObject, ColumnTypes, Shape, MapTableScopesOption<Options['scopes'], Options['softDelete']>>;
2907
2995
  type MapTableScopesOption<Scopes extends CoreQueryScopes | undefined, SoftDelete extends true | PropertyKey | undefined> = {
2908
2996
  [K in keyof Scopes | (SoftDelete extends true | PropertyKey ? 'nonDeleted' : never)]: unknown;
2909
2997
  };
2910
- interface DbResult<ColumnTypes> extends Db<string, Record<string, never>, EmptyObject, ColumnTypes>, DbTableConstructor<ColumnTypes> {
2998
+ interface DbResult<ColumnTypes> extends Db<string, never, never, never, never, never, EmptyObject, ColumnTypes>, DbTableConstructor<ColumnTypes> {
2911
2999
  adapter: Adapter;
2912
3000
  close: Adapter['close'];
2913
3001
  }
@@ -3005,7 +3093,21 @@ type ToSQLOptions = {
3005
3093
  type ToSqlOptionsInternal = ToSQLOptions & {
3006
3094
  aliasValue?: true;
3007
3095
  };
3008
- type ToSQLQuery = Pick<Query, '__isQuery' | 'q' | 'queryBuilder' | 'table' | 'internal' | 'relations' | 'withData' | 'clone' | 'baseQuery' | 'meta' | 'returnType' | 'result' | 'shape'>;
3096
+ type ToSQLQuery = {
3097
+ __isQuery: Query['__isQuery'];
3098
+ q: Query['q'];
3099
+ queryBuilder: Query['queryBuilder'];
3100
+ table?: Query['table'];
3101
+ internal: Query['internal'];
3102
+ relations: Query['relations'];
3103
+ withData: Query['withData'];
3104
+ clone: Query['clone'];
3105
+ baseQuery: Query['baseQuery'];
3106
+ meta: Query['meta'];
3107
+ returnType: Query['returnType'];
3108
+ result: Query['result'];
3109
+ shape: Query['shape'];
3110
+ };
3009
3111
  declare const toSQL: (table: ToSQLQuery, options?: ToSQLOptions) => Sql;
3010
3112
  declare const makeSQL: (table: ToSQLQuery, options?: ToSqlOptionsInternal) => Sql;
3011
3113
  declare function pushLimitSQL(sql: string[], values: unknown[], q: SelectQueryData): void;
@@ -3051,7 +3153,9 @@ interface AggregateOptions<T extends PickQueryMetaResultRelationsWindows> {
3051
3153
  type Over<T extends PickQueryMetaResultWindows> = keyof T['windows'] | WindowArgDeclaration<T>;
3052
3154
  type FnExpressionArgs<Q extends PickQueryMeta> = (SelectableOrExpression<Q> | FnExpressionArgsPairs<Q> | FnExpressionArgsValue)[];
3053
3155
  interface FnExpressionArgsPairs<Q extends PickQueryMeta> {
3054
- pairs: Record<string, SelectableOrExpression<Q>>;
3156
+ pairs: {
3157
+ [K: string]: SelectableOrExpression<Q>;
3158
+ };
3055
3159
  }
3056
3160
  interface FnExpressionArgsValue {
3057
3161
  value: unknown;
@@ -3636,7 +3740,9 @@ type CreateRawArgs<T extends CreateSelf, Arg extends {
3636
3740
  }> = keyof RawRequiredColumns<T> extends Arg['columns'][number] ? [data: Arg] : [
3637
3741
  `Missing required columns: ${Exclude<keyof RawRequiredColumns<T> & string, Arg['columns'][number]>}`
3638
3742
  ];
3639
- type OnConflictArg<T extends CreateSelf> = keyof T['shape'] | (keyof T['shape'])[] | Expression;
3743
+ type OnConflictArg<T extends PickQueryUniqueProperties> = T['internal']['uniqueColumnNames'] | T['internal']['uniqueColumnTuples'] | Expression | {
3744
+ constraint: T['internal']['uniqueConstraints'];
3745
+ };
3640
3746
  type AddQueryDefaults<T extends CreateSelf, Defaults> = {
3641
3747
  [K in keyof T]: K extends 'meta' ? {
3642
3748
  [K in keyof T['meta']]: K extends 'defaults' ? T['meta']['defaults'] & Defaults : T['meta'][K];
@@ -3667,7 +3773,7 @@ declare const _queryInsertFrom: <T extends CreateSelf, Q extends Query & {
3667
3773
  }>(q: T, query: Q, data?: Omit<CreateData<T>, keyof Q['result']>) => InsertResult<T>;
3668
3774
  declare const _queryCreateManyFrom: <T extends CreateSelf>(q: T, query: Query) => CreateManyResult<T>;
3669
3775
  declare const _queryInsertManyFrom: <T extends CreateSelf>(q: T, query: Query) => InsertManyResult<T>;
3670
- declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T>>>(q: T, data: Data) => AddQueryDefaults<T, Record<keyof Data, true>>;
3776
+ declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T>>>(q: T, data: Data) => AddQueryDefaults<T, { [K in keyof Data]: true; }>;
3671
3777
  /**
3672
3778
  * Names of all create methods,
3673
3779
  * is used in {@link RelationQuery} to remove these methods if chained relation shouldn't have them,
@@ -3686,9 +3792,9 @@ declare class Create {
3686
3792
  * password: '1234',
3687
3793
  * });
3688
3794
  *
3689
- * // When using `.onConflict().ignore()`,
3795
+ * // When using `.onConflictDoNothing()`,
3690
3796
  * // the record may be not created and the `createdCount` will be 0.
3691
- * const createdCount = await db.table.insert(data).onConflict().ignore();
3797
+ * const createdCount = await db.table.insert(data).onConflictDoNothing();
3692
3798
  *
3693
3799
  * await db.table.create({
3694
3800
  * // raw SQL
@@ -3861,7 +3967,7 @@ declare class Create {
3861
3967
  *
3862
3968
  * Columns provided in `defaults` are marked as optional in the following `create`.
3863
3969
  *
3864
- * Default data is the same as in [create](#create) and [createMany](#createMany),
3970
+ * Default data is the same as in {@link create} and {@link createMany},
3865
3971
  * so you can provide a raw SQL, or a query with a query.
3866
3972
  *
3867
3973
  * ```ts
@@ -3878,34 +3984,49 @@ declare class Create {
3878
3984
  *
3879
3985
  * @param data - default values for `create` and `createMany` which will follow `defaults`
3880
3986
  */
3881
- defaults<T extends CreateSelf, Data extends Partial<CreateData<T>>>(this: T, data: Data): AddQueryDefaults<T, Record<keyof Data, true>>;
3987
+ defaults<T extends CreateSelf, Data extends Partial<CreateData<T>>>(this: T, data: Data): AddQueryDefaults<T, {
3988
+ [K in keyof Data]: true;
3989
+ }>;
3882
3990
  /**
3883
- * A modifier for creating queries that specify alternative behavior in the case of a conflict.
3884
- * A conflict occurs when a table has a `PRIMARY KEY` or a `UNIQUE` index on a column
3885
- * (or a composite index on a set of columns) and a row being created has the same value as a row
3886
- * that already exists in the table in this column(s).
3887
- * The default behavior in case of conflict is to raise an error and abort the query.
3991
+ * By default, violating unique constraint will cause the creative query to throw,
3992
+ * you can define what to do on a conflict: to ignore it, or to merge the existing record with a new data.
3993
+ *
3994
+ * A conflict occurs when a table has a primary key or a unique index on a column,
3995
+ * or a composite primary key unique index on a set of columns,
3996
+ * and a row being created has the same value as a row that already exists in the table in this column(s).
3997
+ *
3998
+ * Use {@link onConflictDoNothing} to suppress the error and continue without updating the record,
3999
+ * or the `merge` to update the record with new values automatically,
4000
+ * or the `set` to specify own values for the update.
3888
4001
  *
3889
- * Use `onConflict` to either ignore the error by using `.onConflict().ignore()`,
3890
- * or to update the existing row with new data (perform an "UPSERT") by using `.onConflict().merge()`.
4002
+ * `onConflict` only accepts column names that are defined in `primaryKey` or `unique` in the table definition.
4003
+ * To specify a constraint, its name also must be explicitly set in `primaryKey` or `unique` in the table code.
4004
+ *
4005
+ * Postgres has a limitation that a single `INSERT` query can have only a single `ON CONFLICT` clause that can target only a single unique constraint
4006
+ * for updating the record.
4007
+ *
4008
+ * If your table has multiple potential reasons for unique constraint violation, such as username and email columns in a user table,
4009
+ * consider using `upsert` instead.
3891
4010
  *
3892
4011
  * ```ts
3893
4012
  * // leave `onConflict` without argument to ignore or merge on any conflict
3894
- * db.table.create(data).onConflict().ignore();
4013
+ * db.table.create(data).onConflictDoNothing();
3895
4014
  *
3896
4015
  * // single column:
3897
- * db.table.create(data).onConfict('email');
4016
+ * db.table.create(data).onConfict('email').merge();
3898
4017
  *
3899
4018
  * // array of columns:
3900
- * db.table.create(data).onConfict(['email', 'name']);
4019
+ * db.table.create(data).onConfict(['email', 'name']).merge();
3901
4020
  *
3902
- * // raw expression:
3903
- * db.table.create(data).onConfict(db.table.sql`(email) where condition`);
3904
- * ```
4021
+ * // constraint name
4022
+ * db.table.create(data).onConfict({ constraint: 'unique_index_name' }).merge();
3905
4023
  *
3906
- * ::: info
3907
- * The column(s) given to the `onConflict` must either be the table's PRIMARY KEY or have a UNIQUE index on them, or the query will fail to execute.
3908
- * When specifying multiple columns, they must be a composite PRIMARY KEY or have a composite UNIQUE index.
4024
+ * // raw SQL expression:
4025
+ * db.table
4026
+ * .create(data)
4027
+ * .onConfict(db.table.sql`(email) where condition`)
4028
+ * .merge();
4029
+ * ```
3909
4030
  *
3910
4031
  * You can use the db.table.sql function in onConflict.
3911
4032
  * It can be useful to specify a condition when you have a partial index:
@@ -3922,26 +4043,30 @@ declare class Create {
3922
4043
  * .ignore();
3923
4044
  * ```
3924
4045
  *
3925
- * :::
4046
+ * For `merge` and `set`, you can append `where` to update data only for the matching rows:
4047
+ *
4048
+ * ```ts
4049
+ * const timestamp = Date.now();
3926
4050
  *
3927
- * See the documentation on the .ignore() and .merge() methods for more details.
4051
+ * db.table
4052
+ * .create(data)
4053
+ * .onConflict('email')
4054
+ * .set({
4055
+ * name: 'John Doe',
4056
+ * updatedAt: timestamp,
4057
+ * })
4058
+ * .where({ updatedAt: { lt: timestamp } });
4059
+ * ```
3928
4060
  *
3929
4061
  * @param arg - optionally provide an array of columns
3930
4062
  */
3931
- onConflict<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg?: Arg): OnConflictQueryBuilder<T, Arg>;
3932
- }
3933
- declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflictArg<T> | undefined> {
3934
- private query;
3935
- private onConflict;
3936
- constructor(query: T, onConflict: Arg);
4063
+ onConflict<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg: Arg): OnConflictQueryBuilder<T, Arg>;
3937
4064
  /**
3938
- * Available only after `onConflict`.
4065
+ * Use `onConflictDoNothing` to suppress unique constraint violation error when creating a record.
3939
4066
  *
3940
- * `ignore` modifies a create query, and causes it to be silently dropped without an error if a conflict occurs.
4067
+ * Adds `ON CONFLICT (columns) DO NOTHING` clause to the insert statement, columns are optional.
3941
4068
  *
3942
- * Adds the `ON CONFLICT (columns) DO NOTHING` clause to the insert statement.
3943
- *
3944
- * It produces `ON CONFLICT DO NOTHING` when no `onConflict` argument provided.
4069
+ * Can also accept a constraint name.
3945
4070
  *
3946
4071
  * ```ts
3947
4072
  * db.table
@@ -3949,141 +4074,111 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
3949
4074
  * email: 'ignore@example.com',
3950
4075
  * name: 'John Doe',
3951
4076
  * })
3952
- * .onConflict('email')
3953
- * .ignore();
4077
+ * // on any conflict:
4078
+ * .onConflictDoNothing()
4079
+ * // or, for a specific column:
4080
+ * .onConflictDoNothing('email')
4081
+ * // or, for a specific constraint:
4082
+ * .onConflictDoNothing({ constraint: 'unique_index_name' });
3954
4083
  * ```
3955
4084
  *
3956
- *
3957
- * When there is a conflict, nothing can be returned from the database, that's why `ignore` has to add `| undefined` part to the response type.
3958
- *
3959
- * `create` returns a full record by default, it becomes `RecordType | undefined` after applying `ignore`.
4085
+ * When there is a conflict, nothing can be returned from the database, so `onConflictDoNothing` adds `| undefined` part to the response type.
3960
4086
  *
3961
4087
  * ```ts
3962
4088
  * const maybeRecord: RecordType | undefined = await db.table
3963
4089
  * .create(data)
3964
- * .onConflict()
3965
- * .ignore();
4090
+ * .onConflictDoNothing();
3966
4091
  *
3967
4092
  * const maybeId: number | undefined = await db.table
3968
4093
  * .get('id')
3969
4094
  * .create(data)
3970
- * .onConflict()
3971
- * .ignore();
4095
+ * .onConflictDoNothing();
3972
4096
  * ```
3973
4097
  *
3974
- * When creating many records, only the created records will be returned. If no records were created, array will be empty:
4098
+ * When creating multiple records, only created records will be returned. If no records were created, array will be empty:
3975
4099
  *
3976
4100
  * ```ts
3977
4101
  * // array can be empty
3978
- * const arr = await db.table.createMany([data, data, data]).onConflict().ignore();
4102
+ * const arr = await db.table.createMany([data, data, data]).onConflictDoNothing();
3979
4103
  * ```
3980
4104
  */
3981
- ignore(): IgnoreResult<T>;
4105
+ onConflictDoNothing<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg?: Arg): IgnoreResult<T>;
4106
+ }
4107
+ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflictArg<T> | undefined> {
4108
+ private query;
4109
+ private onConflict;
4110
+ constructor(query: T, onConflict: Arg);
3982
4111
  /**
3983
4112
  * Available only after `onConflict`.
3984
4113
  *
3985
- * Modifies a create query, to turn it into an 'upsert' operation.
3986
- *
3987
- * Adds an `ON CONFLICT (columns) DO UPDATE` clause to the insert statement.
3988
- *
3989
- * When no `onConflict` argument provided,
3990
- * it will automatically collect all table columns that have unique index and use them as a conflict target.
4114
+ * Updates the record with a given data when conflict occurs.
3991
4115
  *
3992
4116
  * ```ts
3993
- * db.table
3994
- * .create({
3995
- * email: 'ignore@example.com',
3996
- * name: 'John Doe',
3997
- * })
3998
- * .onConflict('email')
3999
- * .merge();
4117
+ * db.table.create(data).onConflict('column').set({
4118
+ * description: 'setting different data on conflict',
4119
+ * });
4000
4120
  * ```
4001
4121
  *
4002
- * This also works with batch creates:
4122
+ * The `set` can take a raw SQL expression:
4003
4123
  *
4004
4124
  * ```ts
4005
4125
  * db.table
4006
- * .createMany([
4007
- * { email: 'john@example.com', name: 'John Doe' },
4008
- * { email: 'jane@example.com', name: 'Jane Doe' },
4009
- * { email: 'alex@example.com', name: 'Alex Doe' },
4010
- * ])
4011
- * .onConflict('email')
4012
- * .merge();
4013
- * ```
4014
- *
4015
- * It is also possible to specify a subset of the columns to merge when a conflict occurs.
4016
- * For example, you may want to set a `createdAt` column when creating but would prefer not to update it if the row already exists:
4017
- *
4018
- * ```ts
4019
- * const timestamp = Date.now();
4126
+ * .create(data)
4127
+ * .onConflict()
4128
+ * .set(db.table.sql`raw SQL expression`);
4020
4129
  *
4130
+ * // update records only on certain conditions
4021
4131
  * db.table
4022
- * .create({
4023
- * email: 'ignore@example.com',
4024
- * name: 'John Doe',
4025
- * createdAt: timestamp,
4026
- * updatedAt: timestamp,
4027
- * })
4132
+ * .create(data)
4028
4133
  * .onConflict('email')
4029
- * // string argument for a single column:
4030
- * .merge('email')
4031
- * // array of strings for multiple columns:
4032
- * .merge(['email', 'name', 'updatedAt']);
4134
+ * .set({ key: 'value' })
4135
+ * .where({ ...certainConditions });
4033
4136
  * ```
4034
4137
  *
4035
- * It is also possible to specify data to update separately from the data to create.
4036
- * This is useful if you want to make an update with different data than in creating.
4037
- * For example, you may want to change a value if the row already exists:
4138
+ * @param set - object containing new column values, or raw SQL
4139
+ */
4140
+ set(set: Partial<T['inputType']> | Expression): T;
4141
+ /**
4142
+ * Available only after `onConflict`.
4038
4143
  *
4039
- * ```ts
4040
- * const timestamp = Date.now();
4144
+ * Use this method to merge all the data you have passed into `create` to update the existing record on conflict.
4041
4145
  *
4042
- * db.table
4043
- * .create({
4044
- * email: 'ignore@example.com',
4045
- * name: 'John Doe',
4046
- * createdAt: timestamp,
4047
- * updatedAt: timestamp,
4048
- * })
4049
- * .onConflict('email')
4050
- * .merge({
4051
- * name: 'John Doe The Second',
4052
- * });
4053
- * ```
4146
+ * If the table has columns with **dynamic** default values, such values will be applied as well.
4054
4147
  *
4055
- * It is also possible to add a WHERE clause to conditionally update only the matching rows:
4148
+ * You can exclude certain columns from being merged by passing the `exclude` option.
4056
4149
  *
4057
4150
  * ```ts
4058
- * const timestamp = Date.now();
4151
+ * // merge the full data
4152
+ * db.table.create(data).onConflict('email').merge();
4153
+ *
4154
+ * // merge only a single column
4155
+ * db.table.create(data).onConflict('email').merge('name');
4156
+ *
4157
+ * // merge multiple columns
4158
+ * db.table.create(data).onConflict('email').merge(['name', 'quantity']);
4059
4159
  *
4160
+ * // merge all columns except some
4060
4161
  * db.table
4061
- * .create({
4062
- * email: 'ignore@example.com',
4063
- * name: 'John Doe',
4064
- * createdAt: timestamp,
4065
- * updatedAt: timestamp,
4066
- * })
4162
+ * .create(data)
4067
4163
  * .onConflict('email')
4068
- * .merge({
4069
- * name: 'John Doe',
4070
- * updatedAt: timestamp,
4071
- * })
4072
- * .where({ updatedAt: { lt: timestamp } });
4073
- * ```
4164
+ * .merge({ except: ['name', 'quantity'] });
4074
4165
  *
4075
- * `merge` also accepts raw expression:
4166
+ * // merge can be applied also for batch creates
4167
+ * db.table.createMany([data1, data2, data2]).onConflict('email').merge();
4076
4168
  *
4077
- * ```ts
4169
+ * // update records only on certain conditions
4078
4170
  * db.table
4079
4171
  * .create(data)
4080
- * .onConflict()
4081
- * .merge(db.table.sql`raw SQL expression`);
4172
+ * .onConflict('email')
4173
+ * .merge()
4174
+ * .where({ ...certainConditions });
4082
4175
  * ```
4083
4176
  *
4084
- * @param update - column, or array of columns, or object for new column values, or raw SQL
4177
+ * @param merge - no argument will merge all data, or provide a column(s) to merge, or provide `except` to update all except some.
4085
4178
  */
4086
- merge(update?: keyof T['shape'] | (keyof T['shape'])[] | Partial<T['inputType']> | Expression): T;
4179
+ merge(merge?: keyof T['shape'] | (keyof T['shape'])[] | {
4180
+ except: keyof T['shape'] | (keyof T['shape'])[];
4181
+ }): T;
4087
4182
  }
4088
4183
 
4089
4184
  type DeleteMethodsNames = 'delete';
@@ -4170,7 +4265,7 @@ type FromResult<T extends FromQuerySelf, Arg extends FromArg<T>> = Arg extends s
4170
4265
  column: Arg['result'][K];
4171
4266
  } : never;
4172
4267
  } : T['meta'][K];
4173
- } : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends 'then' ? QueryThen<GetQueryResult<T, Arg['result']>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, Arg['result']>> : T[K];
4268
+ } : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends 'then' ? QueryThen<GetQueryResult<T, Arg['result']>> : T[K];
4174
4269
  } : T;
4175
4270
  declare function queryFrom<T extends FromQuerySelf, Arg extends FromArg<T>>(self: T, arg: Arg, options?: FromArgOptions): FromResult<T, Arg>;
4176
4271
  declare function queryFromSql<T extends FromQuerySelf>(self: T, args: SQLQueryArgs): T;
@@ -4644,7 +4739,7 @@ declare class QueryLog {
4644
4739
  type MergeQuery<T extends PickQueryMetaResultReturnTypeWithDataWindows, Q extends PickQueryMetaResultReturnTypeWithDataWindows> = {
4645
4740
  [K in keyof T]: K extends 'meta' ? {
4646
4741
  [K in keyof T['meta'] | keyof Q['meta']]: K extends 'selectable' ? MergeObjects<T['meta']['selectable'], Q['meta']['selectable']> : K extends keyof Q['meta'] ? Q['meta'][K] : T['meta'][K];
4647
- } : K extends 'result' ? MergeQueryResult<T, Q> : K extends 'returnType' ? QueryReturnType extends Q['returnType'] ? T['returnType'] : Q['returnType'] : K extends 'then' ? QueryThen<GetQueryResult<QueryReturnType extends Q['returnType'] ? T : Q, MergeQueryResult<T, Q>>> : K extends 'catch' ? QueryCatch<GetQueryResult<QueryReturnType extends Q['returnType'] ? T : Q, MergeQueryResult<T, Q>>> : K extends 'windows' ? MergeObjects<T['windows'], Q['windows']> : K extends 'withData' ? MergeObjects<T['withData'], Q['withData']> : T[K];
4742
+ } : K extends 'result' ? MergeQueryResult<T, Q> : K extends 'returnType' ? QueryReturnType extends Q['returnType'] ? T['returnType'] : Q['returnType'] : K extends 'then' ? QueryThen<GetQueryResult<QueryReturnType extends Q['returnType'] ? T : Q, MergeQueryResult<T, Q>>> : K extends 'windows' ? MergeObjects<T['windows'], Q['windows']> : K extends 'withData' ? MergeObjects<T['withData'], Q['withData']> : T[K];
4648
4743
  };
4649
4744
  type MergeQueryResult<T extends PickQueryMetaResult, Q extends PickQueryMetaResult> = T['meta']['hasSelect'] extends true ? Q['meta']['hasSelect'] extends true ? {
4650
4745
  [K in keyof T['result'] | keyof Q['result']]: K extends keyof Q['result'] ? Q['result'][K] : T['result'][K];
@@ -4653,7 +4748,9 @@ declare class MergeQueryMethods {
4653
4748
  merge<T extends Query, Q extends Query>(this: T, q: Q): MergeQuery<T, Q>;
4654
4749
  }
4655
4750
 
4656
- declare const queryMethodByReturnType: Record<QueryReturnType, 'query' | 'arrays'>;
4751
+ declare const queryMethodByReturnType: {
4752
+ [K in QueryReturnType]: 'query' | 'arrays';
4753
+ };
4657
4754
  type Resolve = (result: any) => any;
4658
4755
  type Reject = (error: any) => any;
4659
4756
  declare class Then {
@@ -4689,10 +4786,6 @@ type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = {
4689
4786
  [K in Columns[number] | keyof T['shape'] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
4690
4787
  } : {
4691
4788
  [K in Columns[number] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
4692
- }) & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, ('*' extends Columns[number] ? {
4693
- [K in Columns[number] | keyof T['shape'] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
4694
- } : {
4695
- [K in Columns[number] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
4696
4789
  }) & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : T[K];
4697
4790
  } & QueryMetaHasSelect;
4698
4791
  type SelectResultObj<T extends SelectSelf, Obj> = {
@@ -4702,8 +4795,6 @@ type SelectResultObj<T extends SelectSelf, Obj> = {
4702
4795
  [K in keyof Obj | (T['meta']['hasSelect'] extends true ? keyof T['result'] : never)]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never;
4703
4796
  } : K extends 'then' ? QueryThen<GetQueryResult<T, {
4704
4797
  [K in keyof Obj | (T['meta']['hasSelect'] extends true ? keyof T['result'] : never)]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never;
4705
- }>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, {
4706
- [K in keyof Obj | (T['meta']['hasSelect'] extends true ? keyof T['result'] : never)]: K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : K extends keyof T['result'] ? T['result'][K] : never;
4707
4798
  }>> : T[K];
4708
4799
  } & QueryMetaHasSelect;
4709
4800
  type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj> = {
@@ -4714,8 +4805,6 @@ type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey
4714
4805
  [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | keyof T['shape'] : Columns[number]) | keyof Obj as K extends keyof T['meta']['selectable'] ? T['meta']['selectable'][K]['as'] : K]: K extends keyof T['meta']['selectable'] ? T['meta']['selectable'][K]['column'] : K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : never;
4715
4806
  } & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown) : K extends 'then' ? QueryThen<GetQueryResult<T, {
4716
4807
  [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | keyof T['shape'] : Columns[number]) | keyof Obj as K extends keyof T['meta']['selectable'] ? T['meta']['selectable'][K]['as'] : K]: K extends keyof T['meta']['selectable'] ? T['meta']['selectable'][K]['column'] : K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : never;
4717
- } & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, {
4718
- [K in ('*' extends Columns[number] ? Exclude<Columns[number], '*'> | keyof T['shape'] : Columns[number]) | keyof Obj as K extends keyof T['meta']['selectable'] ? T['meta']['selectable'][K]['as'] : K]: K extends keyof T['meta']['selectable'] ? T['meta']['selectable'][K]['column'] : K extends keyof Obj ? SelectAsValueResult<T, Obj[K]> : never;
4719
4808
  } & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : T[K];
4720
4809
  } & QueryMetaHasSelect;
4721
4810
  type SelectAsSelectable<Arg> = {
@@ -4898,7 +4987,9 @@ declare class With {
4898
4987
 
4899
4988
  type UnionArg<T extends PickQueryResult> = {
4900
4989
  result: {
4901
- [K in keyof T['result']]: Pick<T['result'][K], 'dataType'>;
4990
+ [K in keyof T['result']]: {
4991
+ dataType: T['result'][K]['dataType'];
4992
+ };
4902
4993
  };
4903
4994
  } | Expression;
4904
4995
  declare class Union {
@@ -4957,7 +5048,9 @@ declare class Union {
4957
5048
  exceptAll<T extends PickQueryResult>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
4958
5049
  }
4959
5050
 
4960
- type UpdateSelf = Pick<Query, 'meta' | 'inputType' | 'relations' | 'shape' | 'result' | 'returnType' | keyof JsonModifiers>;
5051
+ type UpdateSelf = {
5052
+ [K in 'meta' | 'inputType' | 'relations' | 'shape' | 'result' | 'returnType' | keyof JsonModifiers]: Query[K];
5053
+ };
4961
5054
  type UpdateData<T extends UpdateSelf> = {
4962
5055
  [K in keyof T['inputType']]?: UpdateColumn<T, K>;
4963
5056
  } & {
@@ -4983,10 +5076,14 @@ type UpdateResult<T extends UpdateSelf> = T['meta']['hasSelect'] extends true ?
4983
5076
  type ChangeCountArg<T extends PickQueryShape> = keyof T['shape'] | {
4984
5077
  [K in keyof T['shape']]?: number;
4985
5078
  };
4986
- type UpdateCtx = {
5079
+ interface UpdateCtx {
4987
5080
  queries?: ((queryResult: QueryResult) => Promise<void>)[];
4988
- updateData?: RecordUnknown;
4989
- };
5081
+ collect?: UpdateCtxCollect;
5082
+ }
5083
+ interface UpdateCtxCollect {
5084
+ keys: string[];
5085
+ data: RecordUnknown;
5086
+ }
4990
5087
  declare const _queryChangeCounter: <T extends UpdateSelf>(self: T, op: string, data: ChangeCountArg<T>) => never;
4991
5088
  declare const _queryUpdate: <T extends UpdateSelf>(query: T, arg: UpdateArg<T>) => UpdateResult<T>;
4992
5089
  declare const _queryUpdateRaw: <T extends UpdateSelf>(q: T, sql: Expression) => UpdateResult<T>;
@@ -5741,26 +5838,6 @@ declare class QueryUpsertOrCreate {
5741
5838
  orCreate<T extends UpsertThis>(this: T, data: OrCreateArg<T>): UpsertResult<T>;
5742
5839
  }
5743
5840
 
5744
- declare const templateLiteralToSQL: (template: TemplateLiteralArgs, ctx: ToSQLCtx, quotedAs?: string) => string;
5745
- declare class RawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>> extends RawSQLBase<T, ColumnTypes> {
5746
- columnTypes: ColumnTypes;
5747
- constructor(sql: string | TemplateLiteralArgs, values?: RawSQLValues, type?: T);
5748
- makeSQL(ctx: ToSQLCtx, quotedAs?: string): string;
5749
- }
5750
- interface DynamicRawSQL<T extends QueryColumn> extends Expression<T>, ExpressionTypeMethod {
5751
- }
5752
- declare class DynamicRawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>> extends Expression<T> {
5753
- fn: DynamicSQLArg;
5754
- _type: T;
5755
- columnTypes: ColumnTypes;
5756
- constructor(fn: DynamicSQLArg);
5757
- makeSQL(ctx: ToSQLCtx, quotedAs?: string): string;
5758
- }
5759
- declare function raw<T = unknown>(...args: StaticSQLArgs): RawSQL<QueryColumn<T>>;
5760
- declare function raw<T = unknown>(...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>>;
5761
- declare const countSelect: RawSQL<QueryColumn<unknown, orchid_core.CoreBaseOperators>, DefaultColumnTypes<ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>>>[];
5762
- declare function sqlQueryArgsToExpression(args: SQLQueryArgs): RawSQL<QueryColumn>;
5763
-
5764
5841
  declare abstract class RawSqlMethods<ColumnTypes> {
5765
5842
  /**
5766
5843
  * When there is a need to use a piece of raw SQL, use the `sql` method from tables, or a `raw` function imported from `orchid-orm`.
@@ -5919,11 +5996,11 @@ declare abstract class RawSqlMethods<ColumnTypes> {
5919
5996
  }, ...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>, ColumnTypes>;
5920
5997
  }
5921
5998
 
5922
- type QueryTransformFn<T extends Query> = (input: T['catch'] extends QueryCatch<infer Data> ? Data : never) => unknown;
5999
+ type QueryTransformFn<T extends Query> = (input: T['then'] extends QueryThen<infer Data> ? Data : never) => unknown;
5923
6000
  type QueryTransform<T extends QueryBase, Data> = {
5924
6001
  [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
5925
6002
  value: QueryColumn<Data>;
5926
- } : K extends 'then' ? QueryThen<Data> : K extends 'catch' ? QueryCatch<Data> : T[K];
6003
+ } : K extends 'then' ? QueryThen<Data> : T[K];
5927
6004
  };
5928
6005
  declare class TransformMethods {
5929
6006
  /**
@@ -5988,7 +6065,9 @@ interface WindowArgDeclaration<T extends OrderArgSelf = OrderArgSelf> {
5988
6065
  order?: OrderArg<T>;
5989
6066
  }
5990
6067
  type WindowResult<T, W extends RecordUnknown> = T & {
5991
- windows: Record<keyof W, true>;
6068
+ windows: {
6069
+ [K in keyof W]: true;
6070
+ };
5992
6071
  };
5993
6072
  type OrderArgSelf = PickQueryMetaResult;
5994
6073
  type OrderArg<T extends OrderArgSelf> = OrderArgKey<T> | OrderArgTsQuery<T> | {
@@ -6002,7 +6081,7 @@ type OrderArgs<T extends OrderArgSelf> = OrderArg<T>[];
6002
6081
  type GroupArg<T extends PickQueryResult> = {
6003
6082
  [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' ? never : K;
6004
6083
  }[keyof T['result']] | Expression;
6005
- type FindArg<T extends PickQueryShapeSinglePrimaryKey> = T['shape'][T['singlePrimaryKey']]['queryType'] | Expression;
6084
+ type FindArg<T extends PickQueryShapeSinglePrimaryKey> = T['internal']['singlePrimaryKey'] | Expression;
6006
6085
  type QueryHelper<T extends PickQueryMetaShape, Args extends unknown[], Result> = {
6007
6086
  <Q extends {
6008
6087
  returnType: QueryReturnType;
@@ -6142,20 +6221,11 @@ declare class QueryMethods<ColumnTypes> {
6142
6221
  */
6143
6222
  distinct<T extends PickQueryMeta>(this: T, ...columns: SelectableOrExpression<T>[]): T;
6144
6223
  /**
6145
- * The `find` method is available only for tables which has exactly one primary key.
6146
- * And also it can accept raw SQL template literal, then the primary key is not required.
6147
- *
6148
- * Finds a record by id, throws {@link NotFoundError} if not found:
6149
- *
6150
- * ```ts
6151
- * await db.table.find(1);
6152
- * ```
6224
+ * Finds a single record by the primary key (id), throws [NotFoundError](/guide/error-handling.html) if not found.
6225
+ * Not available if the table has no or multiple primary keys.
6153
6226
  *
6154
6227
  * ```ts
6155
- * await db.user.find`
6156
- * age = ${age} AND
6157
- * name = ${name}
6158
- * `;
6228
+ * const result: TableType = await db.table.find(1);
6159
6229
  * ```
6160
6230
  *
6161
6231
  * @param value - primary key value to find by
@@ -6173,10 +6243,10 @@ declare class QueryMethods<ColumnTypes> {
6173
6243
  *
6174
6244
  * @param args - SQL expression
6175
6245
  */
6176
- findBySql<T extends PickQueryShapeResultSinglePrimaryKey>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOne<WhereResult<T>>;
6246
+ findBySql<T extends PickQueryResult>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOne<WhereResult<T>>;
6177
6247
  /**
6178
- * Find a single record by the primary key (id), adds `LIMIT 1`.
6179
- * Returns `undefined` when not found.
6248
+ * Finds a single record by the primary key (id), returns `undefined` when not found.
6249
+ * Not available if the table has no or multiple primary keys.
6180
6250
  *
6181
6251
  * ```ts
6182
6252
  * const result: TableType | undefined = await db.table.find(123);
@@ -6198,33 +6268,35 @@ declare class QueryMethods<ColumnTypes> {
6198
6268
  *
6199
6269
  * @param args - SQL expression
6200
6270
  */
6201
- findBySqlOptional<T extends PickQueryShapeResultSinglePrimaryKey>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOneOptional<WhereResult<T>>;
6271
+ findBySqlOptional<T extends PickQueryResult>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOneOptional<WhereResult<T>>;
6202
6272
  /**
6203
- * The same as `where(conditions).take()`, takes the same arguments as {@link Where.where}, it will filter records and add a `LIMIT 1`.
6204
- * Throws `NotFoundError` if not found.
6273
+ * Finds a single unique record, throws [NotFoundError](/guide/error-handling.html) if not found.
6274
+ * It accepts values of primary keys or unique indexes defined on the table.
6275
+ * `findBy`'s argument type is a union of all possible sets of unique conditions.
6276
+ *
6277
+ * You can use `where(...).take()` for non-unique conditions.
6205
6278
  *
6206
6279
  * ```ts
6207
- * const result: TableType = await db.table.findBy({ key: 'value' });
6208
- * // is equivalent to:
6209
- * db.table.where({ key: 'value' }).take()
6280
+ * await db.table.findBy({ key: 'value' });
6210
6281
  * ```
6211
6282
  *
6212
- * @param args - `where` conditions
6283
+ * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
6213
6284
  */
6214
- findBy<T extends PickQueryMetaResultRelations>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOne<WhereResult<T>>;
6285
+ findBy<T extends PickQueryResultUniqueColumns>(this: T, uniqueColumnValues: T['internal']['uniqueColumns']): SetQueryReturnsOne<WhereResult<T>>;
6215
6286
  /**
6216
- * The same as `where(conditions).takeOptional()`, it will filter records and add a `LIMIT 1`.
6217
- * Returns `undefined` when not found.
6287
+ * Finds a single unique record, returns `undefined` if not found.
6288
+ * It accepts values of primary keys or unique indexes defined on the table.
6289
+ * `findBy`'s argument type is a union of all possible sets of unique conditions.
6290
+ *
6291
+ * You can use `where(...).takeOptional()` for non-unique conditions.
6218
6292
  *
6219
6293
  * ```ts
6220
- * const result: TableType | undefined = await db.table.findByOptional({
6221
- * key: 'value',
6222
- * });
6294
+ * await db.table.findByOptional({ key: 'value' });
6223
6295
  * ```
6224
6296
  *
6225
- * @param args - `where` conditions
6297
+ * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
6226
6298
  */
6227
- findByOptional<T extends PickQueryMetaResultRelations>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOneOptional<WhereResult<T>>;
6299
+ findByOptional<T extends PickQueryResultUniqueColumns>(this: T, uniqueColumnValues: T['internal']['uniqueColumns']): SetQueryReturnsOneOptional<WhereResult<T>>;
6228
6300
  /**
6229
6301
  * Specifies the schema to be used as a prefix of a table name.
6230
6302
  *
@@ -6345,9 +6417,9 @@ declare class QueryMethods<ColumnTypes> {
6345
6417
  * Order by raw SQL expression.
6346
6418
  *
6347
6419
  * ```ts
6348
- * db.table.order`raw sql`;
6420
+ * db.table.orderSql`raw sql`;
6349
6421
  * // or
6350
- * db.table.order(db.table.sql`raw sql`);
6422
+ * db.table.orderSql(db.table.sql`raw sql`);
6351
6423
  * ```
6352
6424
  *
6353
6425
  * @param args - SQL expression
@@ -6541,9 +6613,16 @@ type DbDomainArg<ColumnTypes> = (columnTypes: ColumnTypes) => ColumnType;
6541
6613
  type DbDomainArgRecord = {
6542
6614
  [K: string]: DbDomainArg<any>;
6543
6615
  };
6544
- interface QueryInternal extends QueryInternalBase, TableData {
6616
+ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColumnNames = any, UniqueColumnTuples = any, UniqueConstraints = any> extends QueryInternalBase {
6617
+ singlePrimaryKey: SinglePrimaryKey;
6618
+ uniqueColumns: UniqueColumns;
6619
+ uniqueColumnNames: UniqueColumnNames;
6620
+ uniqueColumnTuples: UniqueColumnTuples;
6621
+ uniqueConstraints: UniqueConstraints;
6545
6622
  extensions?: DbExtension[];
6546
6623
  domains?: DbDomainArgRecord;
6624
+ tableData: TableData;
6625
+ primaryKeys?: string[];
6547
6626
  }
6548
6627
  type SelectableFromShape<Shape extends QueryColumns, Table extends string | undefined> = {
6549
6628
  [K in keyof Shape]: {
@@ -6568,12 +6647,10 @@ interface Query extends QueryBase, QueryMethods<unknown> {
6568
6647
  queryBuilder: Db;
6569
6648
  columnTypes: unknown;
6570
6649
  shape: QueryColumns;
6571
- singlePrimaryKey: string;
6572
- primaryKeys: string[];
6573
6650
  inputType: RecordUnknown;
6574
6651
  q: QueryData;
6575
6652
  then: QueryThen<unknown>;
6576
- catch: QueryCatch<unknown>;
6653
+ catch: QueryCatch;
6577
6654
  windows: EmptyObject;
6578
6655
  defaultSelectColumns: string[];
6579
6656
  relations: RelationsBase;
@@ -6632,7 +6709,9 @@ interface PickQueryQAndInternal extends PickQueryQ, PickQueryInternal {
6632
6709
  interface PickQueryQAndBaseQuery extends PickQueryQ, PickQueryBaseQuery {
6633
6710
  }
6634
6711
  interface PickQuerySinglePrimaryKey {
6635
- singlePrimaryKey: string;
6712
+ internal: {
6713
+ singlePrimaryKey: unknown;
6714
+ };
6636
6715
  }
6637
6716
  interface PickQueryShapeSinglePrimaryKey extends PickQueryShape, PickQuerySinglePrimaryKey {
6638
6717
  }
@@ -6645,14 +6724,24 @@ type SelectableOrExpressionOfType<T extends PickQueryMeta, C extends PickType> =
6645
6724
  interface QueryWithTable extends Query {
6646
6725
  table: string;
6647
6726
  }
6648
- declare const queryTypeWithLimitOne: Record<QueryReturnType, true | undefined>;
6727
+ declare const queryTypeWithLimitOne: {
6728
+ all: true | undefined;
6729
+ one: true | undefined;
6730
+ oneOrThrow: true | undefined;
6731
+ rows: true | undefined;
6732
+ pluck: true | undefined;
6733
+ value: true | undefined;
6734
+ valueOrThrow: true | undefined;
6735
+ rowCount: true | undefined;
6736
+ void: true | undefined;
6737
+ };
6649
6738
  declare const isQueryReturnsAll: (q: Query) => boolean;
6650
6739
  type QueryReturnsAll<T extends QueryReturnType> = (QueryReturnType extends T ? 'all' : T) extends 'all' ? true : false;
6651
6740
  type GetQueryResult<T extends PickQueryReturnType, Result extends QueryColumns> = QueryReturnsAll<T['returnType']> extends true ? ColumnShapeOutput<Result>[] : T['returnType'] extends 'one' ? ColumnShapeOutput<Result> | undefined : T['returnType'] extends 'oneOrThrow' ? ColumnShapeOutput<Result> : T['returnType'] extends 'value' ? Result['value']['outputType'] | undefined : T['returnType'] extends 'valueOrThrow' ? Result['value']['outputType'] : T['returnType'] extends 'rows' ? ColumnShapeOutput<Result>[keyof Result][][] : T['returnType'] extends 'pluck' ? Result['pluck']['outputType'][] : T['returnType'] extends 'rowCount' ? number : T['returnType'] extends 'void' ? void : never;
6652
6741
  type AddQuerySelect<T extends PickQueryMetaResultReturnType, Result extends QueryColumns> = {
6653
6742
  [K in keyof T]: K extends 'result' ? {
6654
6743
  [K in (T['meta']['hasSelect'] extends true ? keyof T['result'] : never) | keyof Result]: K extends keyof Result ? Result[K] : K extends keyof T['result'] ? T['result'][K] : never;
6655
- } : K extends 'then' ? QueryThen<GetQueryResult<T, Result>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, Result>> : T[K];
6744
+ } : K extends 'then' ? QueryThen<GetQueryResult<T, Result>> : T[K];
6656
6745
  } & QueryMetaHasSelect;
6657
6746
  interface QueryMetaHasSelect {
6658
6747
  meta: {
@@ -6660,71 +6749,71 @@ interface QueryMetaHasSelect {
6660
6749
  };
6661
6750
  }
6662
6751
  type SetQueryReturnsAll<T extends PickQueryResult> = {
6663
- [K in keyof T]: K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : K extends 'catch' ? QueryCatch<ColumnShapeOutput<T['result']>[]> : T[K];
6752
+ [K in keyof T]: K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : T[K];
6664
6753
  } & QueryMetaHasWhere;
6665
6754
  type SetQueryReturnsAllKind<T extends PickQueryMetaResult, Kind extends string> = {
6666
6755
  [K in keyof T]: K extends 'meta' ? {
6667
6756
  [K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
6668
- } : K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : K extends 'catch' ? QueryCatch<ColumnShapeOutput<T['result']>[]> : T[K];
6757
+ } : K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : T[K];
6669
6758
  } & QueryMetaHasWhere;
6670
6759
  type SetQueryReturnsOneOptional<T extends PickQueryResult> = {
6671
- [K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']> | undefined> : K extends 'catch' ? QueryCatch<ColumnShapeOutput<T['result']> | undefined> : T[K];
6760
+ [K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']> | undefined> : T[K];
6672
6761
  };
6673
6762
  type SetQueryReturnsOne<T extends PickQueryResult> = {
6674
- [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : K extends 'catch' ? QueryCatch<ColumnShapeOutput<T['result']>> : T[K];
6763
+ [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : T[K];
6675
6764
  };
6676
6765
  type SetQueryReturnsOneKind<T extends PickQueryMetaResult, Kind extends string> = {
6677
6766
  [K in keyof T]: K extends 'meta' ? {
6678
6767
  [K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
6679
- } : K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : K extends 'catch' ? QueryCatch<ColumnShapeOutput<T['result']>> : T[K];
6768
+ } : K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : T[K];
6680
6769
  };
6681
6770
  type SetQueryReturnsRows<T extends PickQueryResult> = {
6682
- [K in keyof T]: K extends 'returnType' ? 'rows' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[keyof T['result']][][]> : K extends 'catch' ? QueryCatch<ColumnShapeOutput<T['result']>[keyof T['result']][][]> : T[K];
6771
+ [K in keyof T]: K extends 'returnType' ? 'rows' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[keyof T['result']][][]> : T[K];
6683
6772
  };
6684
6773
  type SetQueryReturnsPluck<T extends PickQueryMeta, S extends keyof T['meta']['selectable'] | Expression> = SetQueryReturnsPluckColumn<T, S extends keyof T['meta']['selectable'] ? T['meta']['selectable'][S]['column'] : S extends Expression ? S['_type'] : never>;
6685
6774
  type SetQueryReturnsPluckColumn<T, C extends QueryColumn> = {
6686
6775
  [K in keyof T]: K extends 'result' ? {
6687
6776
  pluck: C;
6688
- } : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<C['outputType'][]> : K extends 'catch' ? QueryCatch<C['outputType'][]> : T[K];
6777
+ } : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<C['outputType'][]> : T[K];
6689
6778
  } & QueryMetaHasSelect;
6690
6779
  type SetQueryReturnsPluckColumnKind<T extends PickQueryMetaResult, Kind extends string> = {
6691
6780
  [K in keyof T]: K extends 'meta' ? {
6692
6781
  [K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
6693
6782
  } : K extends 'result' ? {
6694
6783
  pluck: T['result']['value'];
6695
- } : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['result']['value']['outputType'][]> : K extends 'catch' ? QueryCatch<T['result']['value']['outputType'][]> : T[K];
6784
+ } : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['result']['value']['outputType'][]> : T[K];
6696
6785
  } & QueryMetaHasSelect;
6697
6786
  type SetQueryReturnsValueOrThrow<T extends PickQueryMeta, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOrThrow<T, T['meta']['selectable'][Arg]['column']> & T['meta']['selectable'][Arg]['column']['operators'];
6698
6787
  type SetQueryReturnsValueOptional<T extends PickQueryMeta, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOptional<T, T['meta']['selectable'][Arg]['column']> & T['meta']['selectable'][Arg]['column']['operators'];
6699
6788
  type SetQueryReturnsColumnOrThrow<T, Column extends PickOutputType> = {
6700
6789
  [K in keyof T]: K extends 'result' ? {
6701
6790
  value: Column;
6702
- } : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['outputType']> : K extends 'catch' ? QueryCatch<Column['outputType']> : T[K];
6791
+ } : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['outputType']> : T[K];
6703
6792
  } & QueryMetaHasSelect;
6704
6793
  type SetQueryReturnsColumnOptional<T, Column extends PickOutputType> = {
6705
6794
  [K in keyof T]: K extends 'result' ? {
6706
6795
  value: Column;
6707
- } : K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<Column['outputType'] | undefined> : K extends 'catch' ? QueryCatch<Column['outputType'] | undefined> : T[K];
6796
+ } : K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<Column['outputType'] | undefined> : T[K];
6708
6797
  } & QueryMetaHasSelect;
6709
6798
  type SetQueryReturnsColumnKind<T extends PickQueryMetaResult, Kind extends string> = {
6710
6799
  [K in keyof T]: K extends 'meta' ? {
6711
6800
  [K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
6712
6801
  } : K extends 'result' ? {
6713
6802
  value: T['result']['pluck'];
6714
- } : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['pluck']['outputType']> : K extends 'catch' ? QueryCatch<T['result']['pluck']['outputType']> : T[K];
6803
+ } : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['pluck']['outputType']> : T[K];
6715
6804
  } & QueryMetaHasSelect;
6716
6805
  type SetQueryReturnsRowCount<T extends PickQueryMetaResult, Kind extends string> = {
6717
6806
  [K in keyof T]: K extends 'meta' ? {
6718
6807
  [K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
6719
- } : K extends 'returnType' ? 'rowCount' : K extends 'then' ? QueryThen<number> : K extends 'catch' ? QueryCatch<number> : T[K];
6808
+ } : K extends 'returnType' ? 'rowCount' : K extends 'then' ? QueryThen<number> : T[K];
6720
6809
  };
6721
6810
  type SetQueryReturnsVoid<T> = {
6722
- [K in keyof T]: K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : K extends 'catch' ? QueryCatch<void> : T[K];
6811
+ [K in keyof T]: K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : T[K];
6723
6812
  };
6724
6813
  type SetQueryReturnsVoidKind<T extends PickQueryMeta, Kind extends string> = {
6725
6814
  [K in keyof T]: K extends 'meta' ? {
6726
6815
  [K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
6727
- } : K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : K extends 'catch' ? QueryCatch<void> : T[K];
6816
+ } : K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : T[K];
6728
6817
  };
6729
6818
  type SetQueryKind<T extends PickQueryMeta, Kind extends string> = {
6730
6819
  [K in keyof T]: K extends 'meta' ? {
@@ -6754,76 +6843,14 @@ interface ColumnData extends ColumnDataBase {
6754
6843
  numericScale?: number;
6755
6844
  dateTimePrecision?: number;
6756
6845
  validationDefault?: unknown;
6757
- indexes?: Omit<SingleColumnIndexOptions, 'column'>[];
6846
+ indexes?: TableData.ColumnIndex[];
6758
6847
  comment?: string;
6759
6848
  collate?: string;
6760
6849
  compression?: string;
6761
- foreignKeys?: ForeignKey<string, string[]>[];
6850
+ foreignKeys?: TableData.ColumnReferences[];
6762
6851
  identity?: TableData.Identity;
6763
6852
  generated?: RawSQLBase;
6764
6853
  }
6765
- /**
6766
- * - MATCH FULL will not allow one column of a multicolumn foreign key to be null unless all foreign key columns are null;
6767
- * if they are all null, the row is not required to have a match in the referenced table.
6768
- * - MATCH SIMPLE (default) allows any of the foreign key columns to be null; if any of them are null, the row is not required to have a match in the referenced table.
6769
- * - MATCH PARTIAL - PG docs say it's not implemented.
6770
- */
6771
- type ForeignKeyMatch = 'FULL' | 'PARTIAL' | 'SIMPLE';
6772
- /**
6773
- * - NO ACTION Produce an error indicating that the deletion or update would create a foreign key constraint violation. If the constraint is deferred, this error will be produced at constraint check time if there still exist any referencing rows. This is the default action.
6774
- * - RESTRICT Produce an error indicating that the deletion or update would create a foreign key constraint violation. This is the same as NO ACTION except that the check is not deferrable.
6775
- * - CASCADE Delete any rows referencing the deleted row, or update the values of the referencing column(s) to the new values of the referenced columns, respectively.
6776
- * - SET NULL Set all the referencing columns, or a specified subset of the referencing columns, to null. A subset of columns can only be specified for ON DELETE actions.
6777
- * - SET DEFAULT Set all the referencing columns, or a specified subset of the referencing columns, to their default values. A subset of columns can only be specified for ON DELETE actions. (There must be a row in the referenced table matching the default values, if they are not null, or the operation will fail.)
6778
- */
6779
- type ForeignKeyAction = 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
6780
- type ForeignKey<Table extends string, Columns extends string[]> = ({
6781
- fn(): new () => {
6782
- schema?: string;
6783
- table: Table;
6784
- columns: ColumnsShapeBase;
6785
- };
6786
- } | {
6787
- table: Table;
6788
- }) & {
6789
- columns: Columns;
6790
- } & ForeignKeyOptions;
6791
- type DropMode = 'CASCADE' | 'RESTRICT';
6792
- interface ForeignKeyOptions {
6793
- name?: string;
6794
- match?: ForeignKeyMatch;
6795
- onUpdate?: ForeignKeyAction;
6796
- onDelete?: ForeignKeyAction;
6797
- dropMode?: DropMode;
6798
- }
6799
- interface IndexColumnOptionsForColumn {
6800
- collate?: string;
6801
- opclass?: string;
6802
- order?: string;
6803
- weight?: SearchWeight;
6804
- }
6805
- type IndexColumnOptions = ({
6806
- column: string;
6807
- } | {
6808
- expression: string;
6809
- }) & IndexColumnOptionsForColumn;
6810
- interface IndexOptions {
6811
- name?: string;
6812
- unique?: boolean;
6813
- nullsNotDistinct?: boolean;
6814
- using?: string;
6815
- include?: MaybeArray<string>;
6816
- with?: string;
6817
- tablespace?: string;
6818
- where?: string;
6819
- dropMode?: 'CASCADE' | 'RESTRICT';
6820
- language?: string;
6821
- languageColumn?: string;
6822
- tsVector?: boolean;
6823
- }
6824
- interface SingleColumnIndexOptionsForColumn extends IndexColumnOptionsForColumn, IndexOptions {
6825
- }
6826
- type SingleColumnIndexOptions = IndexColumnOptions & IndexOptions;
6827
6854
  interface ColumnFromDbParams {
6828
6855
  isNullable?: boolean;
6829
6856
  default?: string;
@@ -6851,6 +6878,8 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6851
6878
  * readonly table = 'table';
6852
6879
  * columns = this.setColumns((t) => ({
6853
6880
  * id: t.uuid().primaryKey(),
6881
+ * // database-level name can be passed:
6882
+ * id: t.uuid().primaryKey('primary_key_name'),
6854
6883
  * }));
6855
6884
  * }
6856
6885
  *
@@ -6858,13 +6887,13 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6858
6887
  * db.table.find('97ba9e78-7510-415a-9c03-23d440aec443');
6859
6888
  * ```
6860
6889
  *
6861
- * @param options - to specify a constraint name
6890
+ * @param name - to specify a constraint name
6862
6891
  */
6863
- primaryKey<T extends PickColumnBaseData>(this: T, options?: ConstraintOptions): PrimaryKeyColumn<T>;
6892
+ primaryKey<T extends PickColumnBaseData, Name extends string>(this: T, name?: Name): PrimaryKeyColumn<T, Name>;
6864
6893
  /**
6865
- * Set the foreignKey for the column.
6894
+ * Defines a reference between different tables to enforce data integrity.
6866
6895
  *
6867
- * In `snakeCase` mode, columns of both tables are translated to a snake_case.
6896
+ * In [snakeCase](/guide/orm-and-query-builder.html#snakecase-option) mode, columns of both tables are translated to a snake_case.
6868
6897
  *
6869
6898
  * ```ts
6870
6899
  * import { change } from '../dbScript';
@@ -6876,7 +6905,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6876
6905
  * });
6877
6906
  * ```
6878
6907
  *
6879
- * In the ORM specify a function returning a table class instead of a name:
6908
+ * In the migration it's different from OrchidORM table code where a callback with a table is expected:
6880
6909
  *
6881
6910
  * ```ts
6882
6911
  * export class SomeTable extends BaseTable {
@@ -6885,13 +6914,6 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6885
6914
  * otherTableId: t.integer().foreignKey(() => OtherTable, 'id'),
6886
6915
  * }));
6887
6916
  * }
6888
- *
6889
- * export class OtherTable extends BaseTable {
6890
- * readonly table = 'otherTable';
6891
- * columns = this.setColumns((t) => ({
6892
- * id: t.identity().primaryKey(),
6893
- * }));
6894
- * }
6895
6917
  * ```
6896
6918
  *
6897
6919
  * Optionally you can pass the third argument to `foreignKey` with options:
@@ -6922,7 +6944,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6922
6944
  * change(async (db) => {
6923
6945
  * await db.createTable('table', (t) => ({
6924
6946
  * id: t.integer(),
6925
- * name: t.string(),
6947
+ * name: t.string(), // string is varchar(255)
6926
6948
  * ...t.foreignKey(
6927
6949
  * ['id', 'name'],
6928
6950
  * 'otherTable',
@@ -6942,14 +6964,59 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6942
6964
  * @param column - column in the foreign table to connect with
6943
6965
  * @param options - {@link ForeignKeyOptions}
6944
6966
  */
6945
- foreignKey<T, Table extends ForeignKeyTable, Column extends ColumnNameOfTable<Table>>(this: T, fn: () => Table, column: Column, options?: ForeignKeyOptions): {
6946
- [K in keyof T]: T extends 'foreignKeyData' ? ForeignKey<InstanceType<Table>['table'], [Column]> : T[K];
6947
- };
6948
- foreignKey<T, Table extends string, Column extends string>(this: T, table: Table, column: Column, options?: ForeignKeyOptions): {
6949
- [K in keyof T]: K extends 'foreignKeyData' ? ForeignKey<Table, [Column]> : T[K];
6950
- };
6967
+ foreignKey<T, Table extends ForeignKeyTable, Column extends ColumnNameOfTable<Table>>(this: T, fn: () => Table, column: Column, options?: TableData.References.Options): T;
6968
+ foreignKey<T, Table extends string, Column extends string>(this: T, table: Table, column: Column, options?: TableData.References.Options): T;
6951
6969
  toSQL(): string;
6952
- index<T extends PickColumnData>(this: T, options?: SingleColumnIndexOptionsForColumn): T;
6970
+ /**
6971
+ * Add an index to the column.
6972
+ *
6973
+ * ```ts
6974
+ * import { change } from '../dbScript';
6975
+ *
6976
+ * change(async (db) => {
6977
+ * await db.createTable('table', (t) => ({
6978
+ * // add an index to the name column with default settings:
6979
+ * name: t.text().index(),
6980
+ * // options are described below:
6981
+ * name: t.text().index({ ...options }),
6982
+ * // with a database-level name:
6983
+ * name: t.text().index('custom_index_name'),
6984
+ * // with name and options:
6985
+ * name: t.text().index('custom_index_name', { ...options }),
6986
+ * }));
6987
+ * });
6988
+ * ```
6989
+ *
6990
+ * Possible options are:
6991
+ *
6992
+ * ```ts
6993
+ * type IndexOptions = {
6994
+ * // NULLS NOT DISTINCT: availabe in Postgres 15+, makes sense only for unique index
6995
+ * nullsNotDistinct?: true;
6996
+ * // index algorithm to use such as GIST, GIN
6997
+ * using?: string;
6998
+ * // specify collation:
6999
+ * collate?: string;
7000
+ * // see `opclass` in the Postgres document for creating the index
7001
+ * opclass?: string;
7002
+ * // specify index order such as ASC NULLS FIRST, DESC NULLS LAST
7003
+ * order?: string;
7004
+ * // include columns to an index to optimize specific queries
7005
+ * include?: MaybeArray<string>;
7006
+ * // see "storage parameters" in the Postgres document for creating an index, for example, 'fillfactor = 70'
7007
+ * with?: string;
7008
+ * // The tablespace in which to create the index. If not specified, default_tablespace is consulted, or temp_tablespaces for indexes on temporary tables.
7009
+ * tablespace?: string;
7010
+ * // WHERE clause to filter records for the index
7011
+ * where?: string;
7012
+ * // mode is for dropping the index
7013
+ * mode?: 'CASCADE' | 'RESTRICT';
7014
+ * };
7015
+ * ```
7016
+ *
7017
+ * @param args
7018
+ */
7019
+ index<T extends PickColumnData>(this: T, ...args: [options?: TableData.Index.ColumnArg] | [name: string, options?: TableData.Index.ColumnArg]): T;
6953
7020
  /**
6954
7021
  * `searchIndex` is designed for [full text search](/guide/text-search).
6955
7022
  *
@@ -7052,8 +7119,11 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
7052
7119
  *
7053
7120
  * @param options - index options
7054
7121
  */
7055
- searchIndex<T extends Pick<ColumnType, 'data' | 'dataType'>>(this: T, options?: Omit<IndexOptions, 'tsVector'>): T;
7056
- unique<T extends PickColumnData>(this: T, options?: Omit<SingleColumnIndexOptionsForColumn, 'unique'>): T;
7122
+ searchIndex<T extends {
7123
+ data: ColumnType['data'];
7124
+ dataType: string;
7125
+ }>(this: T, ...args: [options?: TableData.Index.TsVectorColumnArg] | [name: string, options?: TableData.Index.TsVectorColumnArg]): T;
7126
+ unique<T extends PickColumnData, Name extends string>(this: T, ...args: [options?: TableData.Index.UniqueColumnArg] | [name: Name, options?: TableData.Index.UniqueColumnArg]): UniqueColumn<T, Name>;
7057
7127
  comment<T extends PickColumnData>(this: T, comment: string): T;
7058
7128
  compression<T extends PickColumnData>(this: T, compression: string): T;
7059
7129
  collate<T extends PickColumnData>(this: T, collate: string): T;
@@ -7076,9 +7146,89 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
7076
7146
  generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs): T;
7077
7147
  }
7078
7148
 
7149
+ declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, boolean, ReturnType<Schema['boolean']>, OperatorsBoolean> {
7150
+ dataType: "bool";
7151
+ operators: OperatorsBoolean;
7152
+ constructor(schema: Schema);
7153
+ toCode(t: string, m?: boolean): Code;
7154
+ parseItem: (input: string) => boolean;
7155
+ }
7156
+
7157
+ declare class CustomTypeColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, unknown, ReturnType<Schema['unknown']>, typeof Operators.any> {
7158
+ dataType: string;
7159
+ operators: OperatorsAny;
7160
+ constructor(schema: Schema, dataType: string);
7161
+ toCode(t: string, m?: boolean): Code;
7162
+ as<T extends {
7163
+ inputType: unknown;
7164
+ outputType: unknown;
7165
+ data: ColumnDataBase;
7166
+ }, C extends Omit<ColumnTypeBase, 'inputType' | 'outputType'> & {
7167
+ inputType: T['inputType'];
7168
+ outputType: T['outputType'];
7169
+ }>(this: T, column: C): C;
7170
+ }
7171
+ declare class DomainColumn<Schema extends ColumnSchemaConfig> extends CustomTypeColumn<Schema> {
7172
+ toCode(t: string, m?: boolean): Code;
7173
+ }
7174
+
7175
+ declare const getColumnTypes: <ColumnTypes, Shape extends QueryColumnsInit>(types: ColumnTypes, fn: (t: ColumnTypes) => Shape, nowSQL: string | undefined, language: string | undefined) => Shape;
7176
+ interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends TimestampHelpers {
7177
+ schema: SchemaConfig;
7178
+ enum: SchemaConfig['enum'];
7179
+ array: SchemaConfig['array'];
7180
+ name<T>(this: T, name: string): T;
7181
+ sql: SqlFn;
7182
+ smallint: SchemaConfig['smallint'];
7183
+ integer: SchemaConfig['integer'];
7184
+ bigint: SchemaConfig['bigint'];
7185
+ numeric: SchemaConfig['decimal'];
7186
+ decimal: SchemaConfig['decimal'];
7187
+ real: SchemaConfig['real'];
7188
+ doublePrecision: SchemaConfig['doublePrecision'];
7189
+ identity(options?: TableData.Identity): IdentityColumn<ReturnType<SchemaConfig['integer']>>;
7190
+ smallSerial: SchemaConfig['smallSerial'];
7191
+ serial: SchemaConfig['serial'];
7192
+ bigSerial: SchemaConfig['bigSerial'];
7193
+ money: SchemaConfig['money'];
7194
+ varchar: SchemaConfig['varchar'];
7195
+ char: SchemaConfig['char'];
7196
+ text: SchemaConfig['text'];
7197
+ string: SchemaConfig['string'];
7198
+ citext: SchemaConfig['citext'];
7199
+ bytea(): ByteaColumn<SchemaConfig>;
7200
+ date: SchemaConfig['date'];
7201
+ timestampNoTZ: SchemaConfig['timestampNoTZ'];
7202
+ timestamp: SchemaConfig['timestamp'];
7203
+ time(precision?: number): TimeColumn<SchemaConfig>;
7204
+ interval(fields?: string, precision?: number): IntervalColumn<SchemaConfig>;
7205
+ boolean(): BooleanColumn<SchemaConfig>;
7206
+ point(): PointColumn<SchemaConfig>;
7207
+ line(): LineColumn<SchemaConfig>;
7208
+ lseg(): LsegColumn<SchemaConfig>;
7209
+ box(): BoxColumn<SchemaConfig>;
7210
+ path(): PathColumn<SchemaConfig>;
7211
+ polygon(): PolygonColumn<SchemaConfig>;
7212
+ circle(): CircleColumn<SchemaConfig>;
7213
+ cidr(): CidrColumn<SchemaConfig>;
7214
+ inet(): InetColumn<SchemaConfig>;
7215
+ macaddr(): MacAddrColumn<SchemaConfig>;
7216
+ macaddr8(): MacAddr8Column<SchemaConfig>;
7217
+ bit(length: number): BitColumn<SchemaConfig>;
7218
+ bitVarying(length?: number): BitVaryingColumn<SchemaConfig>;
7219
+ tsvector(): TsVectorColumn<SchemaConfig>;
7220
+ tsquery(): TsQueryColumn<SchemaConfig>;
7221
+ uuid(): UUIDColumn<SchemaConfig>;
7222
+ xml(): XMLColumn<SchemaConfig>;
7223
+ json: SchemaConfig['json'];
7224
+ jsonText(): JSONTextColumn<SchemaConfig>;
7225
+ type(dataType: string): CustomTypeColumn<SchemaConfig>;
7226
+ domain(dataType: string): DomainColumn<SchemaConfig>;
7227
+ }
7228
+ declare const makeColumnTypes: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>>(schema: SchemaConfig) => DefaultColumnTypes<SchemaConfig>;
7229
+
7079
7230
  declare const simplifyColumnDefault: (value?: string) => RawSQL<orchid_core.QueryColumn<unknown, orchid_core.CoreBaseOperators>, DefaultColumnTypes<orchid_core.ColumnSchemaConfig<ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>>> | undefined;
7080
7231
  declare const instantiateColumn: (typeFn: () => ColumnTypeBase, params: ColumnFromDbParams) => ColumnTypeBase;
7081
- declare const getConstraintKind: (it: TableData.Constraint) => 'constraint' | 'foreignKey' | 'check';
7082
7232
 
7083
7233
  interface ColumnsShape {
7084
7234
  [K: string]: ColumnType;
@@ -7135,20 +7285,19 @@ declare class UnknownColumn<Schema extends ColumnSchemaConfig> extends VirtualCo
7135
7285
  }
7136
7286
 
7137
7287
  declare const isDefaultTimeStamp: (item: ColumnTypeBase) => boolean;
7138
- declare const columnsShapeToCode: (shape: ColumnsShapeBase, tableData: TableData, t: string, m?: boolean) => Code[];
7139
- declare const primaryKeyToCode: (primaryKey: TableData.PrimaryKey, t: string) => string;
7288
+ declare const columnsShapeToCode: (shape: ColumnsShapeBase, t: string) => Codes;
7289
+ declare const pushTableDataCode: (code: Codes, ast: TableData) => Codes;
7140
7290
  declare const primaryKeyInnerToCode: (primaryKey: TableData.PrimaryKey, t: string) => string;
7141
- declare const indexToCode: (index: TableData.Index, t: string) => Code[];
7142
- declare const indexInnerToCode: (index: TableData.Index, t: string) => Code[];
7143
- declare const constraintToCode: (item: TableData.Constraint, t: string, m?: boolean) => Code[];
7144
- declare const constraintInnerToCode: (item: TableData.Constraint, t: string, m?: boolean) => Code[];
7145
- declare const constraintPropsToCode: (t: string, item: TableData.Constraint, m?: boolean) => Code[];
7146
- declare const referencesArgsToCode: ({ columns, fnOrTable, foreignColumns, options, }: Exclude<TableData.Constraint['references'], undefined>, name?: string | false, m?: boolean) => Code[];
7147
- declare const columnForeignKeysToCode: (foreignKeys: ForeignKey<string, string[]>[], migration: boolean | undefined) => Code[];
7148
- declare const foreignKeyArgumentToCode: (foreignKey: ForeignKey<string, string[]>, migration: boolean | undefined) => Code[];
7149
- declare const columnIndexesToCode: (indexes: Exclude<ColumnData['indexes'], undefined>) => Code[];
7150
- declare const columnCheckToCode: (t: string, { sql, options }: ColumnDataCheckBase) => string;
7151
- declare const identityToCode: (identity: TableData.Identity, dataType?: string) => Code[];
7291
+ declare const indexToCode: (index: TableData.Index, t: string, prefix?: string) => Codes;
7292
+ declare const indexInnerToCode: (index: TableData.Index, t: string) => Codes;
7293
+ declare const constraintToCode: (item: TableData.Constraint, t: string, m?: boolean, prefix?: string) => Codes;
7294
+ declare const constraintInnerToCode: (item: TableData.Constraint, t: string, m?: boolean) => Codes;
7295
+ declare const referencesArgsToCode: ({ columns, fnOrTable, foreignColumns, options, }: Exclude<TableData.Constraint['references'], undefined>, name?: string | false, m?: boolean) => Codes;
7296
+ declare const columnForeignKeysToCode: (foreignKeys: TableData.ColumnReferences[], migration: boolean | undefined) => Codes;
7297
+ declare const foreignKeyArgumentToCode: ({ fnOrTable, foreignColumns, options, }: TableData.ColumnReferences, migration: boolean | undefined) => Codes;
7298
+ declare const columnIndexesToCode: (indexes: Exclude<ColumnData['indexes'], undefined>) => Codes;
7299
+ declare const columnCheckToCode: (t: string, { sql, name }: ColumnDataCheckBase) => string;
7300
+ declare const identityToCode: (identity: TableData.Identity, dataType?: string) => Codes;
7152
7301
  declare const columnCode: (type: ColumnType, t: string, code: Code, migration: boolean | undefined, data?: ColumnData, skip?: {
7153
7302
  encodeFn: unknown;
7154
7303
  }) => Code;
@@ -7208,6 +7357,7 @@ declare const saveSearchAlias: (q: QueryBase, as: string, key: 'joinedShapes' |
7208
7357
  * @param methods - methods to add
7209
7358
  */
7210
7359
  declare const extendQuery: <T extends PickQueryQAndBaseQuery, Methods extends RecordUnknown>(q: T, methods: Methods) => T & Methods;
7360
+ declare const getPrimaryKeys: (q: Query) => string[];
7211
7361
 
7212
7362
  type Arg = {
7213
7363
  $queryBuilder: Query;
@@ -7257,13 +7407,14 @@ declare function addComputedColumns<T extends PickQueryTableMetaShape, Computed
7257
7407
  * Sets query kind to 'columnInfo', returns a single value (may return undefined),
7258
7408
  * the value is a {@link GetColumnInfo} object or a Record with keys for column names and ColumnInfo objects as values.
7259
7409
  **/
7260
- type SetQueryReturnsColumnInfo<T extends PickQueryMetaShape, Column extends keyof T['shape'] | undefined, Result = Column extends keyof T['shape'] ? GetColumnInfo : Record<keyof T['shape'], GetColumnInfo>> = Omit<SetQueryKind<T, 'columnInfo'>, 'result' | 'returnType' | 'then' | 'catch'> & {
7410
+ type SetQueryReturnsColumnInfo<T extends PickQueryMetaShape, Column extends keyof T['shape'] | undefined, Result = Column extends keyof T['shape'] ? GetColumnInfo : {
7411
+ [K in keyof T['shape']]: GetColumnInfo;
7412
+ }> = Omit<SetQueryKind<T, 'columnInfo'>, 'result' | 'returnType' | 'then'> & {
7261
7413
  result: {
7262
7414
  value: QueryColumn<Result>;
7263
7415
  };
7264
7416
  returnType: 'value';
7265
7417
  then: QueryThen<Result>;
7266
- catch: QueryCatch<Result>;
7267
7418
  };
7268
7419
  type GetColumnInfo = {
7269
7420
  defaultValue: unknown;
@@ -7347,4 +7498,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
7347
7498
  */
7348
7499
  declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
7349
7500
 
7350
- export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AddQueryWith, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, CloneSelfKeys, ColumnData, ColumnExpression, ColumnFromDbParams, ColumnInfoQueryData, ColumnOperators, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumnsBase, CopyOptions, CopyQueryData, Create, CreateColumn, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CreateRelationsData, CreateRelationsDataOmittingFKeys, CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbDomainArg, DbDomainArgRecord, DbExtension, DbOptions, DbResult, DbSharedOptions, DbTableConstructor, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, Delete, DeleteArgs, DeleteMethodsNames, DeleteQueryData, DeleteResult, DomainColumn, DoublePrecisionColumn, DropMode, DynamicRawSQL, EnumColumn, ExpressionOutput, FnExpression, FnExpressionArgs, FnExpressionArgsPairs, FnExpressionArgsValue, For, ForeignKey, ForeignKeyAction, ForeignKeyMatch, ForeignKeyOptions, From, FromArg, FromArgOptions, FromQuerySelf, FromResult, GetArg, GetColumnInfo, GetQueryResult, GetResult, GetResultOptional, GetStringArg, GroupArg, Having, HavingItem, HookAction, HookSelect, IdentityColumn, IndexColumnOptions, IndexColumnOptionsForColumn, IndexOptions, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonItem, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MapTableScopesOption, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumnData, OnConflictItem, OnConflictMergeUpdate, OnConflictQueryBuilder, OnMethods, Operator, Operators, OperatorsAny, OperatorsArray, OperatorsBoolean, OperatorsDate, OperatorsJson, OperatorsNumber, OperatorsText, OperatorsTime, OrCreateArg, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgSelf, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PickColumnData, PickQueryBaseQuery, PickQueryDataShapeAndJoinedShapes, PickQueryInternal, PickQueryMetaRelations, PickQueryMetaResultRelations, PickQueryMetaResultRelationsWindows, PickQueryMetaResultRelationsWindowsColumnTypes, PickQueryMetaResultRelationsWithDataReturnType, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryMetaResultReturnTypeWithDataWindows, PickQueryMetaResultReturnTypeWithDataWindowsTable, PickQueryMetaShapeRelationsWithData, PickQueryMetaTable, PickQueryMetaTableShape, PickQueryMetaTableShapeReturnTypeWithData, PickQueryMetaWithData, PickQueryQ, PickQueryQAndBaseQuery, PickQueryQAndInternal, PickQueryRelations, PickQueryRelationsWithData, PickQueryShapeResultSinglePrimaryKey, PickQueryShapeSinglePrimaryKey, PickQuerySinglePrimaryKey, PickQueryWindows, PickQueryWithData, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBaseThen, QueryBeforeHook, QueryData, QueryDataJoinTo, QueryDefaultReturnData, QueryError, QueryErrorName, QueryGet, QueryGetSelf, QueryHelperResult, QueryHookSelect, QueryHooks, QueryInternal, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMetaHasSelect, QueryMetaHasWhere, QueryMethods, QueryResult, QueryReturnsAll, QueryScopeData, QueryScopes, QuerySourceItem, QueryTransform, QueryTransformFn, QueryUpsertOrCreate, QueryWithComputed, QueryWithTable, RawSQL, RawSqlMethods, RealColumn, RelationConfigBase, RelationConfigDataForCreate, RelationJoinQuery, RelationQuery, RelationQueryBase, RelationsBase, RelationsChain, SearchArg, SearchMethods, SearchWeight, Select, SelectArg, SelectAs, SelectItem, SelectQueryData, SelectSubQueryResult, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SerialColumn, SerialColumnData, SetQueryKind, SetQueryReturnsAll, SetQueryReturnsAllKind, SetQueryReturnsColumnInfo, SetQueryReturnsColumnKind, SetQueryReturnsColumnOptional, SetQueryReturnsColumnOrThrow, SetQueryReturnsOne, SetQueryReturnsOneKind, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsPluckColumn, SetQueryReturnsPluckColumnKind, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValueOptional, SetQueryReturnsValueOrThrow, SetQueryReturnsVoid, SetQueryReturnsVoidKind, SetQueryTableAlias, SetQueryWith, SimpleJoinItem, SimpleJoinItemNonSubQueryArgs, SingleColumnIndexOptions, SingleColumnIndexOptionsForColumn, SmallIntColumn, SmallSerialColumn, SortDir, StringColumn$1 as StringColumn, TableData, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, ToSQLCtx, ToSQLOptions, ToSQLQuery, Transaction, TransactionAdapter, TransactionOptions, TransformMethods, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionKind, UnknownColumn, Update, UpdateArg, UpdateCtx, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdateSelf, UpdatedAtDataInjector, UpsertArg, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereNotArgs, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, With, WithDataBase, WithDataItem, WithDataItems, WithItem, WithOptions, WrapQueryArg, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, constraintInnerToCode, constraintPropsToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getConstraintKind, getQueryAs, getShapeFromSelect, getTableData, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeExpression, makeFnExpression, makeRegexToFindInSql, makeSQL, newTableData, parseRecord, parseResult, primaryKeyInnerToCode, primaryKeyToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resetTableData, resolveSubQueryCallback, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlQueryArgsToExpression, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
7501
+ export { Adapter, AdapterConfig, AdapterOptions, AddQueryDefaults, AddQuerySelect, AddQueryWith, AfterHook, AggregateMethods, AggregateOptions, AliasOrTable, ArrayColumn, ArrayColumnValue, ArrayData, AsMethods, AsQueryArg, BaseOperators, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BooleanQueryColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ClearStatement, CloneSelfKeys, ColumnData, ColumnExpression, ColumnFromDbParams, ColumnInfoQueryData, ColumnOperators, ColumnRefExpression, ColumnType, ColumnsByType, ColumnsShape, ColumnsShapeToNullableObject, ColumnsShapeToObject, ColumnsShapeToObjectArray, ColumnsShapeToPluck, CommonQueryData, ComputedColumnsBase, CopyOptions, CopyQueryData, Create, CreateColumn, CreateCtx, CreateData, CreateKind, CreateMethodsNames, CreateRelationsData, CreateRelationsDataOmittingFKeys, CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, DbDomainArg, DbDomainArgRecord, DbExtension, DbOptions, DbResult, DbSharedOptions, DbTableConstructor, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, Delete, DeleteArgs, DeleteMethodsNames, DeleteQueryData, DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionOutput, FnExpression, FnExpressionArgs, FnExpressionArgsPairs, FnExpressionArgsValue, For, From, FromArg, FromArgOptions, FromQuerySelf, FromResult, GetArg, GetColumnInfo, GetQueryResult, GetResult, GetResultOptional, GetStringArg, GroupArg, Having, HavingItem, HookAction, HookSelect, IdentityColumn, InetColumn, InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, IsolationLevel, JSONColumn, JSONTextColumn, Join, JoinArgs, JoinCallback, JoinFirstArg, JoinItem, JoinItemArgs, JoinLateralCallback, JoinLateralItem, JoinLateralResult, JoinOverrides, JoinQueryBuilder, JoinQueryMethod, JoinResult, JoinedParsers, JoinedShapes, JsonItem, JsonMethods, JsonModifiers, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MapTableScopesOption, MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NoPrimaryKeyOption, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, NumberColumnData, OnConflictMerge, OnConflictQueryBuilder, OnConflictSet, OnConflictTarget, OnMethods, Operator, Operators, OperatorsAny, OperatorsArray, OperatorsBoolean, OperatorsDate, OperatorsJson, OperatorsNumber, OperatorsText, OperatorsTime, OrCreateArg, OrchidOrmError, OrchidOrmInternalError, OrderArg, OrderArgSelf, OrderArgs, OrderItem, OrderTsQueryConfig, Over, PathColumn, PickColumnData, PickQueryBaseQuery, PickQueryDataShapeAndJoinedShapes, PickQueryInternal, PickQueryMetaRelations, PickQueryMetaResultRelations, PickQueryMetaResultRelationsWindows, PickQueryMetaResultRelationsWindowsColumnTypes, PickQueryMetaResultRelationsWithDataReturnType, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryMetaResultReturnTypeWithDataWindows, PickQueryMetaResultReturnTypeWithDataWindowsTable, PickQueryMetaShapeRelationsWithData, PickQueryMetaTable, PickQueryMetaTableShape, PickQueryMetaTableShapeReturnTypeWithData, PickQueryMetaWithData, PickQueryQ, PickQueryQAndBaseQuery, PickQueryQAndInternal, PickQueryRelations, PickQueryRelationsWithData, PickQueryShapeResultSinglePrimaryKey, PickQueryShapeSinglePrimaryKey, PickQuerySinglePrimaryKey, PickQueryWindows, PickQueryWithData, PointColumn, PolygonColumn, Query, QueryAfterHook, QueryArraysResult, QueryBase, QueryBaseThen, QueryBeforeHook, QueryData, QueryDataJoinTo, QueryDefaultReturnData, QueryError, QueryErrorName, QueryGet, QueryGetSelf, QueryHelperResult, QueryHookSelect, QueryHooks, QueryInternal, QueryLog, QueryLogObject, QueryLogOptions, QueryLogger, QueryMetaHasSelect, QueryMetaHasWhere, QueryMethods, QueryResult, QueryReturnsAll, QueryScopeData, QueryScopes, QuerySourceItem, QueryTransform, QueryTransformFn, QueryUpsertOrCreate, QueryWithComputed, QueryWithTable, RawSQL, RawSqlMethods, RealColumn, RecordOfColumnsShapeBase, RelationConfigBase, RelationConfigDataForCreate, RelationJoinQuery, RelationQuery, RelationQueryBase, RelationsBase, SearchArg, SearchMethods, SearchWeight, SearchWeightRecord, Select, SelectArg, SelectAs, SelectItem, SelectQueryData, SelectSubQueryResult, SelectableFromShape, SelectableOfType, SelectableOrExpression, SelectableOrExpressionOfType, SerialColumn, SerialColumnData, SetQueryKind, SetQueryReturnsAll, SetQueryReturnsAllKind, SetQueryReturnsColumnInfo, SetQueryReturnsColumnKind, SetQueryReturnsColumnOptional, SetQueryReturnsColumnOrThrow, SetQueryReturnsOne, SetQueryReturnsOneKind, SetQueryReturnsOneOptional, SetQueryReturnsPluck, SetQueryReturnsPluckColumn, SetQueryReturnsPluckColumnKind, SetQueryReturnsRowCount, SetQueryReturnsRows, SetQueryReturnsValueOptional, SetQueryReturnsValueOrThrow, SetQueryReturnsVoid, SetQueryReturnsVoidKind, SetQueryTableAlias, SetQueryWith, ShapeColumnPrimaryKeys, ShapeUniqueColumns, SimpleJoinItem, SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, SortDir, SqlFn, StringColumn$1 as StringColumn, TableData, TableDataFn, TableDataInput, TableDataItem, TableDataItemsUniqueColumnTuples, TableDataItemsUniqueColumns, TableDataItemsUniqueConstraints, TableDataMethods, TextBaseColumn, TextColumn, TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, ToSQLCtx, ToSQLOptions, ToSQLQuery, Transaction, TransactionAdapter, TransactionOptions, TransformMethods, TruncateQueryData, TsQueryColumn, TsVectorColumn, TypeParsers, UUIDColumn, UnhandledTypeError, Union, UnionArg, UnionItem, UnionKind, UniqueConstraints, UniqueQueryTypeOrExpression, UniqueTableDataItem, UnknownColumn, Update, UpdateArg, UpdateCtx, UpdateCtxCollect, UpdateData, UpdateQueryData, UpdateQueryDataItem, UpdateQueryDataObject, UpdateSelf, UpdatedAtDataInjector, UpsertArg, UpsertResult, UpsertThis, VarCharColumn, VirtualColumn, Where, WhereArg, WhereArgs, WhereInArg, WhereInColumn, WhereInItem, WhereInValues, WhereItem, WhereJsonPathEqualsItem, WhereNotArgs, WhereOnItem, WhereOnJoinItem, WhereQueryBuilder, WhereResult, WhereSearchItem, WhereSearchResult, WindowArg, WindowArgDeclaration, WindowDeclaration, WindowItem, With, WithDataBase, WithDataItem, WithDataItems, WithItem, WithOptions, WrapQueryArg, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeExpression, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseResult, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };