pqb 0.27.7 → 0.28.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,24 +266,33 @@ 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;
293
+ type OnConflictItem = string | string[] | Expression | {
294
+ constraint: string;
295
+ };
284
296
  type OnConflictMergeUpdate = string | string[] | RecordUnknown | Expression;
285
297
 
286
298
  interface Operator<Value, Column extends PickOutputTypeAndOperators = PickOutputTypeAndOperators> {
@@ -353,13 +365,20 @@ declare const Operators: {
353
365
  array: OperatorsArray;
354
366
  };
355
367
 
356
- type JoinedShapes = Record<string, ColumnsShapeBase>;
357
- type JoinedParsers = Record<string, ColumnsParsers>;
368
+ interface RecordOfColumnsShapeBase {
369
+ [K: string]: ColumnsShapeBase;
370
+ }
371
+ type JoinedShapes = RecordOfColumnsShapeBase;
372
+ interface JoinedParsers {
373
+ [K: string]: ColumnsParsers;
374
+ }
358
375
  type JoinOverrides = RecordString;
359
376
  type QueryBeforeHook = (query: Query) => void | Promise<void>;
360
377
  type QueryAfterHook<Data = unknown> = (data: Data, query: Query) => void | Promise<void>;
361
378
  type QueryHookSelect = string[];
362
- type QueryScopes = Record<string, QueryScopeData>;
379
+ interface QueryScopes {
380
+ [K: string]: QueryScopeData;
381
+ }
363
382
  type QueryScopeData = {
364
383
  and?: WhereItem[];
365
384
  or?: WhereItem[][];
@@ -375,7 +394,7 @@ type CommonQueryData = {
375
394
  wrapInTransaction?: boolean;
376
395
  throwOnNotFound?: boolean;
377
396
  with?: WithItem[];
378
- withShapes?: Record<string, ColumnsShapeBase>;
397
+ withShapes?: RecordOfColumnsShapeBase;
379
398
  joinTo?: QueryDataJoinTo;
380
399
  joinedShapes?: JoinedShapes;
381
400
  joinedParsers?: JoinedParsers;
@@ -387,7 +406,9 @@ type CommonQueryData = {
387
406
  expr?: Expression;
388
407
  as?: string;
389
408
  from?: string | Query | Expression;
390
- sources?: Record<string, QuerySourceItem>;
409
+ sources?: {
410
+ [K: string]: QuerySourceItem;
411
+ };
391
412
  and?: WhereItem[];
392
413
  or?: WhereItem[][];
393
414
  coalesceValue?: unknown | Expression;
@@ -415,7 +436,7 @@ type CommonQueryData = {
415
436
  transform?: ((input: unknown) => unknown)[];
416
437
  language?: string;
417
438
  isSubQuery?: true;
418
- relChain?: RelationsChain;
439
+ relChain?: (Query | RelationQuery)[];
419
440
  /**
420
441
  * Stores current operator functions available for the query.
421
442
  * Is needed to remove these operators from query object when changing the query type, see {@link setQueryOperators}.
@@ -425,7 +446,9 @@ type CommonQueryData = {
425
446
  * Used by {@link setQueryOperators} to store the original `baseQuery` before extending it with operators.
426
447
  */
427
448
  originalQuery?: Query;
428
- scopes: Record<string, QueryScopeData>;
449
+ scopes: {
450
+ [K: string]: QueryScopeData;
451
+ };
429
452
  all?: true;
430
453
  };
431
454
  type SelectQueryData = CommonQueryData & {
@@ -472,10 +495,12 @@ type InsertQueryData = CommonQueryData & {
472
495
  update?: OnConflictMergeUpdate;
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";
@@ -2374,295 +2680,56 @@ declare class TsVectorColumn<Schema extends ColumnSchemaConfig> extends ColumnTy
2374
2680
  * await db.createTable('post', (t) => ({
2375
2681
  * id: t.id(),
2376
2682
  * title: t.text(),
2377
- * body: t.text(),
2378
- * // join title and body into a single ts_vector
2379
- * generatedTsVector: t.tsvector().generated(['title', 'body']).searchIndex(),
2380
- * // with language:
2381
- * spanishTsVector: t
2382
- * .tsvector()
2383
- * .generated('spanish', ['title', 'body'])
2384
- * .searchIndex(),
2385
- * }));
2386
- * });
2387
- * ```
2388
- *
2389
- * @param args
2390
- */
2391
- generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs | [language: string, columns: TsVectorGeneratedColumns] | [columns: TsVectorGeneratedColumns]): T;
2392
- }
2393
- declare class TsQueryColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
2394
- dataType: "tsquery";
2395
- operators: OperatorsText;
2396
- constructor(schema: Schema);
2397
- toCode(t: string, m?: boolean): Code;
2398
- }
2399
- declare class UUIDColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['uuid']>, OperatorsText> {
2400
- dataType: "uuid";
2401
- operators: OperatorsText;
2402
- 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> & {
2405
- data: {
2406
- default: RawSQLBase;
2407
- };
2408
- };
2409
- toCode(t: string, m?: boolean): Code;
2410
- }
2411
- declare class XMLColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
2412
- dataType: "xml";
2413
- operators: OperatorsText;
2414
- constructor(schema: Schema);
2415
- toCode(t: string, m?: boolean): Code;
2416
- }
2417
- declare class CitextColumn<Schema extends ColumnSchemaConfig> extends TextBaseColumn<Schema> {
2418
- dataType: "citext";
2419
- data: TextColumnData & {
2420
- minArg?: number;
2421
- maxArg?: number;
2422
- };
2423
- constructor(schema: Schema, min?: number, max?: number);
2424
- toCode(t: string, m?: boolean): Code;
2425
- }
2426
-
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;
2683
+ * body: t.text(),
2684
+ * // join title and body into a single ts_vector
2685
+ * generatedTsVector: t.tsvector().generated(['title', 'body']).searchIndex(),
2686
+ * // with language:
2687
+ * spanishTsVector: t
2688
+ * .tsvector()
2689
+ * .generated('spanish', ['title', 'body'])
2690
+ * .searchIndex(),
2691
+ * }));
2692
+ * });
2693
+ * ```
2694
+ *
2695
+ * @param args
2696
+ */
2697
+ generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs | [language: string, columns: TsVectorGeneratedColumns] | [columns: TsVectorGeneratedColumns]): T;
2639
2698
  }
2640
- declare class DoublePrecisionColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
2641
- dataType: "float8";
2699
+ declare class TsQueryColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
2700
+ dataType: "tsquery";
2701
+ operators: OperatorsText;
2642
2702
  constructor(schema: Schema);
2643
2703
  toCode(t: string, m?: boolean): Code;
2644
2704
  }
2645
- declare class SmallSerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2646
- dataType: "int2";
2647
- parseItem: typeof parseInt;
2648
- data: SerialColumnData;
2705
+ declare class UUIDColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['uuid']>, OperatorsText> {
2706
+ dataType: "uuid";
2707
+ operators: OperatorsText;
2649
2708
  constructor(schema: Schema);
2650
- toSQL(): string;
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> & {
2714
+ data: {
2715
+ default: RawSQLBase;
2716
+ };
2717
+ };
2651
2718
  toCode(t: string, m?: boolean): Code;
2652
2719
  }
2653
- declare class SerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
2654
- dataType: "int4";
2655
- parseItem: typeof parseInt;
2656
- data: SerialColumnData;
2720
+ declare class XMLColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
2721
+ dataType: "xml";
2722
+ operators: OperatorsText;
2657
2723
  constructor(schema: Schema);
2658
- toSQL(): string;
2659
2724
  toCode(t: string, m?: boolean): Code;
2660
2725
  }
