pqb 0.27.6 → 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 +839 -583
- package/dist/index.js +785 -574
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +777 -570
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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,
|
|
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';
|
|
@@ -37,7 +37,7 @@ declare class Adapter implements AdapterBase {
|
|
|
37
37
|
connect(): Promise<PoolClient>;
|
|
38
38
|
query<T extends QueryResultRow = QueryResultRow>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
39
39
|
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
40
|
-
transaction<Result>(begin: Sql, cb: (adapter: TransactionAdapter) => Promise<Result
|
|
40
|
+
transaction<Result>(begin: Sql, cb: (adapter: TransactionAdapter) => Promise<Result>, end?: Sql): Promise<Result>;
|
|
41
41
|
close(): Promise<void>;
|
|
42
42
|
}
|
|
43
43
|
declare class TransactionAdapter implements Adapter {
|
|
@@ -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> |
|
|
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 = [
|
|
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 |
|
|
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 |
|
|
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 =
|
|
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
|
-
|
|
357
|
-
|
|
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
|
-
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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:
|
|
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
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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>>> :
|
|
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]>;
|
|
@@ -2130,7 +2155,7 @@ declare abstract class DateBaseColumn<Schema extends ColumnSchemaConfig> extends
|
|
|
2130
2155
|
}
|
|
2131
2156
|
declare class DateColumn<Schema extends ColumnSchemaConfig> extends DateBaseColumn<Schema> {
|
|
2132
2157
|
dataType: "date";
|
|
2133
|
-
toCode(t: string): Code;
|
|
2158
|
+
toCode(t: string, m?: boolean): Code;
|
|
2134
2159
|
}
|
|
2135
2160
|
declare abstract class DateTimeBaseClass<Schema extends ColumnSchemaConfig> extends DateBaseColumn<Schema> {
|
|
2136
2161
|
data: DateColumnData & {
|
|
@@ -2145,12 +2170,12 @@ declare abstract class DateTimeTzBaseClass<Schema extends ColumnSchemaConfig> ex
|
|
|
2145
2170
|
}
|
|
2146
2171
|
declare class TimestampColumn<Schema extends ColumnSchemaConfig> extends DateTimeBaseClass<Schema> {
|
|
2147
2172
|
dataType: "timestamp";
|
|
2148
|
-
toCode(t: string): Code;
|
|
2173
|
+
toCode(t: string, m?: boolean): Code;
|
|
2149
2174
|
}
|
|
2150
2175
|
declare class TimestampTZColumn<Schema extends ColumnSchemaConfig> extends DateTimeTzBaseClass<Schema> {
|
|
2151
2176
|
dataType: "timestamptz";
|
|
2152
2177
|
baseDataType: "timestamp";
|
|
2153
|
-
toCode(t: string): Code;
|
|
2178
|
+
toCode(t: string, m?: boolean): Code;
|
|
2154
2179
|
}
|
|
2155
2180
|
declare class TimeColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsTime> {
|
|
2156
2181
|
data: DateColumnData & {
|
|
@@ -2159,7 +2184,7 @@ declare class TimeColumn<Schema extends ColumnSchemaConfig> extends ColumnType<S
|
|
|
2159
2184
|
dataType: "time";
|
|
2160
2185
|
operators: OperatorsTime;
|
|
2161
2186
|
constructor(schema: Schema, dateTimePrecision?: number);
|
|
2162
|
-
toCode(t: string): Code;
|
|
2187
|
+
toCode(t: string, m?: boolean): Code;
|
|
2163
2188
|
}
|
|
2164
2189
|
declare class IntervalColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, TimeInterval, ReturnType<Schema['timeInterval']>, OperatorsDate> {
|
|
2165
2190
|
data: ColumnData & {
|
|
@@ -2169,7 +2194,7 @@ declare class IntervalColumn<Schema extends ColumnSchemaConfig> extends ColumnTy
|
|
|
2169
2194
|
dataType: "interval";
|
|
2170
2195
|
operators: OperatorsDate;
|
|
2171
2196
|
constructor(schema: Schema, fields?: string, precision?: number);
|
|
2172
|
-
toCode(t: string): Code;
|
|
2197
|
+
toCode(t: string, m?: boolean): Code;
|
|
2173
2198
|
toSQL(): string;
|
|
2174
2199
|
}
|
|
2175
2200
|
|
|
@@ -2179,7 +2204,7 @@ declare class EnumColumn<Schema extends ColumnTypeSchemaArg, SchemaType extends
|
|
|
2179
2204
|
operators: OperatorsAny;
|
|
2180
2205
|
dataType: string;
|
|
2181
2206
|
constructor(schema: Schema, enumName: string, options: T, schemaType: SchemaType);
|
|
2182
|
-
toCode(t: string,
|
|
2207
|
+
toCode(t: string, m?: boolean): Code;
|
|
2183
2208
|
toSQL(): string;
|
|
2184
2209
|
}
|
|
2185
2210
|
|
|
@@ -2192,7 +2217,7 @@ interface ArrayColumnValue {
|
|
|
2192
2217
|
queryType: unknown;
|
|
2193
2218
|
querySchema: any;
|
|
2194
2219
|
toSQL(): string;
|
|
2195
|
-
toCode(t: string,
|
|
2220
|
+
toCode(t: string, m?: boolean): Code;
|
|
2196
2221
|
parseItem?(input: string): unknown;
|
|
2197
2222
|
data: ColumnDataBase;
|
|
2198
2223
|
}
|
|
@@ -2205,7 +2230,7 @@ declare class ArrayColumn<Schema extends ColumnTypeSchemaArg, Item extends Array
|
|
|
2205
2230
|
data: ArrayData<Item>;
|
|
2206
2231
|
constructor(schema: Schema, item: Item, inputType: InputType, outputType?: OutputType, queryType?: QueryType);
|
|
2207
2232
|
toSQL(): string;
|
|
2208
|
-
toCode(this: ArrayColumn<ColumnSchemaConfig, ArrayColumnValue, unknown, unknown, unknown>, t: string): Code;
|
|
2233
|
+
toCode(this: ArrayColumn<ColumnSchemaConfig, ArrayColumnValue, unknown, unknown, unknown>, t: string, m?: boolean): Code;
|
|
2209
2234
|
parseFn: ((input: unknown) => unknown[]) & {
|
|
2210
2235
|
hideFromCode: boolean;
|
|
2211
2236
|
};
|
|
@@ -2214,13 +2239,294 @@ declare class ArrayColumn<Schema extends ColumnTypeSchemaArg, Item extends Array
|
|
|
2214
2239
|
declare class JSONColumn<T, Schema extends ColumnTypeSchemaArg> extends ColumnType<Schema, T, Schema['type'], OperatorsJson> {
|
|
2215
2240
|
dataType: "jsonb";
|
|
2216
2241
|
operators: OperatorsJson;
|
|
2217
|
-
toCode(t: string): Code;
|
|
2242
|
+
toCode(t: string, m?: boolean): Code;
|
|
2218
2243
|
}
|
|
2219
2244
|
declare class JSONTextColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2220
2245
|
dataType: "json";
|
|
2221
2246
|
operators: OperatorsText;
|
|
2222
2247
|
constructor(schema: Schema);
|
|
2223
|
-
toCode(t: string): Code;
|
|
2248
|
+
toCode(t: string, m?: boolean): Code;
|
|
2249
|
+
}
|
|
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;
|
|
2224
2530
|
}
|
|
2225
2531
|
|
|
2226
2532
|
type TextColumnData = StringTypeData;
|
|
@@ -2238,15 +2544,15 @@ declare abstract class LimitedTextBaseColumn<Schema extends ColumnSchemaConfig>
|
|
|
2238
2544
|
}
|
|
2239
2545
|
declare class VarCharColumn<Schema extends ColumnSchemaConfig> extends LimitedTextBaseColumn<Schema> {
|
|
2240
2546
|
dataType: "varchar";
|
|
2241
|
-
toCode(t: string): Code;
|
|
2547
|
+
toCode(t: string, m?: boolean): Code;
|
|
2242
2548
|
}
|
|
2243
2549
|
declare class StringColumn$1<Schema extends ColumnSchemaConfig> extends VarCharColumn<Schema> {
|
|
2244
2550
|
constructor(schema: Schema, limit?: number);
|
|
2245
|
-
toCode(t: string): Code;
|
|
2551
|
+
toCode(t: string, m?: boolean): Code;
|
|
2246
2552
|
}
|
|
2247
2553
|
declare class CharColumn<Schema extends ColumnSchemaConfig> extends LimitedTextBaseColumn<Schema> {
|
|
2248
2554
|
dataType: "char";
|
|
2249
|
-
toCode(t: string): Code;
|
|
2555
|
+
toCode(t: string, m?: boolean): Code;
|
|
2250
2556
|
}
|
|
2251
2557
|
declare class TextColumn<Schema extends ColumnSchemaConfig> extends TextBaseColumn<Schema> {
|
|
2252
2558
|
dataType: "text";
|
|
@@ -2255,60 +2561,60 @@ declare class TextColumn<Schema extends ColumnSchemaConfig> extends TextBaseColu
|
|
|
2255
2561
|
maxArg?: number;
|
|
2256
2562
|
};
|
|
2257
2563
|
constructor(schema: Schema, min?: number, max?: number);
|
|
2258
|
-
toCode(t: string): Code;
|
|
2564
|
+
toCode(t: string, m?: boolean): Code;
|
|
2259
2565
|
}
|
|
2260
2566
|
declare class ByteaColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, Buffer, ReturnType<Schema['buffer']>, OperatorsText> {
|
|
2261
2567
|
dataType: "bytea";
|
|
2262
2568
|
operators: OperatorsText;
|
|
2263
2569
|
constructor(schema: Schema);
|
|
2264
|
-
toCode(t: string): Code;
|
|
2570
|
+
toCode(t: string, m?: boolean): Code;
|
|
2265
2571
|
}
|
|
2266
2572
|
declare class PointColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2267
2573
|
dataType: "point";
|
|
2268
2574
|
operators: OperatorsText;
|
|
2269
2575
|
constructor(schema: Schema);
|
|
2270
|
-
toCode(t: string): Code;
|
|
2576
|
+
toCode(t: string, m?: boolean): Code;
|
|
2271
2577
|
}
|
|
2272
2578
|
declare class LineColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2273
2579
|
dataType: "line";
|
|
2274
2580
|
operators: OperatorsText;
|
|
2275
2581
|
constructor(schema: Schema);
|
|
2276
|
-
toCode(t: string): Code;
|
|
2582
|
+
toCode(t: string, m?: boolean): Code;
|
|
2277
2583
|
}
|
|
2278
2584
|
declare class LsegColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2279
2585
|
dataType: "lseg";
|
|
2280
2586
|
operators: OperatorsText;
|
|
2281
2587
|
constructor(schema: Schema);
|
|
2282
|
-
toCode(t: string): Code;
|
|
2588
|
+
toCode(t: string, m?: boolean): Code;
|
|
2283
2589
|
}
|
|
2284
2590
|
declare class BoxColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2285
2591
|
dataType: "box";
|
|
2286
2592
|
operators: OperatorsText;
|
|
2287
2593
|
constructor(schema: Schema);
|
|
2288
|
-
toCode(t: string): Code;
|
|
2594
|
+
toCode(t: string, m?: boolean): Code;
|
|
2289
2595
|
}
|
|
2290
2596
|
declare class PathColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2291
2597
|
dataType: "path";
|
|
2292
2598
|
operators: OperatorsText;
|
|
2293
2599
|
constructor(schema: Schema);
|
|
2294
|
-
toCode(t: string): Code;
|
|
2600
|
+
toCode(t: string, m?: boolean): Code;
|
|
2295
2601
|
}
|
|
2296
2602
|
declare class PolygonColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2297
2603
|
dataType: "polygon";
|
|
2298
2604
|
operators: OperatorsText;
|
|
2299
2605
|
constructor(schema: Schema);
|
|
2300
|
-
toCode(t: string): Code;
|
|
2606
|
+
toCode(t: string, m?: boolean): Code;
|
|
2301
2607
|
}
|
|
2302
2608
|
declare class CircleColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2303
2609
|
dataType: "circle";
|
|
2304
2610
|
operators: OperatorsText;
|
|
2305
2611
|
constructor(schema: Schema);
|
|
2306
|
-
toCode(t: string): Code;
|
|
2612
|
+
toCode(t: string, m?: boolean): Code;
|
|
2307
2613
|
}
|
|
2308
2614
|
declare class MoneyColumn<Schema extends ColumnSchemaConfig> extends NumberBaseColumn<Schema, ReturnType<Schema['stringSchema']>> {
|
|
2309
2615
|
dataType: "money";
|
|
2310
2616
|
constructor(schema: Schema);
|
|
2311
|
-
toCode(t: string): Code;
|
|
2617
|
+
toCode(t: string, m?: boolean): Code;
|
|
2312
2618
|
parseFn: ((input: unknown) => number) & {
|
|
2313
2619
|
hideFromCode: boolean;
|
|
2314
2620
|
};
|
|
@@ -2317,25 +2623,25 @@ declare class CidrColumn<Schema extends ColumnSchemaConfig> extends ColumnType<S
|
|
|
2317
2623
|
dataType: "cidr";
|
|
2318
2624
|
operators: OperatorsText;
|
|
2319
2625
|
constructor(schema: Schema);
|
|
2320
|
-
toCode(t: string): Code;
|
|
2626
|
+
toCode(t: string, m?: boolean): Code;
|
|
2321
2627
|
}
|
|
2322
2628
|
declare class InetColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2323
2629
|
dataType: "inet";
|
|
2324
2630
|
operators: OperatorsText;
|
|
2325
2631
|
constructor(schema: Schema);
|
|
2326
|
-
toCode(t: string): Code;
|
|
2632
|
+
toCode(t: string, m?: boolean): Code;
|
|
2327
2633
|
}
|
|
2328
2634
|
declare class MacAddrColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2329
2635
|
dataType: "macaddr";
|
|
2330
2636
|
operators: OperatorsText;
|
|
2331
2637
|
constructor(schema: Schema);
|
|
2332
|
-
toCode(t: string): Code;
|
|
2638
|
+
toCode(t: string, m?: boolean): Code;
|
|
2333
2639
|
}
|
|
2334
2640
|
declare class MacAddr8Column<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2335
2641
|
dataType: "macaddr8";
|
|
2336
2642
|
operators: OperatorsText;
|
|
2337
2643
|
constructor(schema: Schema);
|
|
2338
|
-
toCode(t: string): Code;
|
|
2644
|
+
toCode(t: string, m?: boolean): Code;
|
|
2339
2645
|
}
|
|
2340
2646
|
declare class BitColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['bit']>, OperatorsText> {
|
|
2341
2647
|
dataType: "bit";
|
|
@@ -2344,26 +2650,26 @@ declare class BitColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Sc
|
|
|
2344
2650
|
length: number;
|
|
2345
2651
|
};
|
|
2346
2652
|
constructor(schema: Schema, length: number);
|
|
2347
|
-
toCode(t: string): Code;
|
|
2653
|
+
toCode(t: string, m?: boolean): Code;
|
|
2348
2654
|
toSQL(): string;
|
|
2349
2655
|
}
|
|
2350
2656
|
declare class BitVaryingColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['bit']>, OperatorsText> {
|
|
2351
|
-
dataType: "
|
|
2657
|
+
dataType: "varbit";
|
|
2352
2658
|
operators: OperatorsText;
|
|
2353
2659
|
data: ColumnData & {
|
|
2354
2660
|
length?: number;
|
|
2355
2661
|
};
|
|
2356
2662
|
constructor(schema: Schema, length?: number);
|
|
2357
|
-
toCode(t: string): Code;
|
|
2663
|
+
toCode(t: string, m?: boolean): Code;
|
|
2358
2664
|
toSQL(): string;
|
|
2359
2665
|
}
|
|
2360
|
-
type TsVectorGeneratedColumns = string[] |
|
|
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";
|
|
2364
2670
|
operators: OperatorsText;
|
|
2365
2671
|
constructor(schema: Schema, defaultLanguage?: string);
|
|
2366
|
-
toCode(t: string): Code;
|
|
2672
|
+
toCode(t: string, m?: boolean): Code;
|
|
2367
2673
|
/**
|
|
2368
2674
|
* For `tsvector` column type, it can also accept language (optional) and columns:
|
|
2369
2675
|
*
|
|
@@ -2394,271 +2700,37 @@ declare class TsQueryColumn<Schema extends ColumnSchemaConfig> extends ColumnTyp
|
|
|
2394
2700
|
dataType: "tsquery";
|
|
2395
2701
|
operators: OperatorsText;
|
|
2396
2702
|
constructor(schema: Schema);
|
|
2397
|
-
toCode(t: string): Code;
|
|
2703
|
+
toCode(t: string, m?: boolean): Code;
|
|
2398
2704
|
}
|
|
2399
2705
|
declare class UUIDColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['uuid']>, OperatorsText> {
|
|
2400
2706
|
dataType: "uuid";
|
|
2401
2707
|
operators: OperatorsText;
|
|
2402
2708
|
constructor(schema: Schema);
|
|
2403
|
-
|
|
2404
|
-
|
|
2709
|
+
/**
|
|
2710
|
+
* see {@link ColumnType.primaryKey}
|
|
2711
|
+
*/
|
|
2712
|
+
primaryKey<T extends PickColumnBaseData, Name extends string>(this: T, name?: Name): // using & bc otherwise the return type doesn't match `primaryKey` in ColumnType and TS complains
|
|
2713
|
+
PrimaryKeyColumn<T, Name> & {
|
|
2405
2714
|
data: {
|
|
2406
2715
|
default: RawSQLBase;
|
|
2407
2716
|
};
|
|
2408
2717
|
};
|
|
2409
|
-
toCode(t: string): Code;
|
|
2718
|
+
toCode(t: string, m?: boolean): Code;
|
|
2410
2719
|
}
|
|
2411
2720
|
declare class XMLColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, string, ReturnType<Schema['stringSchema']>, OperatorsText> {
|
|
2412
2721
|
dataType: "xml";
|
|
2413
2722
|
operators: OperatorsText;
|
|
2414
2723
|
constructor(schema: Schema);
|
|
2415
|
-
toCode(t: string): Code;
|
|
2724
|
+
toCode(t: string, m?: boolean): Code;
|
|
2416
2725
|
}
|
|
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): Code;
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, boolean, ReturnType<Schema['boolean']>, OperatorsBoolean> {
|
|
2428
|
-
dataType: "boolean";
|
|
2429
|
-
operators: OperatorsBoolean;
|
|
2430
|
-
constructor(schema: Schema);
|
|
2431
|
-
toCode(t: string): 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): 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): 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
|
-
incrementBy?: number;
|
|
2481
|
-
startWith?: 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): 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: "decimal";
|
|
2609
|
-
constructor(schema: Schema, numericPrecision?: number, numericScale?: number);
|
|
2610
|
-
toCode(t: string): 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: "smallint";
|
|
2616
|
-
parseItem: typeof parseInt;
|
|
2617
|
-
toCode(t: string): Code;
|
|
2618
|
-
identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
|
|
2619
|
-
}
|
|
2620
|
-
declare class IntegerColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
|
|
2621
|
-
dataType: "integer";
|
|
2622
|
-
parseItem: typeof parseInt;
|
|
2623
|
-
toCode(t: string): Code;
|
|
2624
|
-
identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
|
|
2625
|
-
}
|
|
2626
|
-
declare class BigIntColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
|
|
2627
|
-
dataType: "bigint";
|
|
2628
|
-
toCode(t: string): Code;
|
|
2629
|
-
identity<T extends ColumnType>(this: T, options?: TableData.Identity): IdentityColumn<T>;
|
|
2630
|
-
}
|
|
2631
|
-
declare class RealColumn<Schema extends ColumnSchemaConfig> extends NumberBaseColumn<Schema, ReturnType<Schema['number']>> {
|
|
2632
|
-
dataType: "real";
|
|
2633
|
-
parseItem: typeof parseFloat;
|
|
2634
|
-
constructor(schema: Schema);
|
|
2635
|
-
toCode(t: string): Code;
|
|
2636
|
-
}
|
|
2637
|
-
declare class DoublePrecisionColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
|
|
2638
|
-
dataType: "double precision";
|
|
2639
|
-
toCode(t: string): Code;
|
|
2640
|
-
}
|
|
2641
|
-
declare class SmallSerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
|
|
2642
|
-
dataType: "smallint";
|
|
2643
|
-
parseItem: typeof parseInt;
|
|
2644
|
-
data: SerialColumnData;
|
|
2645
|
-
constructor(schema: Schema);
|
|
2646
|
-
toSQL(): string;
|
|
2647
|
-
toCode(t: string): Code;
|
|
2648
|
-
}
|
|
2649
|
-
declare class SerialColumn<Schema extends ColumnSchemaConfig> extends IntegerBaseColumn<Schema> {
|
|
2650
|
-
dataType: "integer";
|
|
2651
|
-
parseItem: typeof parseInt;
|
|
2652
|
-
data: SerialColumnData;
|
|
2653
|
-
constructor(schema: Schema);
|
|
2654
|
-
toSQL(): string;
|
|
2655
|
-
toCode(t: string): Code;
|
|
2656
|
-
}
|
|
2657
|
-
declare class BigSerialColumn<Schema extends ColumnSchemaConfig> extends NumberAsStringBaseColumn<Schema> {
|
|
2658
|
-
dataType: "bigint";
|
|
2659
|
-
data: SerialColumnData;
|
|
2660
|
-
toSQL(): string;
|
|
2661
|
-
toCode(t: string): Code;
|
|
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);
|
|
2733
|
+
toCode(t: string, m?: boolean): Code;
|
|
2662
2734
|
}
|
|
2663
2735
|
|
|
2664
2736
|
interface DefaultSchemaConfig extends ColumnSchemaConfig<ColumnType> {
|
|
@@ -2770,14 +2842,33 @@ declare class SoftDeleteMethods {
|
|
|
2770
2842
|
hardDelete<T extends QueryWithSoftDelete>(this: T, ..._args: DeleteArgs<T>): DeleteResult<T>;
|
|
2771
2843
|
}
|
|
2772
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];
|
|
2773
2858
|
type NoPrimaryKeyOption = 'error' | 'warning' | 'ignore';
|
|
2859
|
+
interface DbSharedOptions extends QueryLogOptions {
|
|
2860
|
+
autoPreparedStatements?: boolean;
|
|
2861
|
+
noPrimaryKey?: NoPrimaryKeyOption;
|
|
2862
|
+
extensions?: (string | RecordString)[];
|
|
2863
|
+
domains?: {
|
|
2864
|
+
[K: string]: DbDomainArg<DefaultColumnTypes<DefaultSchemaConfig>>;
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2774
2867
|
type DbOptions<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> = ({
|
|
2775
2868
|
adapter: Adapter;
|
|
2776
|
-
} | Omit<AdapterOptions, 'log'>) &
|
|
2869
|
+
} | Omit<AdapterOptions, 'log'>) & DbSharedOptions & {
|
|
2777
2870
|
schemaConfig?: SchemaConfig;
|
|
2778
2871
|
columnTypes?: ColumnTypes | ((t: DefaultColumnTypes<SchemaConfig>) => ColumnTypes);
|
|
2779
|
-
autoPreparedStatements?: boolean;
|
|
2780
|
-
noPrimaryKey?: NoPrimaryKeyOption;
|
|
2781
2872
|
snakeCase?: boolean;
|
|
2782
2873
|
nowSQL?: string;
|
|
2783
2874
|
};
|
|
@@ -2795,21 +2886,23 @@ interface DbTableOptions<Table extends string | undefined, Shape extends QueryCo
|
|
|
2795
2886
|
* See {@link SoftDeleteMethods}
|
|
2796
2887
|
*/
|
|
2797
2888
|
softDelete?: SoftDeleteOption<Shape>;
|
|
2889
|
+
comment?: string;
|
|
2798
2890
|
}
|
|
2799
2891
|
/**
|
|
2800
2892
|
* See {@link ScopeMethods}
|
|
2801
2893
|
*/
|
|
2802
|
-
type DbTableOptionScopes<Table extends string | undefined, Shape extends QueryColumns, Keys extends string = string> =
|
|
2803
|
-
|
|
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
|
+
}[];
|
|
2804
2900
|
declare const anyShape: QueryColumnsInit;
|
|
2805
|
-
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 {
|
|
2806
|
-
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 {
|
|
2807
2902
|
result: Pick<Shape, DefaultSelectColumns<Shape>[number]>;
|
|
2808
2903
|
queryBuilder: Db;
|
|
2809
|
-
primaryKeys: Query['primaryKeys'];
|
|
2810
2904
|
returnType: Query['returnType'];
|
|
2811
2905
|
then: QueryThen<QueryDefaultReturnData<Shape>>;
|
|
2812
|
-
catch: QueryCatch<QueryDefaultReturnData<Shape>>;
|
|
2813
2906
|
windows: Query['windows'];
|
|
2814
2907
|
defaultSelectColumns: DefaultSelectColumns<Shape>;
|
|
2815
2908
|
relations: Relations;
|
|
@@ -2820,17 +2913,25 @@ interface Db<Table extends string | undefined = undefined, Shape extends QueryCo
|
|
|
2820
2913
|
defaults: {
|
|
2821
2914
|
[K in keyof Shape as unknown extends Shape[K]['data']['default'] ? never : K]: true;
|
|
2822
2915
|
};
|
|
2823
|
-
scopes:
|
|
2916
|
+
scopes: {
|
|
2917
|
+
[K in keyof Scopes]: true;
|
|
2918
|
+
};
|
|
2824
2919
|
selectable: SelectableFromShape<ShapeWithComputed, Table>;
|
|
2825
2920
|
};
|
|
2826
|
-
|
|
2827
|
-
|
|
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 {
|
|
2828
2929
|
adapter: Adapter;
|
|
2829
2930
|
queryBuilder: Db;
|
|
2830
2931
|
table: Table;
|
|
2831
2932
|
shape: ShapeWithComputed;
|
|
2832
2933
|
columnTypes: ColumnTypes;
|
|
2833
|
-
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: ShapeWithComputed, columnTypes: ColumnTypes, transactionStorage: AsyncLocalStorage<TransactionState>, options: DbTableOptions<Table, ShapeWithComputed
|
|
2934
|
+
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: ShapeWithComputed, columnTypes: ColumnTypes, transactionStorage: AsyncLocalStorage<TransactionState>, options: DbTableOptions<Table, ShapeWithComputed>, tableData?: TableData);
|
|
2834
2935
|
[inspect.custom](): string;
|
|
2835
2936
|
/**
|
|
2836
2937
|
* Use `query` to perform raw SQL queries.
|
|
@@ -2890,16 +2991,16 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Que
|
|
|
2890
2991
|
*/
|
|
2891
2992
|
queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryArraysResult<R>>;
|
|
2892
2993
|
}
|
|
2893
|
-
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']>>;
|
|
2894
2995
|
type MapTableScopesOption<Scopes extends CoreQueryScopes | undefined, SoftDelete extends true | PropertyKey | undefined> = {
|
|
2895
2996
|
[K in keyof Scopes | (SoftDelete extends true | PropertyKey ? 'nonDeleted' : never)]: unknown;
|
|
2896
2997
|
};
|
|
2897
|
-
interface DbResult<ColumnTypes> extends Db<string,
|
|
2998
|
+
interface DbResult<ColumnTypes> extends Db<string, never, never, never, never, never, EmptyObject, ColumnTypes>, DbTableConstructor<ColumnTypes> {
|
|
2898
2999
|
adapter: Adapter;
|
|
2899
3000
|
close: Adapter['close'];
|
|
2900
3001
|
}
|
|
2901
3002
|
/**
|
|
2902
|
-
*
|
|
3003
|
+
* If you'd like to use the query builder of OrchidORM as a standalone tool, install `pqb` package and use `createDb` to initialize it.
|
|
2903
3004
|
*
|
|
2904
3005
|
* As `Orchid ORM` focuses on ORM usage, docs examples mostly demonstrates how to work with ORM-defined tables,
|
|
2905
3006
|
* but everything that's not related to table relations should also work with `pqb` query builder on its own.
|
|
@@ -2975,6 +3076,7 @@ interface DbResult<ColumnTypes> extends Db<string, Record<string, never>, EmptyO
|
|
|
2975
3076
|
* ```
|
|
2976
3077
|
*/
|
|
2977
3078
|
declare const createDb: <SchemaConfig extends ColumnSchemaConfig<ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>> = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({ log, logger, snakeCase, nowSQL, schemaConfig, columnTypes: ctOrFn, ...options }: DbOptions<SchemaConfig, ColumnTypes>) => DbResult<ColumnTypes>;
|
|
3079
|
+
declare const _initQueryBuilder: (adapter: Adapter, columnTypes: unknown, transactionStorage: AsyncLocalStorage<TransactionState>, commonOptions: DbTableOptions<undefined, QueryColumns>, options: DbSharedOptions) => Db;
|
|
2978
3080
|
|
|
2979
3081
|
type ToSQLCtx = {
|
|
2980
3082
|
queryBuilder: Db;
|
|
@@ -2991,7 +3093,21 @@ type ToSQLOptions = {
|
|
|
2991
3093
|
type ToSqlOptionsInternal = ToSQLOptions & {
|
|
2992
3094
|
aliasValue?: true;
|
|
2993
3095
|
};
|
|
2994
|
-
type ToSQLQuery =
|
|
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
|
+
};
|
|
2995
3111
|
declare const toSQL: (table: ToSQLQuery, options?: ToSQLOptions) => Sql;
|
|
2996
3112
|
declare const makeSQL: (table: ToSQLQuery, options?: ToSqlOptionsInternal) => Sql;
|
|
2997
3113
|
declare function pushLimitSQL(sql: string[], values: unknown[], q: SelectQueryData): void;
|
|
@@ -3001,7 +3117,7 @@ type SelectableOrExpression<T extends PickQueryMeta = PickQueryMeta, C extends Q
|
|
|
3001
3117
|
type ExpressionOutput<T extends PickQueryMeta, Expr extends SelectableOrExpression<T>> = Expr extends keyof T['meta']['selectable'] ? T['meta']['selectable'][Expr]['column'] : Expr extends Expression ? Expr['_type'] : never;
|
|
3002
3118
|
declare const getClonedQueryData: (query: QueryData) => QueryData;
|
|
3003
3119
|
declare const getQueryAs: (q: {
|
|
3004
|
-
table?: string
|
|
3120
|
+
table?: string;
|
|
3005
3121
|
q: {
|
|
3006
3122
|
as?: string;
|
|
3007
3123
|
};
|
|
@@ -3037,7 +3153,9 @@ interface AggregateOptions<T extends PickQueryMetaResultRelationsWindows> {
|
|
|
3037
3153
|
type Over<T extends PickQueryMetaResultWindows> = keyof T['windows'] | WindowArgDeclaration<T>;
|
|
3038
3154
|
type FnExpressionArgs<Q extends PickQueryMeta> = (SelectableOrExpression<Q> | FnExpressionArgsPairs<Q> | FnExpressionArgsValue)[];
|
|
3039
3155
|
interface FnExpressionArgsPairs<Q extends PickQueryMeta> {
|
|
3040
|
-
pairs:
|
|
3156
|
+
pairs: {
|
|
3157
|
+
[K: string]: SelectableOrExpression<Q>;
|
|
3158
|
+
};
|
|
3041
3159
|
}
|
|
3042
3160
|
interface FnExpressionArgsValue {
|
|
3043
3161
|
value: unknown;
|
|
@@ -3622,7 +3740,9 @@ type CreateRawArgs<T extends CreateSelf, Arg extends {
|
|
|
3622
3740
|
}> = keyof RawRequiredColumns<T> extends Arg['columns'][number] ? [data: Arg] : [
|
|
3623
3741
|
`Missing required columns: ${Exclude<keyof RawRequiredColumns<T> & string, Arg['columns'][number]>}`
|
|
3624
3742
|
];
|
|
3625
|
-
type OnConflictArg<T extends
|
|
3743
|
+
type OnConflictArg<T extends PickQueryUniqueProperties> = T['internal']['uniqueColumnNames'] | T['internal']['uniqueColumnTuples'] | Expression | {
|
|
3744
|
+
constraint: T['internal']['uniqueConstraints'];
|
|
3745
|
+
};
|
|
3626
3746
|
type AddQueryDefaults<T extends CreateSelf, Defaults> = {
|
|
3627
3747
|
[K in keyof T]: K extends 'meta' ? {
|
|
3628
3748
|
[K in keyof T['meta']]: K extends 'defaults' ? T['meta']['defaults'] & Defaults : T['meta'][K];
|
|
@@ -3653,7 +3773,7 @@ declare const _queryInsertFrom: <T extends CreateSelf, Q extends Query & {
|
|
|
3653
3773
|
}>(q: T, query: Q, data?: Omit<CreateData<T>, keyof Q['result']>) => InsertResult<T>;
|
|
3654
3774
|
declare const _queryCreateManyFrom: <T extends CreateSelf>(q: T, query: Query) => CreateManyResult<T>;
|
|
3655
3775
|
declare const _queryInsertManyFrom: <T extends CreateSelf>(q: T, query: Query) => InsertManyResult<T>;
|
|
3656
|
-
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T>>>(q: T, data: Data) => AddQueryDefaults<T,
|
|
3776
|
+
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T>>>(q: T, data: Data) => AddQueryDefaults<T, { [K in keyof Data]: true; }>;
|
|
3657
3777
|
/**
|
|
3658
3778
|
* Names of all create methods,
|
|
3659
3779
|
* is used in {@link RelationQuery} to remove these methods if chained relation shouldn't have them,
|
|
@@ -3672,9 +3792,9 @@ declare class Create {
|
|
|
3672
3792
|
* password: '1234',
|
|
3673
3793
|
* });
|
|
3674
3794
|
*
|
|
3675
|
-
* // When using `.
|
|
3795
|
+
* // When using `.onConflictIgnore()`,
|
|
3676
3796
|
* // the record may be not created and the `createdCount` will be 0.
|
|
3677
|
-
* const createdCount = await db.table.insert(data).
|
|
3797
|
+
* const createdCount = await db.table.insert(data).onConflictIgnore();
|
|
3678
3798
|
*
|
|
3679
3799
|
* await db.table.create({
|
|
3680
3800
|
* // raw SQL
|
|
@@ -3864,34 +3984,48 @@ declare class Create {
|
|
|
3864
3984
|
*
|
|
3865
3985
|
* @param data - default values for `create` and `createMany` which will follow `defaults`
|
|
3866
3986
|
*/
|
|
3867
|
-
defaults<T extends CreateSelf, Data extends Partial<CreateData<T>>>(this: T, data: Data): AddQueryDefaults<T,
|
|
3987
|
+
defaults<T extends CreateSelf, Data extends Partial<CreateData<T>>>(this: T, data: Data): AddQueryDefaults<T, {
|
|
3988
|
+
[K in keyof Data]: true;
|
|
3989
|
+
}>;
|
|
3868
3990
|
/**
|
|
3869
|
-
*
|
|
3870
|
-
*
|
|
3871
|
-
*
|
|
3872
|
-
*
|
|
3873
|
-
*
|
|
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.
|
|
3874
4000
|
*
|
|
3875
|
-
*
|
|
3876
|
-
*
|
|
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.
|
|
3877
4009
|
*
|
|
3878
4010
|
* ```ts
|
|
3879
4011
|
* // leave `onConflict` without argument to ignore or merge on any conflict
|
|
3880
|
-
* db.table.create(data).
|
|
4012
|
+
* db.table.create(data).onConflictIgnore();
|
|
3881
4013
|
*
|
|
3882
4014
|
* // single column:
|
|
3883
|
-
* db.table.create(data).onConfict('email');
|
|
4015
|
+
* db.table.create(data).onConfict('email').merge();
|
|
3884
4016
|
*
|
|
3885
4017
|
* // array of columns:
|
|
3886
|
-
* db.table.create(data).onConfict(['email', 'name']);
|
|
4018
|
+
* db.table.create(data).onConfict(['email', 'name']).merge();
|
|
3887
4019
|
*
|
|
3888
|
-
* //
|
|
3889
|
-
* db.table.create(data).onConfict(
|
|
3890
|
-
* ```
|
|
4020
|
+
* // constraint name
|
|
4021
|
+
* db.table.create(data).onConfict({ constraint: 'unique_index_name' }).merge();
|
|
3891
4022
|
*
|
|
3892
|
-
*
|
|
3893
|
-
*
|
|
3894
|
-
*
|
|
4023
|
+
* // raw SQL expression:
|
|
4024
|
+
* db.table
|
|
4025
|
+
* .create(data)
|
|
4026
|
+
* .onConfict(db.table.sql`(email) where condition`)
|
|
4027
|
+
* .merge();
|
|
4028
|
+
* ```
|
|
3895
4029
|
*
|
|
3896
4030
|
* You can use the db.table.sql function in onConflict.
|
|
3897
4031
|
* It can be useful to specify a condition when you have a partial index:
|
|
@@ -3908,26 +4042,15 @@ declare class Create {
|
|
|
3908
4042
|
* .ignore();
|
|
3909
4043
|
* ```
|
|
3910
4044
|
*
|
|
3911
|
-
* :::
|
|
3912
|
-
*
|
|
3913
|
-
* See the documentation on the .ignore() and .merge() methods for more details.
|
|
3914
|
-
*
|
|
3915
4045
|
* @param arg - optionally provide an array of columns
|
|
3916
4046
|
*/
|
|
3917
|
-
onConflict<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg
|
|
3918
|
-
}
|
|
3919
|
-
declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflictArg<T> | undefined> {
|
|
3920
|
-
private query;
|
|
3921
|
-
private onConflict;
|
|
3922
|
-
constructor(query: T, onConflict: Arg);
|
|
4047
|
+
onConflict<T extends CreateSelf, Arg extends OnConflictArg<T>>(this: T, arg: Arg): OnConflictQueryBuilder<T, Arg>;
|
|
3923
4048
|
/**
|
|
3924
|
-
*
|
|
4049
|
+
* Use `onConflictIgnore` to suppress unique constraint violation error when creating a record.
|
|
3925
4050
|
*
|
|
3926
|
-
* `
|
|
4051
|
+
* Adds `ON CONFLICT (columns) DO NOTHING` clause to the insert statement, columns are optional.
|
|
3927
4052
|
*
|
|
3928
|
-
*
|
|
3929
|
-
*
|
|
3930
|
-
* It produces `ON CONFLICT DO NOTHING` when no `onConflict` argument provided.
|
|
4053
|
+
* Can also accept a constraint name.
|
|
3931
4054
|
*
|
|
3932
4055
|
* ```ts
|
|
3933
4056
|
* db.table
|
|
@@ -3935,53 +4058,55 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
|
|
|
3935
4058
|
* email: 'ignore@example.com',
|
|
3936
4059
|
* name: 'John Doe',
|
|
3937
4060
|
* })
|
|
3938
|
-
*
|
|
3939
|
-
* .
|
|
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' });
|
|
3940
4067
|
* ```
|
|
3941
4068
|
*
|
|
3942
|
-
*
|
|
3943
|
-
* 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.
|
|
3944
|
-
*
|
|
3945
|
-
* `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.
|
|
3946
4070
|
*
|
|
3947
4071
|
* ```ts
|
|
3948
4072
|
* const maybeRecord: RecordType | undefined = await db.table
|
|
3949
4073
|
* .create(data)
|
|
3950
|
-
* .
|
|
3951
|
-
* .ignore();
|
|
4074
|
+
* .onConflictIgnore();
|
|
3952
4075
|
*
|
|
3953
4076
|
* const maybeId: number | undefined = await db.table
|
|
3954
4077
|
* .get('id')
|
|
3955
4078
|
* .create(data)
|
|
3956
|
-
* .
|
|
3957
|
-
* .ignore();
|
|
4079
|
+
* .onConflictIgnore();
|
|
3958
4080
|
* ```
|
|
3959
4081
|
*
|
|
3960
|
-
* When creating
|
|
4082
|
+
* When creating multiple records, only created records will be returned. If no records were created, array will be empty:
|
|
3961
4083
|
*
|
|
3962
4084
|
* ```ts
|
|
3963
4085
|
* // array can be empty
|
|
3964
|
-
* const arr = await db.table.createMany([data, data, data]).
|
|
4086
|
+
* const arr = await db.table.createMany([data, data, data]).onConflictIgnore();
|
|
3965
4087
|
* ```
|
|
3966
4088
|
*/
|
|
3967
|
-
|
|
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);
|
|
3968
4095
|
/**
|
|
3969
|
-
* Available only after
|
|
3970
|
-
*
|
|
3971
|
-
* Modifies a create query, to turn it into an 'upsert' operation.
|
|
4096
|
+
* Available only after [onConflict](#onconflict).
|
|
3972
4097
|
*
|
|
3973
4098
|
* Adds an `ON CONFLICT (columns) DO UPDATE` clause to the insert statement.
|
|
3974
4099
|
*
|
|
3975
|
-
* When no `onConflict` argument provided,
|
|
3976
|
-
* it will automatically collect all table columns that have unique index and use them as a conflict target.
|
|
3977
|
-
*
|
|
3978
4100
|
* ```ts
|
|
3979
4101
|
* db.table
|
|
3980
4102
|
* .create({
|
|
3981
4103
|
* email: 'ignore@example.com',
|
|
3982
4104
|
* name: 'John Doe',
|
|
3983
4105
|
* })
|
|
4106
|
+
* // for a specific column:
|
|
3984
4107
|
* .onConflict('email')
|
|
4108
|
+
* // or, for a specific constraint:
|
|
4109
|
+
* .onConflict({ constraint: 'unique_constraint_name' })
|
|
3985
4110
|
* .merge();
|
|
3986
4111
|
* ```
|
|
3987
4112
|
*
|
|
@@ -4012,15 +4137,15 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
|
|
|
4012
4137
|
* updatedAt: timestamp,
|
|
4013
4138
|
* })
|
|
4014
4139
|
* .onConflict('email')
|
|
4015
|
-
* //
|
|
4140
|
+
* // update only a single column
|
|
4016
4141
|
* .merge('email')
|
|
4017
|
-
* //
|
|
4142
|
+
* // or, update multiple columns
|
|
4018
4143
|
* .merge(['email', 'name', 'updatedAt']);
|
|
4019
4144
|
* ```
|
|
4020
4145
|
*
|
|
4021
|
-
* It
|
|
4146
|
+
* It's possible to specify data to update separately from the data to create.
|
|
4022
4147
|
* This is useful if you want to make an update with different data than in creating.
|
|
4023
|
-
* For example,
|
|
4148
|
+
* For example, changing a value if the row already exists:
|
|
4024
4149
|
*
|
|
4025
4150
|
* ```ts
|
|
4026
4151
|
* const timestamp = Date.now();
|
|
@@ -4038,7 +4163,7 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
|
|
|
4038
4163
|
* });
|
|
4039
4164
|
* ```
|
|
4040
4165
|
*
|
|
4041
|
-
*
|
|
4166
|
+
* You can use `where` to update only the matching rows:
|
|
4042
4167
|
*
|
|
4043
4168
|
* ```ts
|
|
4044
4169
|
* const timestamp = Date.now();
|
|
@@ -4058,7 +4183,7 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
|
|
|
4058
4183
|
* .where({ updatedAt: { lt: timestamp } });
|
|
4059
4184
|
* ```
|
|
4060
4185
|
*
|
|
4061
|
-
* `merge`
|
|
4186
|
+
* `merge` can take a raw SQL expression:
|
|
4062
4187
|
*
|
|
4063
4188
|
* ```ts
|
|
4064
4189
|
* db.table
|
|
@@ -4156,7 +4281,7 @@ type FromResult<T extends FromQuerySelf, Arg extends FromArg<T>> = Arg extends s
|
|
|
4156
4281
|
column: Arg['result'][K];
|
|
4157
4282
|
} : never;
|
|
4158
4283
|
} : T['meta'][K];
|
|
4159
|
-
} : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends 'then' ? QueryThen<GetQueryResult<T, Arg['result']>> :
|
|
4284
|
+
} : K extends 'result' ? Arg['result'] : K extends 'shape' ? Arg['result'] : K extends 'then' ? QueryThen<GetQueryResult<T, Arg['result']>> : T[K];
|
|
4160
4285
|
} : T;
|
|
4161
4286
|
declare function queryFrom<T extends FromQuerySelf, Arg extends FromArg<T>>(self: T, arg: Arg, options?: FromArgOptions): FromResult<T, Arg>;
|
|
4162
4287
|
declare function queryFromSql<T extends FromQuerySelf>(self: T, args: SQLQueryArgs): T;
|
|
@@ -4630,7 +4755,7 @@ declare class QueryLog {
|
|
|
4630
4755
|
type MergeQuery<T extends PickQueryMetaResultReturnTypeWithDataWindows, Q extends PickQueryMetaResultReturnTypeWithDataWindows> = {
|
|
4631
4756
|
[K in keyof T]: K extends 'meta' ? {
|
|
4632
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];
|
|
4633
|
-
} : 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 '
|
|
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];
|
|
4634
4759
|
};
|
|
4635
4760
|
type MergeQueryResult<T extends PickQueryMetaResult, Q extends PickQueryMetaResult> = T['meta']['hasSelect'] extends true ? Q['meta']['hasSelect'] extends true ? {
|
|
4636
4761
|
[K in keyof T['result'] | keyof Q['result']]: K extends keyof Q['result'] ? Q['result'][K] : T['result'][K];
|
|
@@ -4639,7 +4764,9 @@ declare class MergeQueryMethods {
|
|
|
4639
4764
|
merge<T extends Query, Q extends Query>(this: T, q: Q): MergeQuery<T, Q>;
|
|
4640
4765
|
}
|
|
4641
4766
|
|
|
4642
|
-
declare const queryMethodByReturnType:
|
|
4767
|
+
declare const queryMethodByReturnType: {
|
|
4768
|
+
[K in QueryReturnType]: 'query' | 'arrays';
|
|
4769
|
+
};
|
|
4643
4770
|
type Resolve = (result: any) => any;
|
|
4644
4771
|
type Reject = (error: any) => any;
|
|
4645
4772
|
declare class Then {
|
|
@@ -4675,10 +4802,6 @@ type SelectResult<T extends SelectSelf, Columns extends PropertyKey[]> = {
|
|
|
4675
4802
|
[K in Columns[number] | keyof T['shape'] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
|
|
4676
4803
|
} : {
|
|
4677
4804
|
[K in Columns[number] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
|
|
4678
|
-
}) & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, ('*' extends Columns[number] ? {
|
|
4679
|
-
[K in Columns[number] | keyof T['shape'] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
|
|
4680
|
-
} : {
|
|
4681
|
-
[K in Columns[number] as T['meta']['selectable'][K]['as']]: T['meta']['selectable'][K]['column'];
|
|
4682
4805
|
}) & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : T[K];
|
|
4683
4806
|
} & QueryMetaHasSelect;
|
|
4684
4807
|
type SelectResultObj<T extends SelectSelf, Obj> = {
|
|
@@ -4688,8 +4811,6 @@ type SelectResultObj<T extends SelectSelf, Obj> = {
|
|
|
4688
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;
|
|
4689
4812
|
} : K extends 'then' ? QueryThen<GetQueryResult<T, {
|
|
4690
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;
|
|
4691
|
-
}>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, {
|
|
4692
|
-
[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;
|
|
4693
4814
|
}>> : T[K];
|
|
4694
4815
|
} & QueryMetaHasSelect;
|
|
4695
4816
|
type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey[], Obj> = {
|
|
@@ -4700,8 +4821,6 @@ type SelectResultColumnsAndObj<T extends SelectSelf, Columns extends PropertyKey
|
|
|
4700
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;
|
|
4701
4822
|
} & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown) : K extends 'then' ? QueryThen<GetQueryResult<T, {
|
|
4702
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;
|
|
4703
|
-
} & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : K extends 'catch' ? QueryCatch<GetQueryResult<T, {
|
|
4704
|
-
[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;
|
|
4705
4824
|
} & (T['meta']['hasSelect'] extends true ? Omit<T['result'], Columns[number]> : unknown)>> : T[K];
|
|
4706
4825
|
} & QueryMetaHasSelect;
|
|
4707
4826
|
type SelectAsSelectable<Arg> = {
|
|
@@ -4884,7 +5003,9 @@ declare class With {
|
|
|
4884
5003
|
|
|
4885
5004
|
type UnionArg<T extends PickQueryResult> = {
|
|
4886
5005
|
result: {
|
|
4887
|
-
[K in keyof T['result']]:
|
|
5006
|
+
[K in keyof T['result']]: {
|
|
5007
|
+
dataType: T['result'][K]['dataType'];
|
|
5008
|
+
};
|
|
4888
5009
|
};
|
|
4889
5010
|
} | Expression;
|
|
4890
5011
|
declare class Union {
|
|
@@ -4943,7 +5064,9 @@ declare class Union {
|
|
|
4943
5064
|
exceptAll<T extends PickQueryResult>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
4944
5065
|
}
|
|
4945
5066
|
|
|
4946
|
-
type UpdateSelf =
|
|
5067
|
+
type UpdateSelf = {
|
|
5068
|
+
[K in 'meta' | 'inputType' | 'relations' | 'shape' | 'result' | 'returnType' | keyof JsonModifiers]: Query[K];
|
|
5069
|
+
};
|
|
4947
5070
|
type UpdateData<T extends UpdateSelf> = {
|
|
4948
5071
|
[K in keyof T['inputType']]?: UpdateColumn<T, K>;
|
|
4949
5072
|
} & {
|
|
@@ -4969,10 +5092,14 @@ type UpdateResult<T extends UpdateSelf> = T['meta']['hasSelect'] extends true ?
|
|
|
4969
5092
|
type ChangeCountArg<T extends PickQueryShape> = keyof T['shape'] | {
|
|
4970
5093
|
[K in keyof T['shape']]?: number;
|
|
4971
5094
|
};
|
|
4972
|
-
|
|
5095
|
+
interface UpdateCtx {
|
|
4973
5096
|
queries?: ((queryResult: QueryResult) => Promise<void>)[];
|
|
4974
|
-
|
|
4975
|
-
}
|
|
5097
|
+
collect?: UpdateCtxCollect;
|
|
5098
|
+
}
|
|
5099
|
+
interface UpdateCtxCollect {
|
|
5100
|
+
keys: string[];
|
|
5101
|
+
data: RecordUnknown;
|
|
5102
|
+
}
|
|
4976
5103
|
declare const _queryChangeCounter: <T extends UpdateSelf>(self: T, op: string, data: ChangeCountArg<T>) => never;
|
|
4977
5104
|
declare const _queryUpdate: <T extends UpdateSelf>(query: T, arg: UpdateArg<T>) => UpdateResult<T>;
|
|
4978
5105
|
declare const _queryUpdateRaw: <T extends UpdateSelf>(q: T, sql: Expression) => UpdateResult<T>;
|
|
@@ -5727,26 +5854,6 @@ declare class QueryUpsertOrCreate {
|
|
|
5727
5854
|
orCreate<T extends UpsertThis>(this: T, data: OrCreateArg<T>): UpsertResult<T>;
|
|
5728
5855
|
}
|
|
5729
5856
|
|
|
5730
|
-
declare const templateLiteralToSQL: (template: TemplateLiteralArgs, ctx: ToSQLCtx, quotedAs?: string) => string;
|
|
5731
|
-
declare class RawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>> extends RawSQLBase<T, ColumnTypes> {
|
|
5732
|
-
columnTypes: ColumnTypes;
|
|
5733
|
-
constructor(sql: string | TemplateLiteralArgs, values?: RawSQLValues, type?: T);
|
|
5734
|
-
makeSQL(ctx: ToSQLCtx, quotedAs?: string): string;
|
|
5735
|
-
}
|
|
5736
|
-
interface DynamicRawSQL<T extends QueryColumn> extends Expression<T>, ExpressionTypeMethod {
|
|
5737
|
-
}
|
|
5738
|
-
declare class DynamicRawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>> extends Expression<T> {
|
|
5739
|
-
fn: DynamicSQLArg;
|
|
5740
|
-
_type: T;
|
|
5741
|
-
columnTypes: ColumnTypes;
|
|
5742
|
-
constructor(fn: DynamicSQLArg);
|
|
5743
|
-
makeSQL(ctx: ToSQLCtx, quotedAs?: string): string;
|
|
5744
|
-
}
|
|
5745
|
-
declare function raw<T = unknown>(...args: StaticSQLArgs): RawSQL<QueryColumn<T>>;
|
|
5746
|
-
declare function raw<T = unknown>(...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>>;
|
|
5747
|
-
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>>>>[];
|
|
5748
|
-
declare function sqlQueryArgsToExpression(args: SQLQueryArgs): RawSQL<QueryColumn>;
|
|
5749
|
-
|
|
5750
5857
|
declare abstract class RawSqlMethods<ColumnTypes> {
|
|
5751
5858
|
/**
|
|
5752
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`.
|
|
@@ -5905,11 +6012,11 @@ declare abstract class RawSqlMethods<ColumnTypes> {
|
|
|
5905
6012
|
}, ...args: [DynamicSQLArg]): DynamicRawSQL<QueryColumn<T>, ColumnTypes>;
|
|
5906
6013
|
}
|
|
5907
6014
|
|
|
5908
|
-
type QueryTransformFn<T extends Query> = (input: T['
|
|
6015
|
+
type QueryTransformFn<T extends Query> = (input: T['then'] extends QueryThen<infer Data> ? Data : never) => unknown;
|
|
5909
6016
|
type QueryTransform<T extends QueryBase, Data> = {
|
|
5910
6017
|
[K in keyof T]: K extends 'returnType' ? 'valueOrThrow' : K extends 'result' ? {
|
|
5911
6018
|
value: QueryColumn<Data>;
|
|
5912
|
-
} : K extends 'then' ? QueryThen<Data> :
|
|
6019
|
+
} : K extends 'then' ? QueryThen<Data> : T[K];
|
|
5913
6020
|
};
|
|
5914
6021
|
declare class TransformMethods {
|
|
5915
6022
|
/**
|
|
@@ -5974,7 +6081,9 @@ interface WindowArgDeclaration<T extends OrderArgSelf = OrderArgSelf> {
|
|
|
5974
6081
|
order?: OrderArg<T>;
|
|
5975
6082
|
}
|
|
5976
6083
|
type WindowResult<T, W extends RecordUnknown> = T & {
|
|
5977
|
-
windows:
|
|
6084
|
+
windows: {
|
|
6085
|
+
[K in keyof W]: true;
|
|
6086
|
+
};
|
|
5978
6087
|
};
|
|
5979
6088
|
type OrderArgSelf = PickQueryMetaResult;
|
|
5980
6089
|
type OrderArg<T extends OrderArgSelf> = OrderArgKey<T> | OrderArgTsQuery<T> | {
|
|
@@ -5988,7 +6097,7 @@ type OrderArgs<T extends OrderArgSelf> = OrderArg<T>[];
|
|
|
5988
6097
|
type GroupArg<T extends PickQueryResult> = {
|
|
5989
6098
|
[K in keyof T['result']]: T['result'][K]['dataType'] extends 'array' | 'object' ? never : K;
|
|
5990
6099
|
}[keyof T['result']] | Expression;
|
|
5991
|
-
type FindArg<T extends PickQueryShapeSinglePrimaryKey> = T['
|
|
6100
|
+
type FindArg<T extends PickQueryShapeSinglePrimaryKey> = T['internal']['singlePrimaryKey'] | Expression;
|
|
5992
6101
|
type QueryHelper<T extends PickQueryMetaShape, Args extends unknown[], Result> = {
|
|
5993
6102
|
<Q extends {
|
|
5994
6103
|
returnType: QueryReturnType;
|
|
@@ -6128,20 +6237,11 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6128
6237
|
*/
|
|
6129
6238
|
distinct<T extends PickQueryMeta>(this: T, ...columns: SelectableOrExpression<T>[]): T;
|
|
6130
6239
|
/**
|
|
6131
|
-
*
|
|
6132
|
-
*
|
|
6133
|
-
*
|
|
6134
|
-
* Finds a record by id, throws {@link NotFoundError} if not found:
|
|
6135
|
-
*
|
|
6136
|
-
* ```ts
|
|
6137
|
-
* await db.table.find(1);
|
|
6138
|
-
* ```
|
|
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.
|
|
6139
6242
|
*
|
|
6140
6243
|
* ```ts
|
|
6141
|
-
* await db.
|
|
6142
|
-
* age = ${age} AND
|
|
6143
|
-
* name = ${name}
|
|
6144
|
-
* `;
|
|
6244
|
+
* const result: TableType = await db.table.find(1);
|
|
6145
6245
|
* ```
|
|
6146
6246
|
*
|
|
6147
6247
|
* @param value - primary key value to find by
|
|
@@ -6159,10 +6259,10 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6159
6259
|
*
|
|
6160
6260
|
* @param args - SQL expression
|
|
6161
6261
|
*/
|
|
6162
|
-
findBySql<T extends
|
|
6262
|
+
findBySql<T extends PickQueryResult>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOne<WhereResult<T>>;
|
|
6163
6263
|
/**
|
|
6164
|
-
*
|
|
6165
|
-
*
|
|
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.
|
|
6166
6266
|
*
|
|
6167
6267
|
* ```ts
|
|
6168
6268
|
* const result: TableType | undefined = await db.table.find(123);
|
|
@@ -6184,33 +6284,35 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6184
6284
|
*
|
|
6185
6285
|
* @param args - SQL expression
|
|
6186
6286
|
*/
|
|
6187
|
-
findBySqlOptional<T extends
|
|
6287
|
+
findBySqlOptional<T extends PickQueryResult>(this: T, ...args: SQLQueryArgs): SetQueryReturnsOneOptional<WhereResult<T>>;
|
|
6188
6288
|
/**
|
|
6189
|
-
*
|
|
6190
|
-
*
|
|
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.
|
|
6191
6294
|
*
|
|
6192
6295
|
* ```ts
|
|
6193
|
-
*
|
|
6194
|
-
* // is equivalent to:
|
|
6195
|
-
* db.table.where({ key: 'value' }).take()
|
|
6296
|
+
* await db.table.findBy({ key: 'value' });
|
|
6196
6297
|
* ```
|
|
6197
6298
|
*
|
|
6198
|
-
* @param
|
|
6299
|
+
* @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
|
|
6199
6300
|
*/
|
|
6200
|
-
findBy<T extends
|
|
6301
|
+
findBy<T extends PickQueryResultUniqueColumns>(this: T, uniqueColumnValues: T['internal']['uniqueColumns']): SetQueryReturnsOne<WhereResult<T>>;
|
|
6201
6302
|
/**
|
|
6202
|
-
*
|
|
6203
|
-
*
|
|
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.
|
|
6204
6308
|
*
|
|
6205
6309
|
* ```ts
|
|
6206
|
-
*
|
|
6207
|
-
* key: 'value',
|
|
6208
|
-
* });
|
|
6310
|
+
* await db.table.findByOptional({ key: 'value' });
|
|
6209
6311
|
* ```
|
|
6210
6312
|
*
|
|
6211
|
-
* @param
|
|
6313
|
+
* @param uniqueColumnValues - is derived from primary keys and unique indexes in the table
|
|
6212
6314
|
*/
|
|
6213
|
-
findByOptional<T extends
|
|
6315
|
+
findByOptional<T extends PickQueryResultUniqueColumns>(this: T, uniqueColumnValues: T['internal']['uniqueColumns']): SetQueryReturnsOneOptional<WhereResult<T>>;
|
|
6214
6316
|
/**
|
|
6215
6317
|
* Specifies the schema to be used as a prefix of a table name.
|
|
6216
6318
|
*
|
|
@@ -6331,9 +6433,9 @@ declare class QueryMethods<ColumnTypes> {
|
|
|
6331
6433
|
* Order by raw SQL expression.
|
|
6332
6434
|
*
|
|
6333
6435
|
* ```ts
|
|
6334
|
-
* db.table.
|
|
6436
|
+
* db.table.orderSql`raw sql`;
|
|
6335
6437
|
* // or
|
|
6336
|
-
* db.table.
|
|
6438
|
+
* db.table.orderSql(db.table.sql`raw sql`);
|
|
6337
6439
|
* ```
|
|
6338
6440
|
*
|
|
6339
6441
|
* @param args - SQL expression
|
|
@@ -6519,6 +6621,25 @@ declare function queryWrap<T extends PickQueryTableMetaResult, Q extends WrapQue
|
|
|
6519
6621
|
*/
|
|
6520
6622
|
declare function cloneQueryBaseUnscoped(query: Query): Query;
|
|
6521
6623
|
|
|
6624
|
+
interface DbExtension {
|
|
6625
|
+
name: string;
|
|
6626
|
+
version?: string;
|
|
6627
|
+
}
|
|
6628
|
+
type DbDomainArg<ColumnTypes> = (columnTypes: ColumnTypes) => ColumnType;
|
|
6629
|
+
type DbDomainArgRecord = {
|
|
6630
|
+
[K: string]: DbDomainArg<any>;
|
|
6631
|
+
};
|
|
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;
|
|
6638
|
+
extensions?: DbExtension[];
|
|
6639
|
+
domains?: DbDomainArgRecord;
|
|
6640
|
+
tableData: TableData;
|
|
6641
|
+
primaryKeys?: string[];
|
|
6642
|
+
}
|
|
6522
6643
|
type SelectableFromShape<Shape extends QueryColumns, Table extends string | undefined> = {
|
|
6523
6644
|
[K in keyof Shape]: {
|
|
6524
6645
|
as: K;
|
|
@@ -6542,12 +6663,10 @@ interface Query extends QueryBase, QueryMethods<unknown> {
|
|
|
6542
6663
|
queryBuilder: Db;
|
|
6543
6664
|
columnTypes: unknown;
|
|
6544
6665
|
shape: QueryColumns;
|
|
6545
|
-
singlePrimaryKey: string;
|
|
6546
|
-
primaryKeys: string[];
|
|
6547
6666
|
inputType: RecordUnknown;
|
|
6548
6667
|
q: QueryData;
|
|
6549
6668
|
then: QueryThen<unknown>;
|
|
6550
|
-
catch: QueryCatch
|
|
6669
|
+
catch: QueryCatch;
|
|
6551
6670
|
windows: EmptyObject;
|
|
6552
6671
|
defaultSelectColumns: string[];
|
|
6553
6672
|
relations: RelationsBase;
|
|
@@ -6606,7 +6725,9 @@ interface PickQueryQAndInternal extends PickQueryQ, PickQueryInternal {
|
|
|
6606
6725
|
interface PickQueryQAndBaseQuery extends PickQueryQ, PickQueryBaseQuery {
|
|
6607
6726
|
}
|
|
6608
6727
|
interface PickQuerySinglePrimaryKey {
|
|
6609
|
-
|
|
6728
|
+
internal: {
|
|
6729
|
+
singlePrimaryKey: unknown;
|
|
6730
|
+
};
|
|
6610
6731
|
}
|
|
6611
6732
|
interface PickQueryShapeSinglePrimaryKey extends PickQueryShape, PickQuerySinglePrimaryKey {
|
|
6612
6733
|
}
|
|
@@ -6619,14 +6740,24 @@ type SelectableOrExpressionOfType<T extends PickQueryMeta, C extends PickType> =
|
|
|
6619
6740
|
interface QueryWithTable extends Query {
|
|
6620
6741
|
table: string;
|
|
6621
6742
|
}
|
|
6622
|
-
declare const queryTypeWithLimitOne:
|
|
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
|
+
};
|
|
6623
6754
|
declare const isQueryReturnsAll: (q: Query) => boolean;
|
|
6624
6755
|
type QueryReturnsAll<T extends QueryReturnType> = (QueryReturnType extends T ? 'all' : T) extends 'all' ? true : false;
|
|
6625
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;
|
|
6626
6757
|
type AddQuerySelect<T extends PickQueryMetaResultReturnType, Result extends QueryColumns> = {
|
|
6627
6758
|
[K in keyof T]: K extends 'result' ? {
|
|
6628
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;
|
|
6629
|
-
} : K extends 'then' ? QueryThen<GetQueryResult<T, Result>> :
|
|
6760
|
+
} : K extends 'then' ? QueryThen<GetQueryResult<T, Result>> : T[K];
|
|
6630
6761
|
} & QueryMetaHasSelect;
|
|
6631
6762
|
interface QueryMetaHasSelect {
|
|
6632
6763
|
meta: {
|
|
@@ -6634,71 +6765,71 @@ interface QueryMetaHasSelect {
|
|
|
6634
6765
|
};
|
|
6635
6766
|
}
|
|
6636
6767
|
type SetQueryReturnsAll<T extends PickQueryResult> = {
|
|
6637
|
-
[K in keyof T]: K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> :
|
|
6768
|
+
[K in keyof T]: K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : T[K];
|
|
6638
6769
|
} & QueryMetaHasWhere;
|
|
6639
6770
|
type SetQueryReturnsAllKind<T extends PickQueryMetaResult, Kind extends string> = {
|
|
6640
6771
|
[K in keyof T]: K extends 'meta' ? {
|
|
6641
6772
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6642
|
-
} : K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> :
|
|
6773
|
+
} : K extends 'returnType' ? 'all' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[]> : T[K];
|
|
6643
6774
|
} & QueryMetaHasWhere;
|
|
6644
6775
|
type SetQueryReturnsOneOptional<T extends PickQueryResult> = {
|
|
6645
|
-
[K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']> | undefined> :
|
|
6776
|
+
[K in keyof T]: K extends 'returnType' ? 'one' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']> | undefined> : T[K];
|
|
6646
6777
|
};
|
|
6647
6778
|
type SetQueryReturnsOne<T extends PickQueryResult> = {
|
|
6648
|
-
[K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> :
|
|
6779
|
+
[K in keyof T]: K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : T[K];
|
|
6649
6780
|
};
|
|
6650
6781
|
type SetQueryReturnsOneKind<T extends PickQueryMetaResult, Kind extends string> = {
|
|
6651
6782
|
[K in keyof T]: K extends 'meta' ? {
|
|
6652
6783
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6653
|
-
} : K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> :
|
|
6784
|
+
} : K extends 'returnType' ? 'oneOrThrow' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>> : T[K];
|
|
6654
6785
|
};
|
|
6655
6786
|
type SetQueryReturnsRows<T extends PickQueryResult> = {
|
|
6656
|
-
[K in keyof T]: K extends 'returnType' ? 'rows' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[keyof T['result']][][]> :
|
|
6787
|
+
[K in keyof T]: K extends 'returnType' ? 'rows' : K extends 'then' ? QueryThen<ColumnShapeOutput<T['result']>[keyof T['result']][][]> : T[K];
|
|
6657
6788
|
};
|
|
6658
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>;
|
|
6659
6790
|
type SetQueryReturnsPluckColumn<T, C extends QueryColumn> = {
|
|
6660
6791
|
[K in keyof T]: K extends 'result' ? {
|
|
6661
6792
|
pluck: C;
|
|
6662
|
-
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<C['outputType'][]> :
|
|
6793
|
+
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<C['outputType'][]> : T[K];
|
|
6663
6794
|
} & QueryMetaHasSelect;
|
|
6664
6795
|
type SetQueryReturnsPluckColumnKind<T extends PickQueryMetaResult, Kind extends string> = {
|
|
6665
6796
|
[K in keyof T]: K extends 'meta' ? {
|
|
6666
6797
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6667
6798
|
} : K extends 'result' ? {
|
|
6668
6799
|
pluck: T['result']['value'];
|
|
6669
|
-
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['result']['value']['outputType'][]> :
|
|
6800
|
+
} : K extends 'returnType' ? 'pluck' : K extends 'then' ? QueryThen<T['result']['value']['outputType'][]> : T[K];
|
|
6670
6801
|
} & QueryMetaHasSelect;
|
|
6671
6802
|
type SetQueryReturnsValueOrThrow<T extends PickQueryMeta, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOrThrow<T, T['meta']['selectable'][Arg]['column']> & T['meta']['selectable'][Arg]['column']['operators'];
|
|
6672
6803
|
type SetQueryReturnsValueOptional<T extends PickQueryMeta, Arg extends GetStringArg<T>> = SetQueryReturnsColumnOptional<T, T['meta']['selectable'][Arg]['column']> & T['meta']['selectable'][Arg]['column']['operators'];
|
|
6673
6804
|
type SetQueryReturnsColumnOrThrow<T, Column extends PickOutputType> = {
|
|
6674
6805
|
[K in keyof T]: K extends 'result' ? {
|
|
6675
6806
|
value: Column;
|
|
6676
|
-
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['outputType']> :
|
|
6807
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['outputType']> : T[K];
|
|
6677
6808
|
} & QueryMetaHasSelect;
|
|
6678
6809
|
type SetQueryReturnsColumnOptional<T, Column extends PickOutputType> = {
|
|
6679
6810
|
[K in keyof T]: K extends 'result' ? {
|
|
6680
6811
|
value: Column;
|
|
6681
|
-
} : K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<Column['outputType'] | undefined> :
|
|
6812
|
+
} : K extends 'returnType' ? 'value' : K extends 'then' ? QueryThen<Column['outputType'] | undefined> : T[K];
|
|
6682
6813
|
} & QueryMetaHasSelect;
|
|
6683
6814
|
type SetQueryReturnsColumnKind<T extends PickQueryMetaResult, Kind extends string> = {
|
|
6684
6815
|
[K in keyof T]: K extends 'meta' ? {
|
|
6685
6816
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6686
6817
|
} : K extends 'result' ? {
|
|
6687
6818
|
value: T['result']['pluck'];
|
|
6688
|
-
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['pluck']['outputType']> :
|
|
6819
|
+
} : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<T['result']['pluck']['outputType']> : T[K];
|
|
6689
6820
|
} & QueryMetaHasSelect;
|
|
6690
6821
|
type SetQueryReturnsRowCount<T extends PickQueryMetaResult, Kind extends string> = {
|
|
6691
6822
|
[K in keyof T]: K extends 'meta' ? {
|
|
6692
6823
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6693
|
-
} : K extends 'returnType' ? 'rowCount' : K extends 'then' ? QueryThen<number> :
|
|
6824
|
+
} : K extends 'returnType' ? 'rowCount' : K extends 'then' ? QueryThen<number> : T[K];
|
|
6694
6825
|
};
|
|
6695
6826
|
type SetQueryReturnsVoid<T> = {
|
|
6696
|
-
[K in keyof T]: K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> :
|
|
6827
|
+
[K in keyof T]: K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : T[K];
|
|
6697
6828
|
};
|
|
6698
6829
|
type SetQueryReturnsVoidKind<T extends PickQueryMeta, Kind extends string> = {
|
|
6699
6830
|
[K in keyof T]: K extends 'meta' ? {
|
|
6700
6831
|
[K in keyof T['meta']]: K extends 'kind' ? Kind : T['meta'][K];
|
|
6701
|
-
} : K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> :
|
|
6832
|
+
} : K extends 'returnType' ? 'void' : K extends 'then' ? QueryThen<void> : T[K];
|
|
6702
6833
|
};
|
|
6703
6834
|
type SetQueryKind<T extends PickQueryMeta, Kind extends string> = {
|
|
6704
6835
|
[K in keyof T]: K extends 'meta' ? {
|
|
@@ -6728,75 +6859,14 @@ interface ColumnData extends ColumnDataBase {
|
|
|
6728
6859
|
numericScale?: number;
|
|
6729
6860
|
dateTimePrecision?: number;
|
|
6730
6861
|
validationDefault?: unknown;
|
|
6731
|
-
indexes?:
|
|
6862
|
+
indexes?: TableData.ColumnIndex[];
|
|
6732
6863
|
comment?: string;
|
|
6733
6864
|
collate?: string;
|
|
6734
6865
|
compression?: string;
|
|
6735
|
-
foreignKeys?:
|
|
6866
|
+
foreignKeys?: TableData.ColumnReferences[];
|
|
6736
6867
|
identity?: TableData.Identity;
|
|
6737
6868
|
generated?: RawSQLBase;
|
|
6738
6869
|
}
|
|
6739
|
-
/**
|
|
6740
|
-
* - MATCH FULL will not allow one column of a multicolumn foreign key to be null unless all foreign key columns are null;
|
|
6741
|
-
* if they are all null, the row is not required to have a match in the referenced table.
|
|
6742
|
-
* - 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.
|
|
6743
|
-
* - MATCH PARTIAL - PG docs say it's not implemented.
|
|
6744
|
-
*/
|
|
6745
|
-
type ForeignKeyMatch = 'FULL' | 'PARTIAL' | 'SIMPLE';
|
|
6746
|
-
/**
|
|
6747
|
-
* - 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.
|
|
6748
|
-
* - 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.
|
|
6749
|
-
* - 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.
|
|
6750
|
-
* - 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.
|
|
6751
|
-
* - 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.)
|
|
6752
|
-
*/
|
|
6753
|
-
type ForeignKeyAction = 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
|
|
6754
|
-
type ForeignKey<Table extends string, Columns extends string[]> = ({
|
|
6755
|
-
fn(): new () => {
|
|
6756
|
-
table: Table;
|
|
6757
|
-
columns: ColumnsShapeBase;
|
|
6758
|
-
};
|
|
6759
|
-
} | {
|
|
6760
|
-
table: Table;
|
|
6761
|
-
}) & {
|
|
6762
|
-
columns: Columns;
|
|
6763
|
-
} & ForeignKeyOptions;
|
|
6764
|
-
type DropMode = 'CASCADE' | 'RESTRICT';
|
|
6765
|
-
interface ForeignKeyOptions {
|
|
6766
|
-
name?: string;
|
|
6767
|
-
match?: ForeignKeyMatch;
|
|
6768
|
-
onUpdate?: ForeignKeyAction;
|
|
6769
|
-
onDelete?: ForeignKeyAction;
|
|
6770
|
-
dropMode?: DropMode;
|
|
6771
|
-
}
|
|
6772
|
-
interface IndexColumnOptionsForColumn {
|
|
6773
|
-
collate?: string;
|
|
6774
|
-
opclass?: string;
|
|
6775
|
-
order?: string;
|
|
6776
|
-
weight?: SearchWeight;
|
|
6777
|
-
}
|
|
6778
|
-
type IndexColumnOptions = ({
|
|
6779
|
-
column: string;
|
|
6780
|
-
} | {
|
|
6781
|
-
expression: string;
|
|
6782
|
-
}) & IndexColumnOptionsForColumn;
|
|
6783
|
-
interface IndexOptions {
|
|
6784
|
-
name?: string;
|
|
6785
|
-
unique?: boolean;
|
|
6786
|
-
nullsNotDistinct?: boolean;
|
|
6787
|
-
using?: string;
|
|
6788
|
-
include?: MaybeArray<string>;
|
|
6789
|
-
with?: string;
|
|
6790
|
-
tablespace?: string;
|
|
6791
|
-
where?: string;
|
|
6792
|
-
dropMode?: 'CASCADE' | 'RESTRICT';
|
|
6793
|
-
language?: string | RawSQLBase;
|
|
6794
|
-
languageColumn?: string;
|
|
6795
|
-
tsVector?: boolean;
|
|
6796
|
-
}
|
|
6797
|
-
interface SingleColumnIndexOptionsForColumn extends IndexColumnOptionsForColumn, IndexOptions {
|
|
6798
|
-
}
|
|
6799
|
-
type SingleColumnIndexOptions = IndexColumnOptions & IndexOptions;
|
|
6800
6870
|
interface ColumnFromDbParams {
|
|
6801
6871
|
isNullable?: boolean;
|
|
6802
6872
|
default?: string;
|
|
@@ -6804,6 +6874,8 @@ interface ColumnFromDbParams {
|
|
|
6804
6874
|
numericPrecision?: number;
|
|
6805
6875
|
numericScale?: number;
|
|
6806
6876
|
dateTimePrecision?: number;
|
|
6877
|
+
compression?: string;
|
|
6878
|
+
collate?: string;
|
|
6807
6879
|
}
|
|
6808
6880
|
interface PickColumnData {
|
|
6809
6881
|
data: ColumnData;
|
|
@@ -6822,18 +6894,22 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6822
6894
|
* readonly table = 'table';
|
|
6823
6895
|
* columns = this.setColumns((t) => ({
|
|
6824
6896
|
* id: t.uuid().primaryKey(),
|
|
6897
|
+
* // database-level name can be passed:
|
|
6898
|
+
* id: t.uuid().primaryKey('primary_key_name'),
|
|
6825
6899
|
* }));
|
|
6826
6900
|
* }
|
|
6827
6901
|
*
|
|
6828
6902
|
* // primary key can be used by `find` later:
|
|
6829
6903
|
* db.table.find('97ba9e78-7510-415a-9c03-23d440aec443');
|
|
6830
6904
|
* ```
|
|
6905
|
+
*
|
|
6906
|
+
* @param name - to specify a constraint name
|
|
6831
6907
|
*/
|
|
6832
|
-
primaryKey<T extends PickColumnBaseData>(this: T): PrimaryKeyColumn<T>;
|
|
6908
|
+
primaryKey<T extends PickColumnBaseData, Name extends string>(this: T, name?: Name): PrimaryKeyColumn<T, Name>;
|
|
6833
6909
|
/**
|
|
6834
|
-
*
|
|
6910
|
+
* Defines a reference between different tables to enforce data integrity.
|
|
6835
6911
|
*
|
|
6836
|
-
* In
|
|
6912
|
+
* In [snakeCase](/guide/orm-and-query-builder.html#snakecase-option) mode, columns of both tables are translated to a snake_case.
|
|
6837
6913
|
*
|
|
6838
6914
|
* ```ts
|
|
6839
6915
|
* import { change } from '../dbScript';
|
|
@@ -6845,7 +6921,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6845
6921
|
* });
|
|
6846
6922
|
* ```
|
|
6847
6923
|
*
|
|
6848
|
-
* In the
|
|
6924
|
+
* In the migration it's different from OrchidORM table code where a callback with a table is expected:
|
|
6849
6925
|
*
|
|
6850
6926
|
* ```ts
|
|
6851
6927
|
* export class SomeTable extends BaseTable {
|
|
@@ -6854,13 +6930,6 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6854
6930
|
* otherTableId: t.integer().foreignKey(() => OtherTable, 'id'),
|
|
6855
6931
|
* }));
|
|
6856
6932
|
* }
|
|
6857
|
-
*
|
|
6858
|
-
* export class OtherTable extends BaseTable {
|
|
6859
|
-
* readonly table = 'otherTable';
|
|
6860
|
-
* columns = this.setColumns((t) => ({
|
|
6861
|
-
* id: t.identity().primaryKey(),
|
|
6862
|
-
* }));
|
|
6863
|
-
* }
|
|
6864
6933
|
* ```
|
|
6865
6934
|
*
|
|
6866
6935
|
* Optionally you can pass the third argument to `foreignKey` with options:
|
|
@@ -6891,7 +6960,7 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6891
6960
|
* change(async (db) => {
|
|
6892
6961
|
* await db.createTable('table', (t) => ({
|
|
6893
6962
|
* id: t.integer(),
|
|
6894
|
-
* name: t.string(),
|
|
6963
|
+
* name: t.string(), // string is varchar(255)
|
|
6895
6964
|
* ...t.foreignKey(
|
|
6896
6965
|
* ['id', 'name'],
|
|
6897
6966
|
* 'otherTable',
|
|
@@ -6911,18 +6980,63 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6911
6980
|
* @param column - column in the foreign table to connect with
|
|
6912
6981
|
* @param options - {@link ForeignKeyOptions}
|
|
6913
6982
|
*/
|
|
6914
|
-
foreignKey<T, Table extends ForeignKeyTable, Column extends ColumnNameOfTable<Table>>(this: T, fn: () => Table, column: Column, options?:
|
|
6915
|
-
|
|
6916
|
-
};
|
|
6917
|
-
foreignKey<T, Table extends string, Column extends string>(this: T, table: Table, column: Column, options?: ForeignKeyOptions): {
|
|
6918
|
-
[K in keyof T]: K extends 'foreignKeyData' ? ForeignKey<Table, [Column]> : T[K];
|
|
6919
|
-
};
|
|
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;
|
|
6920
6985
|
toSQL(): string;
|
|
6921
|
-
index<T extends PickColumnData>(this: T, options?: SingleColumnIndexOptionsForColumn): T;
|
|
6922
6986
|
/**
|
|
6923
|
-
*
|
|
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;
|
|
7036
|
+
/**
|
|
7037
|
+
* `searchIndex` is designed for [full text search](/guide/text-search).
|
|
6924
7038
|
*
|
|
6925
|
-
* It can accept the same options as a regular `index`, but it is `USING GIN` by default, and it is concatenating columns into a `tsvector
|
|
7039
|
+
* It can accept the same options as a regular `index`, but it is `USING GIN` by default, and it is concatenating columns into a `tsvector` database type.
|
|
6926
7040
|
*
|
|
6927
7041
|
* ```ts
|
|
6928
7042
|
* import { change } from '../dbScript';
|
|
@@ -6930,8 +7044,8 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6930
7044
|
* change(async (db) => {
|
|
6931
7045
|
* await db.createTable('table', (t) => ({
|
|
6932
7046
|
* id: t.identity().primaryKey(),
|
|
6933
|
-
* title: t.
|
|
6934
|
-
* body: t.
|
|
7047
|
+
* title: t.text(),
|
|
7048
|
+
* body: t.text(),
|
|
6935
7049
|
* ...t.searchIndex(['title', 'body']),
|
|
6936
7050
|
* }));
|
|
6937
7051
|
* });
|
|
@@ -6940,10 +7054,65 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6940
7054
|
* Produces the following index ('english' is a default language, see [full text search](/guide/text-search.html#language) for changing it):
|
|
6941
7055
|
*
|
|
6942
7056
|
* ```sql
|
|
6943
|
-
* CREATE INDEX "table_title_body_idx" ON "table" USING GIN (to_tsvector('english',
|
|
7057
|
+
* CREATE INDEX "table_title_body_idx" ON "table" USING GIN (to_tsvector('english', "title" || ' ' || "body"))
|
|
7058
|
+
* ```
|
|
7059
|
+
*
|
|
7060
|
+
* You can set different search weights (`A` to `D`) on different columns inside the index:
|
|
7061
|
+
*
|
|
7062
|
+
* ```ts
|
|
7063
|
+
* import { change } from '../dbScript';
|
|
7064
|
+
*
|
|
7065
|
+
* change(async (db) => {
|
|
7066
|
+
* await db.createTable('table', (t) => ({
|
|
7067
|
+
* id: t.identity().primaryKey(),
|
|
7068
|
+
* title: t.text(),
|
|
7069
|
+
* body: t.text(),
|
|
7070
|
+
* ...t.searchIndex([
|
|
7071
|
+
* { column: 'title', weight: 'A' },
|
|
7072
|
+
* { column: 'body', weight: 'B' },
|
|
7073
|
+
* ]),
|
|
7074
|
+
* }));
|
|
7075
|
+
* });
|
|
7076
|
+
* ```
|
|
7077
|
+
*
|
|
7078
|
+
* When the table has localized columns,
|
|
7079
|
+
* you can define different indexes for different languages by setting the `language` parameter:
|
|
7080
|
+
*
|
|
7081
|
+
* ```ts
|
|
7082
|
+
* import { change } from '../dbScript';
|
|
7083
|
+
*
|
|
7084
|
+
* change(async (db) => {
|
|
7085
|
+
* await db.createTable('table', (t) => ({
|
|
7086
|
+
* id: t.identity().primaryKey(),
|
|
7087
|
+
* titleEn: t.text(),
|
|
7088
|
+
* bodyEn: t.text(),
|
|
7089
|
+
* titleFr: t.text(),
|
|
7090
|
+
* bodyFr: t.text(),
|
|
7091
|
+
* ...t.searchIndex(['titleEn', 'bodyEn'], { language: 'english' }),
|
|
7092
|
+
* ...t.searchIndex(['titleFr', 'bodyFr'], { language: 'french' }),
|
|
7093
|
+
* }));
|
|
7094
|
+
* });
|
|
7095
|
+
* ```
|
|
7096
|
+
*
|
|
7097
|
+
* Alternatively, different table records may correspond to a single language,
|
|
7098
|
+
* then you can define a search index that relies on a language column by using `languageColumn` parameter:
|
|
7099
|
+
*
|
|
7100
|
+
* ```ts
|
|
7101
|
+
* import { change } from '../dbScript';
|
|
7102
|
+
*
|
|
7103
|
+
* change(async (db) => {
|
|
7104
|
+
* await db.createTable('table', (t) => ({
|
|
7105
|
+
* id: t.identity().primaryKey(),
|
|
7106
|
+
* lang: t.type('regconfig'),
|
|
7107
|
+
* title: t.text(),
|
|
7108
|
+
* body: t.text(),
|
|
7109
|
+
* ...t.searchIndex(['title', 'body'], { languageColumn: 'lang' }),
|
|
7110
|
+
* }));
|
|
7111
|
+
* });
|
|
6944
7112
|
* ```
|
|
6945
7113
|
*
|
|
6946
|
-
*
|
|
7114
|
+
* It can be more efficient to use a [generated](/guide/migration-column-methods.html#generated-column) column instead of indexing text column in the way described above,
|
|
7115
|
+
* and to set a `searchIndex` on it:
|
|
6947
7116
|
*
|
|
6948
7117
|
* ```ts
|
|
6949
7118
|
* import { change } from '../dbScript';
|
|
@@ -6951,8 +7120,8 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6951
7120
|
* change(async (db) => {
|
|
6952
7121
|
* await db.createTable('table', (t) => ({
|
|
6953
7122
|
* id: t.identity().primaryKey(),
|
|
6954
|
-
* title: t.
|
|
6955
|
-
* body: t.
|
|
7123
|
+
* title: t.text(),
|
|
7124
|
+
* body: t.text(),
|
|
6956
7125
|
* generatedTsVector: t.tsvector().generated(['title', 'body']).searchIndex(),
|
|
6957
7126
|
* }));
|
|
6958
7127
|
* });
|
|
@@ -6966,8 +7135,11 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6966
7135
|
*
|
|
6967
7136
|
* @param options - index options
|
|
6968
7137
|
*/
|
|
6969
|
-
searchIndex<T extends
|
|
6970
|
-
|
|
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>;
|
|
6971
7143
|
comment<T extends PickColumnData>(this: T, comment: string): T;
|
|
6972
7144
|
compression<T extends PickColumnData>(this: T, compression: string): T;
|
|
6973
7145
|
collate<T extends PickColumnData>(this: T, collate: string): T;
|
|
@@ -6990,9 +7162,89 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
6990
7162
|
generated<T extends PickColumnData>(this: T, ...args: StaticSQLArgs): T;
|
|
6991
7163
|
}
|
|
6992
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
|
+
|
|
6993
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;
|
|
6994
7247
|
declare const instantiateColumn: (typeFn: () => ColumnTypeBase, params: ColumnFromDbParams) => ColumnTypeBase;
|
|
6995
|
-
declare const getConstraintKind: (it: TableData.Constraint) => 'constraint' | 'foreignKey' | 'check';
|
|
6996
7248
|
|
|
6997
7249
|
interface ColumnsShape {
|
|
6998
7250
|
[K: string]: ColumnType;
|
|
@@ -7049,18 +7301,20 @@ declare class UnknownColumn<Schema extends ColumnSchemaConfig> extends VirtualCo
|
|
|
7049
7301
|
}
|
|
7050
7302
|
|
|
7051
7303
|
declare const isDefaultTimeStamp: (item: ColumnTypeBase) => boolean;
|
|
7052
|
-
declare const columnsShapeToCode: (shape: ColumnsShapeBase,
|
|
7053
|
-
declare const
|
|
7054
|
-
declare const
|
|
7055
|
-
declare const
|
|
7056
|
-
declare const
|
|
7057
|
-
declare const
|
|
7058
|
-
declare const
|
|
7059
|
-
declare const
|
|
7060
|
-
declare const
|
|
7061
|
-
declare const
|
|
7062
|
-
declare const
|
|
7063
|
-
declare const
|
|
7304
|
+
declare const columnsShapeToCode: (shape: ColumnsShapeBase, t: string) => Codes;
|
|
7305
|
+
declare const pushTableDataCode: (code: Codes, ast: TableData) => Codes;
|
|
7306
|
+
declare const primaryKeyInnerToCode: (primaryKey: TableData.PrimaryKey, t: string) => string;
|
|
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;
|
|
7317
|
+
declare const columnCode: (type: ColumnType, t: string, code: Code, migration: boolean | undefined, data?: ColumnData, skip?: {
|
|
7064
7318
|
encodeFn: unknown;
|
|
7065
7319
|
}) => Code;
|
|
7066
7320
|
|
|
@@ -7119,6 +7373,7 @@ declare const saveSearchAlias: (q: QueryBase, as: string, key: 'joinedShapes' |
|
|
|
7119
7373
|
* @param methods - methods to add
|
|
7120
7374
|
*/
|
|
7121
7375
|
declare const extendQuery: <T extends PickQueryQAndBaseQuery, Methods extends RecordUnknown>(q: T, methods: Methods) => T & Methods;
|
|
7376
|
+
declare const getPrimaryKeys: (q: Query) => string[];
|
|
7122
7377
|
|
|
7123
7378
|
type Arg = {
|
|
7124
7379
|
$queryBuilder: Query;
|
|
@@ -7168,13 +7423,14 @@ declare function addComputedColumns<T extends PickQueryTableMetaShape, Computed
|
|
|
7168
7423
|
* Sets query kind to 'columnInfo', returns a single value (may return undefined),
|
|
7169
7424
|
* the value is a {@link GetColumnInfo} object or a Record with keys for column names and ColumnInfo objects as values.
|
|
7170
7425
|
**/
|
|
7171
|
-
type SetQueryReturnsColumnInfo<T extends PickQueryMetaShape, Column extends keyof T['shape'] | undefined, Result = Column extends keyof T['shape'] ? GetColumnInfo :
|
|
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'> & {
|
|
7172
7429
|
result: {
|
|
7173
7430
|
value: QueryColumn<Result>;
|
|
7174
7431
|
};
|
|
7175
7432
|
returnType: 'value';
|
|
7176
7433
|
then: QueryThen<Result>;
|
|
7177
|
-
catch: QueryCatch<Result>;
|
|
7178
7434
|
};
|
|
7179
7435
|
type GetColumnInfo = {
|
|
7180
7436
|
defaultValue: unknown;
|
|
@@ -7258,4 +7514,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
7258
7514
|
*/
|
|
7259
7515
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
7260
7516
|
|
|
7261
|
-
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, DbOptions, DbResult, DbTableConstructor, DbTableOptionScopes, DbTableOptions, DecimalColumn, DecimalColumnData, DefaultColumnTypes, DefaultSchemaConfig, Delete, DeleteArgs, DeleteMethodsNames, DeleteQueryData, DeleteResult, DomainColumn, DoublePrecisionColumn,
|
|
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 };
|