2661
- declare class BigSerialColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
2662
- dataType: "int8";
2663
- data: SerialColumnData;
2664
- constructor(schema: Schema);
2665
- toSQL(): string;
2726
+ declare class CitextColumn<Schema extends ColumnSchemaConfig> extends TextBaseColumn<Schema> {
2727
+ dataType: "citext";
2728
+ data: TextColumnData & {
2729
+ minArg?: number;
2730
+ maxArg?: number;
2731
+ };
2732
+ constructor(schema: Schema, min?: number, max?: number);
2666
2733
  toCode(t: string, m?: boolean): Code;
2667
2734
  }
2668
2735
 
@@ -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 `.onConflictIgnore()`,
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).onConflictIgnore();
3692
3798
  *
3693
3799
  * await db.table.create({
3694
3800
  * // raw SQL
@@ -3878,34 +3984,48 @@ 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 `onConflictIgnore()` to suppress the error and continue without updating the record,
3999
+ * or `onConflict(['uniqueColumn']).merge()` to update the record with a new data.
3888
4000
  *
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()`.
4001
+ * `onConflict` only accepts column names that are defined in `primaryKey` or `unique` in the table definition.
4002
+ * To specify a constraint, its name also must be explicitly set in `primaryKey` or `unique` in the table code.
4003
+ *
4004
+ * 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
4005
+ * for updating the record.
4006
+ *
4007
+ * If your table has multiple potential reasons for unique constraint violation, such as username and email columns in a user table,
4008
+ * consider using [upsert](#upsert) instead.
3891
4009
  *
3892
4010
  * ```ts
3893
4011
  * // leave `onConflict` without argument to ignore or merge on any conflict
3894
- * db.table.create(data).onConflict().ignore();
4012
+ * db.table.create(data).onConflictIgnore();
3895
4013
  *
3896
4014
  * // single column:
3897
- * db.table.create(data).onConfict('email');
4015
+ * db.table.create(data).onConfict('email').merge();
3898
4016
  *
3899
4017
  * // array of columns:
3900
- * db.table.create(data).onConfict(['email', 'name']);
4018
+ * db.table.create(data).onConfict(['email', 'name']).merge();
3901
4019
  *
3902
- * // raw expression:
3903
- * db.table.create(data).onConfict(db.table.sql`(email) where condition`);
3904
- * ```
4020
+ * // constraint name
4021
+ * db.table.create(data).onConfict({ constraint: 'unique_index_name' }).merge();
3905
4022
  *
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.
4023
+ * // raw SQL expression:
4024
+ * db.table
4025
+ * .create(data)
4026
+ * .onConfict(db.table.sql`(email) where condition`)
4027
+ * .merge();
4028
+ * ```
3909
4029
  *
3910
4030
  * You can use the db.table.sql function in onConflict.
3911
4031
  * It can be useful to specify a condition when you have a partial index:
@@ -3922,26 +4042,15 @@ declare class Create {
3922
4042
  * .ignore();
3923
4043
  * ```
3924
4044
  *
3925
- * :::
3926
- *
3927
- * See the documentation on the .ignore() and .merge() methods for more details.
3928
- *
3929
4045
  * @param arg - optionally provide an array of columns
3930
4046
  */
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);
4047
+ onConflict<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg: Arg): OnConflictQueryBuilder<T, Arg>;
3937
4048
  /**
3938
- * Available only after `onConflict`.
4049
+ * Use `onConflictIgnore` to suppress unique constraint violation error when creating a record.
3939
4050
  *
3940
- * `ignore` modifies a create query, and causes it to be silently dropped without an error if a conflict occurs.
4051
+ * Adds `ON CONFLICT (columns) DO NOTHING` clause to the insert statement, columns are optional.
3941
4052
  *
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.
4053
+ * Can also accept a constraint name.
3945
4054
  *
3946
4055
  * ```ts
3947
4056
  * db.table
@@ -3949,53 +4058,55 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
3949
4058
  * email: 'ignore@example.com',
3950
4059
  * name: 'John Doe',
3951
4060
  * })
3952
- * .onConflict('email')
3953
- * .ignore();
4061
+ * // on any conflict:
4062
+ * .onConflictIgnore()
4063
+ * // or, for a specific column:
4064
+ * .onConflictIgnore('email')
4065
+ * // or, for a specific constraint:
4066
+ * .onConflictIgnore({ constraint: 'unique_index_name' });
3954
4067
  * ```
3955
4068
  *
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`.
4069
+ * When there is a conflict, nothing can be returned from the database, so `onConflictIgnore` adds `| undefined` part to the response type.
3960
4070
  *
3961
4071
  * ```ts
3962
4072
  * const maybeRecord: RecordType | undefined = await db.table
3963
4073
  * .create(data)
3964
- * .onConflict()
3965
- * .ignore();
4074
+ * .onConflictIgnore();
3966
4075
  *
3967
4076
  * const maybeId: number | undefined = await db.table
3968
4077
  * .get('id')
3969
4078
  * .create(data)
3970
- * .onConflict()
3971
- * .ignore();
4079
+ * .onConflictIgnore();
3972
4080
  * ```
3973
4081
  *
3974
- * When creating many records, only the created records will be returned. If no records were created, array will be empty:
4082
+ * When creating multiple records, only created records will be returned. If no records were created, array will be empty:
3975
4083
  *
3976
4084
  * ```ts
3977
4085
  * // array can be empty
3978
- * const arr = await db.table.createMany([data, data, data]).onConflict().ignore();
4086
+ * const arr = await db.table.createMany([data, data, data]).onConflictIgnore();
3979
4087
  * ```
3980
4088
  */
3981
- ignore(): IgnoreResult<T>;
4089
+ onConflictIgnore<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg?: Arg): IgnoreResult<T>;
4090
+ }
4091
+ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflictArg<T> | undefined> {
4092
+ private query;
4093
+ private onConflict;
4094
+ constructor(query: T, onConflict: Arg);
3982
4095
  /**
3983
- * Available only after `onConflict`.
3984
- *
3985
- * Modifies a create query, to turn it into an 'upsert' operation.
4096
+ * Available only after [onConflict](#onconflict).
3986
4097
  *
3987
4098
  * Adds an `ON CONFLICT (columns) DO UPDATE` clause to the insert statement.
3988
4099
  *
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.
3991
- *
3992
4100
  * ```ts
3993
4101
  * db.table
3994
4102
  * .create({
3995
4103
  * email: 'ignore@example.com',
3996
4104
  * name: 'John Doe',
3997
4105
  * })
4106
+ * // for a specific column:
3998
4107
  * .onConflict('email')
4108
+ * // or, for a specific constraint:
4109
+ * .onConflict({ constraint: 'unique_constraint_name' })
3999
4110
  * .merge();
4000
4111
  * ```
4001
4112
  *
@@ -4026,15 +4137,15 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
4026
4137
  * updatedAt: timestamp,
4027
4138
  * })
4028
4139
  * .onConflict('email')
4029
- * // string argument for a single column:
4140
+ * // update only a single column
4030
4141
  * .merge('email')
4031
- * // array of strings for multiple columns:
4142
+ * // or, update multiple columns
4032
4143
  * .merge(['email', 'name', 'updatedAt']);
4033
4144
  * ```
4034
4145
  *
4035
- * It is also possible to specify data to update separately from the data to create.
4146
+ * It's possible to specify data to update separately from the data to create.
4036
4147
  * 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:
4148
+ * For example, changing a value if the row already exists:
4038
4149
  *
4039
4150
  * ```ts
4040
4151
  * const timestamp = Date.now();
@@ -4052,7 +4163,7 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
4052
4163
  * });
4053
4164
  * ```
4054
4165
  *
4055
- * It is also possible to add a WHERE clause to conditionally update only the matching rows:
4166
+ * You can use `where` to update only the matching rows:
4056
4167
  *
4057
4168
  * ```ts
4058
4169
  * const timestamp = Date.now();
@@ -4072,7 +4183,7 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
4072
4183
  * .where({ updatedAt: { lt: timestamp } });
4073
4184
  * ```
4074
4185
  *
4075
- * `merge` also accepts raw expression:
4186
+ * `merge` can take a raw SQL expression:
4076
4187
  *
4077
4188
  * ```ts
4078
4189
  * db.table
@@ -4170,7 +4281,7 @@ type FromResult<T extends FromQuerySelf, Arg extends FromArg<T>> = Arg extends s
4170
4281
  column: Arg['result'][K];
4171
4282
  } : never;
4172
4283
  } : 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];
4284
+ } : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends 'then' ? QueryThen<GetQueryResult<T, Arg['result']>> : T[K];
4174
4285
  } : T;
4175
4286
  declare function queryFrom<T extends FromQuerySelf, Arg extends FromArg<T>>(self: T, arg: Arg, options?: FromArgOptions): FromResult<T, Arg>;
4176
4287
  declare function queryFromSql<T extends FromQuerySelf>(self: T, args: SQLQueryArgs): T;
@@ -4644,7 +4755,7 @@ declare class QueryLog {
4644
4755
  type MergeQuery<T extends PickQueryMetaResultReturnTypeWithDataWindows, Q extends PickQueryMetaResultReturnTypeWithDataWindows> = {
4645
4756
  [K in keyof T]: K extends 'meta' ? {
4646
4757
  [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];
4758
+ } : 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
4759
  };
4649
4760
  type MergeQueryResult<T extends PickQueryMetaResult, Q extends PickQueryMetaResult> = T['meta']['hasSelect'] extends true ? Q['meta']['hasSelect'] extends true ? {
4650
4761
  [K in keyof T['result'] | keyof Q['result']]: K extends keyof Q['result'] ? Q['result'][K] : T['result'][K];
@@ -4653,7 +4764,9 @@ declare class MergeQueryMethods {
4653
4764
  merge<T extends Query, Q extends Query>(this: T, q: Q): MergeQuery<T, Q>;
4654
4765
  }
4655
4766
 
4656
- declare const queryMethodByReturnType: Record<QueryReturnType, 'query' | 'arrays'>;
4767
+ declare const queryMethodByReturnType: {
4768
+ [K in QueryReturnType]: 'query' | 'arrays';
4769
+ };
4657
4770
  type Resolve = (result: any) => any;
4658
4771
  type Reject = (error: any) => any;
4659
4772
  declare class Then {
@@ -4689,10 +4802,6 @@ type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = {
4689
4802
  [K in Columns[number] | keyof T['shape'] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
4690
4803
  } : {
4691
4804
  [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
4805
  }) & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : T[K];
4697
4806
  } & QueryMetaHasSelect;
4698
4807
  type SelectResultObj<T extends SelectSelf, Obj> = {
@@ -4702,8 +4811,6 @@ type SelectResultObj<T extends SelectSelf, Obj> = {
4702
4811
  [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
4812
  } : K extends 'then' ? QueryThen<GetQueryResult<T, {
4704
4813
  [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
4814
  }>> : T[K];
4708
4815
  } & QueryMetaHasSelect;
4709
4816
  type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj> = {
@@ -4714,8 +4821,6 @@ type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey
4714
4821
  [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
4822
  } & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown) : K extends 'then' ? QueryThen<GetQueryResult<T, {
4716
4823
  [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
4824
  } & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : T[K];
4720
4825
  } & QueryMetaHasSelect;
4721
4826
  type SelectAsSelectable<Arg> = {
@@ -4898,7 +5003,9 @@ declare class With {
4898
5003
 
4899
5004
  type UnionArg<T extends PickQueryResult> = {
4900
5005
  result: {
4901
- [K in keyof T['result']]: Pick<T['result'][K], 'dataType'>;
5006
+ [K in keyof T['result']]: {
5007
+ dataType: T['result'][K]['dataType'];
5008
+ };
4902
5009
  };
4903
5010
  } | Expression;
4904
5011
  declare class Union {
@@ -4957,7 +5064,9 @@ declare class Union {
4957
5064
  exceptAll<T extends PickQueryResult>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
4958
5065
  }
4959
5066
 
4960
- type UpdateSelf = Pick<Query, 'meta' | 'inputType' | 'relations' | 'shape' | 'result' | 'returnType' | keyof JsonModifiers>;
5067
+ type UpdateSelf = {
5068
+ [K in 'meta' | 'inputType' | 'relations' | 'shape' | 'result' | 'returnType' | keyof JsonModifiers]: Query[K];
5069
+ };
4961
5070
  type UpdateData<T extends UpdateSelf> = {
4962
5071
  [K in keyof T['inputType']]?: UpdateColumn<T, K>;
4963
5072
  } & {
@@ -4983,10 +5092,14 @@ type UpdateResult<T extends UpdateSelf> = T['meta']['hasSelect'] extends true ?
4983
5092
  type ChangeCountArg<T extends PickQueryShape> = keyof T['shape'] | {
4984
5093
  [K in keyof T['shape']]?: number;
4985
5094
  };
4986
- type UpdateCtx = {
5095
+ interface UpdateCtx {
4987
5096
  queries?: ((queryResult: QueryResult) => Promise<void>)[];
4988
- updateData?: RecordUnknown;
4989
- };
5097
+ collect?: UpdateCtxCollect;
5098
+ }
5099
+ interface UpdateCtxCollect {
5100
+ keys: string[];
5101
+ data: RecordUnknown;
5102
+ }
4990
5103
  declare const _queryChangeCounter: <T extends UpdateSelf>(self: T, op: string, data: ChangeCountArg<T>) => never;
4991
5104
  declare const _queryUpdate: <T extends UpdateSelf>(query: T, arg: UpdateArg<T>) => UpdateResult<T>;
4992
5105
  declare const _queryUpdateRaw: <T extends UpdateSelf>(q: T, sql: Expression) => UpdateResult<T>;
@@ -5741,26 +5854,6 @@ declare class QueryUpsertOrCreate {
5741
5854
  orCreate<T extends UpsertThis>(this: T, data: OrCreateArg<T>): UpsertResult<T>;
5742
5855
  }
5743
5856
 
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
5857
  declare abstract class RawSqlMethods<ColumnTypes> {
5765
5858
  /**
5766
5859
  * 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 +6012,11 @@ declare abstract class RawSqlMethods<ColumnTypes> {
5919
6012
  }, ...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>, ColumnTypes>;
5920
6013
  }
5921
6014
 
5922
- type QueryTransformFn<T extends Query> = (input: T['catch'] extends QueryCatch<infer Data> ? Data : never) => unknown;
6015
+ type QueryTransformFn<T extends Query> = (input: T['then'] extends QueryThen<infer Data> ? Data : never) => unknown;
5923
6016
  type QueryTransform<T extends QueryBase, Data> = {
5924
6017
  [K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
5925
6018
  value: QueryColumn<Data>;
5926
- } : K extends 'then' ? QueryThen<Data> : K extends 'catch' ? QueryCatch<Data> : T[K];
6019
+ } : K extends 'then' ? QueryThen<Data> : T[K];
5927
6020
  };
5928
6021
  declare class TransformMethods {
5929
6022
  /**
@@ -5988,7 +6081,9 @@ interface WindowArgDeclaration<T extends OrderArgSelf = OrderArgSelf> {
5988
6081
  order?: OrderArg<T>;
5989
6082
  }
5990
6083
  type WindowResult<T, W extends RecordUnknown> = T & {
5991
- windows: Record<keyof W, true>;
6084
+ windows: {
6085
+ [K in keyof W]: true;
6086
+ };
5992
6087
  };
5993
6088
  type OrderArgSelf = PickQueryMetaResult;
5994
6089
  type OrderArg<T extends OrderArgSelf> = OrderArgKey<T> | OrderArgTsQuery<T> | {
@@ -6002,7 +6097,7 @@ type OrderArgs<T extends OrderArgSelf> = OrderArg<T>[];
6002
6097
  type GroupArg<T extends PickQueryResult> = {
6003
6098
  [K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' ? never : K;
6004
6099
  }[keyof T['result']] | Expression;
6005
- type FindArg<T extends PickQueryShapeSinglePrimaryKey> = T['shape'][T['singlePrimaryKey']]['queryType'] | Expression;
6100
+ type FindArg<T extends PickQueryShapeSinglePrimaryKey> = T['internal']['singlePrimaryKey'] | Expression;
6006
6101
  type QueryHelper<T extends PickQueryMetaShape, Args extends unknown[], Result> = {
6007
6102
  <Q extends {
6008
6103
  returnType: QueryReturnType;
@@ -6142,20 +6237,11 @@ declare class QueryMethods<ColumnTypes> {
6142
6237
  */
6143
6238
  distinct<T extends PickQueryMeta>(this: T, ...columns: SelectableOrExpression<T>[]): T;
6144
6239
  /**
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
- * ```
6240
+ * Finds a single record by the primary key (id), throws [NotFoundError](/guide/error-handling.html) if not found.
6241
+ * Not available if the table has no or multiple primary keys.
6153
6242
  *
6154
6243
  * ```ts
6155
- * await db.user.find`
6156
- * age = ${age} AND
6157
- * name = ${name}
6158
- * `;
6244
+ * const result: TableType = await db.table.find(1);
6159
6245
  * ```
6160
6246
  *
6161
6247
  * @param value - primary key value to find by
@@ -6173,10 +6259,10 @@ declare class QueryMethods<ColumnTypes> {
6173
6259
  *
6174
6260
  * @param args - SQL expression
6175
6261
  */
6176
- findBySql<T extends PickQueryShapeResultSinglePrimaryKey>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOne<WhereResult<T>>;
6262
+ findBySql<T extends PickQueryResult>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOne<WhereResult<T>>;
6177
6263
  /**
6178
- * Find a single record by the primary key (id), adds `LIMIT 1`.
6179
- * Returns `undefined` when not found.
6264
+ * Finds a single record by the primary key (id), returns `undefined` when not found.
6265
+ * Not available if the table has no or multiple primary keys.
6180
6266
  *
6181
6267
  * ```ts
6182
6268
  * const result: TableType | undefined = await db.table.find(123);
@@ -6198,33 +6284,35 @@ declare class QueryMethods<ColumnTypes> {
6198
6284
  *
6199
6285
  * @param args - SQL expression
6200
6286
  */
6201
- findBySqlOptional<T extends PickQueryShapeResultSinglePrimaryKey>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOneOptional<WhereResult<T>>;
6287
+ findBySqlOptional<T extends PickQueryResult>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOneOptional<WhereResult<T>>;
6202
6288
  /**
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.
6289
+ * Finds a single unique record, throws [NotFoundError](/guide/error-handling.html) if not found.
6290
+ * It accepts values of primary keys or unique indexes defined on the table.
6291
+ * `findBy`'s argument type is a union of all possible sets of unique conditions.
6292
+ *
6293
+ * You can use `where(...).take()` for non-unique conditions.
6205
6294
  *
6206
6295
  * ```ts
6207
- * const result: TableType = await db.table.findBy({ key: 'value' });
6208
- * // is equivalent to:
6209
- * db.table.where({ key: 'value' }).take()
6296
+ * await db.table.findBy({ key: 'value' });
6210
6297
  * ```
6211
6298
  *
6212
- * @param args - `where` conditions
6299
+ * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
6213
6300
  */
6214
- findBy<T extends PickQueryMetaResultRelations>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOne<WhereResult<T>>;
6301
+ findBy<T extends PickQueryResultUniqueColumns>(this: T, uniqueColumnValues: T['internal']['uniqueColumns']): SetQueryReturnsOne<WhereResult<T>>;
6215
6302
  /**
6216
- * The same as `where(conditions).takeOptional()`, it will filter records and add a `LIMIT 1`.
6217
- * Returns `undefined` when not found.
6303
+ * Finds a single unique record, returns `undefined` if not found.
6304
+ * It accepts values of primary keys or unique indexes defined on the table.
6305
+ * `findBy`'s argument type is a union of all possible sets of unique conditions.
6306
+ *
6307
+ * You can use `where(...).takeOptional()` for non-unique conditions.
6218
6308
  *
6219
6309
  * ```ts
6220
- * const result: TableType | undefined = await db.table.findByOptional({
6221
- * key: 'value',
6222
- * });
6310
+ * await db.table.findByOptional({ key: 'value' });
6223
6311
  * ```
6224
6312
  *
6225
- * @param args - `where` conditions
6313
+ * @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
6226
6314
  */
6227
- findByOptional<T extends PickQueryMetaResultRelations>(this: T, ...args: WhereArg<T>[]): SetQueryReturnsOneOptional<WhereResult<T>>;
6315
+ findByOptional<T extends PickQueryResultUniqueColumns>(this: T, uniqueColumnValues: T['internal']['uniqueColumns']): SetQueryReturnsOneOptional<WhereResult<T>>;
6228
6316
  /**
6229
6317
  * Specifies the schema to be used as a prefix of a table name.
6230
6318
  *
@@ -6345,9 +6433,9 @@ declare class QueryMethods<ColumnTypes> {
6345
6433
  * Order by raw SQL expression.
6346
6434
  *
6347
6435
  * ```ts
6348
- * db.table.order`raw sql`;
6436
+ * db.table.orderSql`raw sql`;
6349
6437
  * // or
6350
- * db.table.order(db.table.sql`raw sql`);
6438
+ * db.table.orderSql(db.table.sql`raw sql`);
6351
6439
  * ```
6352
6440
  *
6353
6441
  * @param args - SQL expression
@@ -6541,9 +6629,16 @@ type DbDomainArg<ColumnTypes> = (columnTypes: ColumnTypes) => ColumnType;
6541
6629
  type DbDomainArgRecord = {
6542
6630
  [K: string]: DbDomainArg<any>;
6543
6631
  };
6544
- interface QueryInternal extends QueryInternalBase, TableData {
6632
+ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColumnNames = any, UniqueColumnTuples = any, UniqueConstraints = any> extends QueryInternalBase {
6633
+ singlePrimaryKey: SinglePrimaryKey;
6634
+ uniqueColumns: UniqueColumns;
6635
+ uniqueColumnNames: UniqueColumnNames;
6636
+ uniqueColumnTuples: UniqueColumnTuples;
6637
+ uniqueConstraints: UniqueConstraints;
6545
6638
  extensions?: DbExtension[];
6546
6639
  domains?: DbDomainArgRecord;
6640
+ tableData: TableData;
6641
+ primaryKeys?: string[];
6547
6642
  }
6548
6643
  type SelectableFromShape<Shape extends QueryColumns, Table extends string | undefined> = {
6549
6644
  [K in keyof Shape]: {
@@ -6568,12 +6663,10 @@ interface Query extends QueryBase, QueryMethods<unknown> {
6568
6663
  queryBuilder: Db;
6569
6664
  columnTypes: unknown;
6570
6665
  shape: QueryColumns;
6571
- singlePrimaryKey: string;
6572
- primaryKeys: string[];
6573
6666
  inputType: RecordUnknown;
6574
6667
  q: QueryData;
6575
6668
  then: QueryThen<unknown>;
6576
- catch: QueryCatch<unknown>;
6669
+ catch: QueryCatch;
6577
6670
  windows: EmptyObject;
6578
6671
  defaultSelectColumns: string[];
6579
6672
  relations: RelationsBase;
@@ -6632,7 +6725,9 @@ interface PickQueryQAndInternal extends PickQueryQ, PickQueryInternal {
6632
6725
  interface PickQueryQAndBaseQuery extends PickQueryQ, PickQueryBaseQuery {
6633
6726
  }
6634
6727
  interface PickQuerySinglePrimaryKey {
6635
- singlePrimaryKey: string;
6728
+ internal: {
6729
+ singlePrimaryKey: unknown;
6730
+ };
6636
6731
  }
6637
6732
  interface PickQueryShapeSinglePrimaryKey extends PickQueryShape, PickQuerySinglePrimaryKey {
6638
6733
  }
@@ -6645,14 +6740,24 @@ type SelectableOrExpressionOfType<T extends PickQueryMeta, C extends PickType> =
6645
6740
  interface QueryWithTable extends Query {
6646
6741
  table: string;
6647
6742
  }
6648
- declare const queryTypeWithLimitOne: Record<QueryReturnType, true | undefined>;
6743
+ declare const queryTypeWithLimitOne: {
6744
+ all: true | undefined;
6745
+ one: true | undefined;
6746
+ oneOrThrow: true | undefined;
6747
+ rows: true | undefined;
6748
+ pluck: true | undefined;
6749
+ value: true | undefined;
6750
+ valueOrThrow: true | undefined;
6751
+ rowCount: true | undefined;
6752
+ void: true | undefined;
6753
+ };
6649
6754
  declare const isQueryReturnsAll: (q: Query) => boolean;
6650
6755
  type QueryReturnsAll<T extends QueryReturnType> = (QueryReturnType extends T ? 'all' : T) extends 'all' ? true : false;
6651
6756
  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
6757
  type AddQuerySelect<T extends PickQueryMetaResultReturnType, Result extends QueryColumns> = {
6653
6758
  [K in keyof T]: K extends 'result' ? {
6654
6759
  [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];
6760
+ } : K extends 'then' ? QueryThen<GetQueryResult<T, Result>> : T[K];
6656
6761
  } & QueryMetaHasSelect;
6657
6762
  interface QueryMetaHasSelect {
6658
6763
  meta: {
@@ -6660,71 +6765,71 @@ interface QueryMetaHasSelect {
6660
6765
  };
6661
6766
  }
6662
6767
  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];
6768
+ [K in keyof T]: K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : T[K];
6664
6769
  } & QueryMetaHasWhere;
6665
6770
  type SetQueryReturnsAllKind<T extends PickQueryMetaResult, Kind extends string> = {
6666
6771
  [K in keyof T]: K extends 'meta' ? {
6667
6772
  [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];
6773
+ } : K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : T[K];
6669
6774
  } & QueryMetaHasWhere;
6670
6775
  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];
6776
+ [K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']> | undefined> : T[K];
6672
6777
  };
6673
6778
  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];
6779
+ [K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : T[K];
6675
6780
  };
6676
6781
  type SetQueryReturnsOneKind<T extends PickQueryMetaResult, Kind extends string> = {
6677
6782
  [K in keyof T]: K extends 'meta' ? {
6678
6783
  [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];
6784
+ } : K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : T[K];
6680
6785
  };
6681
6786
  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];
6787
+ [K in keyof T]: K extends 'returnType' ? 'rows' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[keyof T['result']][][]> : T[K];
6683
6788
  };
6684
6789
  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
6790
  type SetQueryReturnsPluckColumn<T, C extends QueryColumn> = {
6686
6791
  [K in keyof T]: K extends 'result' ? {
6687
6792
  pluck: C;
6688
- } : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<C['outputType'][]> : K extends 'catch' ? QueryCatch<C['outputType'][]> : T[K];
6793
+ } : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<C['outputType'][]> : T[K];
6689
6794
  } & QueryMetaHasSelect;
6690
6795
  type SetQueryReturnsPluckColumnKind<T extends PickQueryMetaResult, Kind extends string> = {
6691
6796
  [K in keyof T]: K extends 'meta' ? {
6692
6797
  [K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
6693
6798
  } : K extends 'result' ? {
6694
6799
  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];
6800
+ } : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['result']['value']['outputType'][]> : T[K];
6696
6801
  } & QueryMetaHasSelect;
6697
6802
  type SetQueryReturnsValueOrThrow<T extends PickQueryMeta, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOrThrow<T, T['meta']['selectable'][Arg]['column']> & T['meta']['selectable'][Arg]['column']['operators'];
6698
6803
  type SetQueryReturnsValueOptional<T extends PickQueryMeta, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOptional<T, T['meta']['selectable'][Arg]['column']> & T['meta']['selectable'][Arg]['column']['operators'];
6699
6804
  type SetQueryReturnsColumnOrThrow<T, Column extends PickOutputType> = {
6700
6805
  [K in keyof T]: K extends 'result' ? {
6701
6806
  value: Column;
6702
- } : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['outputType']> : K extends 'catch' ? QueryCatch<Column['outputType']> : T[K];
6807
+ } : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['outputType']> : T[K];
6703
6808
  } & QueryMetaHasSelect;
6704
6809
  type SetQueryReturnsColumnOptional<T, Column extends PickOutputType> = {
6705
6810
  [K in keyof T]: K extends 'result' ? {
6706
6811
  value: Column;
6707
- } : K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<Column['outputType'] | undefined> : K extends 'catch' ? QueryCatch<Column['outputType'] | undefined> : T[K];
6812
+ } : K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<Column['outputType'] | undefined> : T[K];
6708
6813
  } & QueryMetaHasSelect;
6709
6814
  type SetQueryReturnsColumnKind<T extends PickQueryMetaResult, Kind extends string> = {
6710
6815
  [K in keyof T]: K extends 'meta' ? {
6711
6816
  [K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
6712
6817
  } : K extends 'result' ? {
6713
6818
  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];
6819
+ } : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['pluck']['outputType']> : T[K];
6715
6820
  } & QueryMetaHasSelect;
6716
6821
  type SetQueryReturnsRowCount<T extends PickQueryMetaResult, Kind extends string> = {
6717
6822
  [K in keyof T]: K extends 'meta' ? {
6718
6823
  [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];
6824
+ } : K extends 'returnType' ? 'rowCount' : K extends 'then' ? QueryThen<number> : T[K];
6720
6825
  };
6721
6826
  type SetQueryReturnsVoid<T> = {
6722
- [K in keyof T]: K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : K extends 'catch' ? QueryCatch<void> : T[K];
6827
+ [K in keyof T]: K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : T[K];
6723
6828
  };
6724
6829
  type SetQueryReturnsVoidKind<T extends PickQueryMeta, Kind extends string> = {
6725
6830
  [K in keyof T]: K extends 'meta' ? {
6726
6831
  [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];
6832
+ } : K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : T[K];
6728
6833
  };
6729
6834
  type SetQueryKind<T extends PickQueryMeta, Kind extends string> = {
6730
6835
  [K in keyof T]: K extends 'meta' ? {
@@ -6754,76 +6859,14 @@ interface ColumnData extends ColumnDataBase {
6754
6859
  numericScale?: number;
6755
6860
  dateTimePrecision?: number;
6756
6861
  validationDefault?: unknown;
6757
- indexes?: Omit<SingleColumnIndexOptions, 'column'>[];
6862
+ indexes?: TableData.ColumnIndex[];
6758
6863
  comment?: string;
6759
6864
  collate?: string;
6760
6865
  compression?: string;
6761
- foreignKeys?: ForeignKey<string, string[]>[];
6866
+ foreignKeys?: TableData.ColumnReferences[];
6762
6867
  identity?: TableData.Identity;
6763
6868
  generated?: RawSQLBase;
6764
6869
  }
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
6870
  interface ColumnFromDbParams {
6828
6871
  isNullable?: boolean;
6829
6872
  default?: string;
@@ -6851,6 +6894,8 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6851
6894
  * readonly table = 'table';
6852
6895
  * columns = this.setColumns((t) => ({
6853
6896
  * id: t.uuid().primaryKey(),
6897
+ * // database-level name can be passed:
6898
+ * id: t.uuid().primaryKey('primary_key_name'),
6854
6899
  * }));
6855
6900
  * }
6856
6901
  *
@@ -6858,13 +6903,13 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6858
6903
  * db.table.find('97ba9e78-7510-415a-9c03-23d440aec443');
6859
6904
  * ```
6860
6905
  *
6861
- * @param options - to specify a constraint name
6906
+ * @param name - to specify a constraint name
6862
6907
  */
6863
- primaryKey<T extends PickColumnBaseData>(this: T, options?: ConstraintOptions): PrimaryKeyColumn<T>;
6908
+ primaryKey<T extends PickColumnBaseData, Name extends string>(this: T, name?: Name): PrimaryKeyColumn<T, Name>;
6864
6909
  /**
6865
- * Set the foreignKey for the column.
6910
+ * Defines a reference between different tables to enforce data integrity.
6866
6911
  *
6867
- * In `snakeCase` mode, columns of both tables are translated to a snake_case.
6912
+ * In [snakeCase](/guide/orm-and-query-builder.html#snakecase-option) mode, columns of both tables are translated to a snake_case.
6868
6913
  *
6869
6914
  * ```ts
6870
6915
  * import { change } from '../dbScript';
@@ -6876,7 +6921,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6876
6921
  * });
6877
6922
  * ```
6878
6923
  *
6879
- * In the ORM specify a function returning a table class instead of a name:
6924
+ * In the migration it's different from OrchidORM table code where a callback with a table is expected:
6880
6925
  *
6881
6926
  * ```ts
6882
6927
  * export class SomeTable extends BaseTable {
@@ -6885,13 +6930,6 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6885
6930
  * otherTableId: t.integer().foreignKey(() => OtherTable, 'id'),
6886
6931
  * }));
6887
6932
  * }
6888
- *
6889
- * export class OtherTable extends BaseTable {
6890
- * readonly table = 'otherTable';
6891
- * columns = this.setColumns((t) => ({
6892
- * id: t.identity().primaryKey(),
6893
- * }));
6894
- * }
6895
6933
  * ```
6896
6934
  *
6897
6935
  * Optionally you can pass the third argument to `foreignKey` with options:
@@ -6922,7 +6960,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6922
6960
  * change(async (db) => {
6923
6961
  * await db.createTable('table', (t) => ({
6924
6962
  * id: t.integer(),
6925
- * name: t.string(),
6963
+ * name: t.string(), // string is varchar(255)
6926
6964
  * ...t.foreignKey(
6927
6965
  * ['id', 'name'],
6928
6966
  * 'otherTable',
@@ -6942,14 +6980,59 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
6942
6980
  * @param column - column in the foreign table to connect with
6943
6981
  * @param options - {@link ForeignKeyOptions}
6944
6982
  */
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
- };
6983
+ foreignKey<T, Table extends ForeignKeyTable, Column extends ColumnNameOfTable<Table>>(this: T, fn: () => Table, column: Column, options?: TableData.References.Options): T;
6984
+ foreignKey<T, Table extends string, Column extends string>(this: T, table: Table, column: Column, options?: TableData.References.Options): T;
6951
6985
  toSQL(): string;
6952
- index<T extends PickColumnData>(this: T, options?: SingleColumnIndexOptionsForColumn): T;
6986
+ /**
6987
+ * Add an index to the column.
6988
+ *
6989
+ * ```ts
6990
+ * import { change } from '../dbScript';
6991
+ *
6992
+ * change(async (db) => {
6993
+ * await db.createTable('table', (t) => ({
6994
+ * // add an index to the name column with default settings:
6995
+ * name: t.text().index(),
6996
+ * // options are described below:
6997
+ * name: t.text().index({ ...options }),
6998
+ * // with a database-level name:
6999
+ * name: t.text().index('custom_index_name'),
7000
+ * // with name and options:
7001
+ * name: t.text().index('custom_index_name', { ...options }),
7002
+ * }));
7003
+ * });
7004
+ * ```
7005
+ *
7006
+ * Possible options are:
7007
+ *
7008
+ * ```ts
7009
+ * type IndexOptions = {
7010
+ * // NULLS NOT DISTINCT: availabe in Postgres 15+, makes sense only for unique index
7011
+ * nullsNotDistinct?: true;
7012
+ * // index algorithm to use such as GIST, GIN
7013
+ * using?: string;
7014
+ * // specify collation:
7015
+ * collate?: string;
7016
+ * // see `opclass` in the Postgres document for creating the index
7017
+ * opclass?: string;
7018
+ * // specify index order such as ASC NULLS FIRST, DESC NULLS LAST
7019
+ * order?: string;
7020
+ * // include columns to an index to optimize specific queries
7021
+ * include?: MaybeArray<string>;
7022
+ * // see "storage parameters" in the Postgres document for creating an index, for example, 'fillfactor = 70'
7023
+ * with?: string;
7024
+ * // The tablespace in which to create the index. If not specified, default_tablespace is consulted, or temp_tablespaces for indexes on temporary tables.
7025
+ * tablespace?: string;
7026
+ * // WHERE clause to filter records for the index
7027
+ * where?: string;
7028
+ * // mode is for dropping the index
7029
+ * mode?: 'CASCADE' | 'RESTRICT';
7030
+ * };
7031
+ * ```
7032
+ *
7033
+ * @param args
7034
+ */
7035
+ index<T extends PickColumnData>(this: T, ...args: [options?: TableData.Index.ColumnArg] | [name: string, options?: TableData.Index.ColumnArg]): T;
6953
7036
  /**
6954
7037
  * `searchIndex` is designed for [full text search](/guide/text-search).
6955
7038
  *
@@ -7052,8 +7135,11 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
7052
7135
  *
7053
7136
  * @param options - index options
7054
7137
  */
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;
7138
+ searchIndex<T extends {
7139
+ data: ColumnType['data'];
7140
+ dataType: string;
7141
+ }>(this: T, ...args: [options?: TableData.Index.TsVectorColumnArg] | [name: string, options?: TableData.Index.TsVectorColumnArg]): T;
7142
+ unique<T extends PickColumnData, Name extends string>(this: T, ...args: [options?: TableData.Index.UniqueColumnArg] | [name: Name, options?: TableData.Index.UniqueColumnArg]): UniqueColumn<T, Name>;
7057
7143
  comment<T extends PickColumnData>(this: T, comment: string): T;
7058
7144
  compression<T extends PickColumnData>(this: T, compression: string): T;
7059
7145
  collate<T extends PickColumnData>(this: T, collate: string): T;
@@ -7076,9 +7162,89 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
7076
7162
  generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs): T;
7077
7163
  }
7078
7164
 
7165
+ declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, boolean, ReturnType<Schema['boolean']>, OperatorsBoolean> {
7166
+ dataType: "bool";
7167
+ operators: OperatorsBoolean;
7168
+ constructor(schema: Schema);
7169
+ toCode(t: string, m?: boolean): Code;
7170
+ parseItem: (input: string) => boolean;
7171
+ }
7172
+
7173
+ declare class CustomTypeColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, unknown, ReturnType<Schema['unknown']>, typeof Operators.any> {
7174
+ dataType: string;
7175
+ operators: OperatorsAny;
7176
+ constructor(schema: Schema, dataType: string);
7177
+ toCode(t: string, m?: boolean): Code;
7178
+ as<T extends {
7179
+ inputType: unknown;
7180
+ outputType: unknown;
7181
+ data: ColumnDataBase;
7182
+ }, C extends Omit<ColumnTypeBase, 'inputType' | 'outputType'> & {
7183
+ inputType: T['inputType'];
7184
+ outputType: T['outputType'];
7185
+ }>(this: T, column: C): C;
7186
+ }
7187
+ declare class DomainColumn<Schema extends ColumnSchemaConfig> extends CustomTypeColumn<Schema> {
7188
+ toCode(t: string, m?: boolean): Code;
7189
+ }
7190
+
7191
+ declare const getColumnTypes: <ColumnTypes, Shape extends QueryColumnsInit>(types: ColumnTypes, fn: (t: ColumnTypes) => Shape, nowSQL: string | undefined, language: string | undefined) => Shape;
7192
+ interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends TimestampHelpers {
7193
+ schema: SchemaConfig;
7194
+ enum: SchemaConfig['enum'];
7195
+ array: SchemaConfig['array'];
7196
+ name<T>(this: T, name: string): T;
7197
+ sql: SqlFn;
7198
+ smallint: SchemaConfig['smallint'];
7199
+ integer: SchemaConfig['integer'];
7200
+ bigint: SchemaConfig['bigint'];
7201
+ numeric: SchemaConfig['decimal'];
7202
+ decimal: SchemaConfig['decimal'];
7203
+ real: SchemaConfig['real'];
7204
+ doublePrecision: SchemaConfig['doublePrecision'];
7205
+ identity(options?: TableData.Identity): IdentityColumn<ReturnType<SchemaConfig['integer']>>;
7206
+ smallSerial: SchemaConfig['smallSerial'];
7207
+ serial: SchemaConfig['serial'];
7208
+ bigSerial: SchemaConfig['bigSerial'];
7209
+ money: SchemaConfig['money'];
7210
+ varchar: SchemaConfig['varchar'];
7211
+ char: SchemaConfig['char'];
7212
+ text: SchemaConfig['text'];
7213
+ string: SchemaConfig['string'];
7214
+ citext: SchemaConfig['citext'];
7215
+ bytea(): ByteaColumn<SchemaConfig>;
7216
+ date: SchemaConfig['date'];
7217
+ timestampNoTZ: SchemaConfig['timestampNoTZ'];
7218
+ timestamp: SchemaConfig['timestamp'];
7219
+ time(precision?: number): TimeColumn<SchemaConfig>;
7220
+ interval(fields?: string, precision?: number): IntervalColumn<SchemaConfig>;
7221
+ boolean(): BooleanColumn<SchemaConfig>;
7222
+ point(): PointColumn<SchemaConfig>;
7223
+ line(): LineColumn<SchemaConfig>;
7224
+ lseg(): LsegColumn<SchemaConfig>;
7225
+ box(): BoxColumn<SchemaConfig>;
7226
+ path(): PathColumn<SchemaConfig>;
7227
+ polygon(): PolygonColumn<SchemaConfig>;
7228
+ circle(): CircleColumn<SchemaConfig>;
7229
+ cidr(): CidrColumn<SchemaConfig>;
7230
+ inet(): InetColumn<SchemaConfig>;
7231
+ macaddr(): MacAddrColumn<SchemaConfig>;
7232
+ macaddr8(): MacAddr8Column<SchemaConfig>;
7233
+ bit(length: number): BitColumn<SchemaConfig>;
7234
+ bitVarying(length?: number): BitVaryingColumn<SchemaConfig>;
7235
+ tsvector(): TsVectorColumn<SchemaConfig>;
7236
+ tsquery(): TsQueryColumn<SchemaConfig>;
7237
+ uuid(): UUIDColumn<SchemaConfig>;
7238
+ xml(): XMLColumn<SchemaConfig>;
7239
+ json: SchemaConfig['json'];
7240
+ jsonText(): JSONTextColumn<SchemaConfig>;
7241
+ type(dataType: string): CustomTypeColumn<SchemaConfig>;
7242
+ domain(dataType: string): DomainColumn<SchemaConfig>;
7243
+ }
7244
+ 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>;
7245
+
7079
7246
  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
7247
  declare const instantiateColumn: (typeFn: () => ColumnTypeBase, params: ColumnFromDbParams) => ColumnTypeBase;
7081
- declare const getConstraintKind: (it: TableData.Constraint) => 'constraint' | 'foreignKey' | 'check';
7082
7248
 
7083
7249
  interface ColumnsShape {
7084
7250
  [K: string]: ColumnType;
@@ -7135,20 +7301,19 @@ declare class UnknownColumn<Schema extends ColumnSchemaConfig> extends VirtualCo
7135
7301
  }
7136
7302
 
7137
7303
  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;
7304
+ declare const columnsShapeToCode: (shape: ColumnsShapeBase, t: string) => Codes;
7305
+ declare const pushTableDataCode: (code: Codes, ast: TableData) => Codes;
7140
7306
  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[];
7307
+ declare const indexToCode: (index: TableData.Index, t: string, prefix?: string) => Codes;
7308
+ declare const indexInnerToCode: (index: TableData.Index, t: string) => Codes;
7309
+ declare const constraintToCode: (item: TableData.Constraint, t: string, m?: boolean, prefix?: string) => Codes;
7310
+ declare const constraintInnerToCode: (item: TableData.Constraint, t: string, m?: boolean) => Codes;
7311
+ declare const referencesArgsToCode: ({ columns, fnOrTable, foreignColumns, options, }: Exclude<TableData.Constraint['references'], undefined>, name?: string | false, m?: boolean) => Codes;
7312
+ declare const columnForeignKeysToCode: (foreignKeys: TableData.ColumnReferences[], migration: boolean | undefined) => Codes;
7313
+ declare const foreignKeyArgumentToCode: ({ fnOrTable, foreignColumns, options, }: TableData.ColumnReferences, migration: boolean | undefined) => Codes;
7314
+ declare const columnIndexesToCode: (indexes: Exclude<ColumnData['indexes'], undefined>) => Codes;
7315
+ declare const columnCheckToCode: (t: string, { sql, name }: ColumnDataCheckBase) => string;
7316
+ declare const identityToCode: (identity: TableData.Identity, dataType?: string) => Codes;
7152
7317
  declare const columnCode: (type: ColumnType, t: string, code: Code, migration: boolean | undefined, data?: ColumnData, skip?: {
7153
7318
  encodeFn: unknown;
7154
7319
  }) => Code;
@@ -7208,6 +7373,7 @@ declare const saveSearchAlias: (q: QueryBase, as: string, key: 'joinedShapes' |
7208
7373
  * @param methods - methods to add
7209
7374
  */
7210
7375
  declare const extendQuery: <T extends PickQueryQAndBaseQuery, Methods extends RecordUnknown>(q: T, methods: Methods) => T & Methods;
7376
+ declare const getPrimaryKeys: (q: Query) => string[];
7211
7377
 
7212
7378
  type Arg = {
7213
7379
  $queryBuilder: Query;
@@ -7257,13 +7423,14 @@ declare function addComputedColumns<T extends PickQueryTableMetaShape, Computed
7257
7423
  * Sets query kind to 'columnInfo', returns a single value (may return undefined),
7258
7424
  * the value is a {@link GetColumnInfo} object or a Record with keys for column names and ColumnInfo objects as values.
7259
7425
  **/
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'> & {
7426
+ type SetQueryReturnsColumnInfo<T extends PickQueryMetaShape, Column extends keyof T['shape'] | undefined, Result = Column extends keyof T['shape'] ? GetColumnInfo : {
7427
+ [K in keyof T['shape']]: GetColumnInfo;
7428
+ }> = Omit<SetQueryKind<T, 'columnInfo'>, 'result' | 'returnType' | 'then'> & {
7261
7429
  result: {
7262
7430
  value: QueryColumn<Result>;
7263
7431
  };
7264
7432
  returnType: 'value';
7265
7433
  then: QueryThen<Result>;
7266
- catch: QueryCatch<Result>;
7267
7434
  };
7268
7435
  type GetColumnInfo = {
7269
7436
  defaultValue: unknown;
@@ -7347,4 +7514,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
7347
7514
  */
7348
7515
  declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
7349
7516
 
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 };
7517
+ 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, 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, 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 };