pqb 0.57.0 → 0.57.2
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 +1829 -47
- package/dist/index.js +1851 -526
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1324 -96
- package/dist/index.mjs.map +1 -1
- package/dist/node-postgres.d.ts +1074 -4
- package/dist/node-postgres.js +37 -5
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +33 -1
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.d.ts +1076 -6
- package/dist/postgres-js.js +40 -8
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +33 -1
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +3 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,1792 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Expression, MaybeArray, QueryColumns, IsQuery, ColumnTypesBase, RecordUnknown, RelationConfigBase, TemplateLiteralArgs, QueryOrExpression, QueryColumn, EmptyObject, MaybePromise, FnUnknownToUnknown, RelationsBase, QueryMetaBase, QueryReturnType, RecordString, ColumnsShapeBase, ColumnsParsers, QueryHookUtils, PickQueryInputType, PickQueryTable, QueryResult, Sql, QueryDataBase, AdapterBase, HookSelect, BatchParsers, QueryLogObject, QueryLogger, QueryDataTransform, ExpressionChain, DelayedRelationSelect, QueryDataAliases, ColumnSchemaConfig, RawSQLBase, RawSQLValues, ExpressionTypeMethod, DynamicSQLArg, ExpressionData, StaticSQLArgs, SQLQueryArgs, PickQueryRelationsWithData, PickQueryTableMetaResult, PickQueryMetaShapeRelationsWithData, EmptyTuple, PickQueryMeta, WithDataItem, PickQueryMetaResultReturnType, QueryColumnToNullable, QueryThenByQuery, PickQueryMetaResultRelationsWithDataReturnType, AliasOrTable, PickQueryTableMetaResultShape, PickQueryTableMetaShape, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryMetaColumnTypes, ColumnShapeInput, SelectableBase, PickQueryMetaShape, PickQueryMetaResultRelationsWindows, PickQueryMetaResultWindows, PickOutputTypeAndOperators, PickQueryResult, PickQueryResultColumnTypes, PickQueryColumnTypes, PickQueryShape, ValExpression, PickQueryMetaResultRelationsWindowsColumnTypes, PickOutputType, QueryThen, PickQueryMetaRelations, PickQueryRelations, PickQueryMetaRelationsResultReturnType, DateColumnData, ColumnToCodeCtx, Code, TimeInterval, ColumnTypeSchemaArg, ColumnDataBase, ArrayMethodsData, ForeignKeyTable, ColumnNameOfTable, BaseNumberData, PickColumnBaseData, ColumnWithDefault, StringTypeData, PrimaryKeyColumn, ColumnTypeBase, ParseColumn, ParseNullColumn, EncodeColumn, ColumnInputOutputQueryTypes, QueryResultRow, QueryColumnsInit, QueryLogOptions, DefaultSelectColumns, DefaultSelectOutput, QueryThenShallowSimplifyArr, QueryErrorName, QueryError, QueryCatch, TransactionState, QueryArraysResult, PickQueryMetaTable, QueryColumnOfDataType, AsQueryArg, SetQueryTableAlias, PickQueryUniqueProperties, RelationConfigDataForCreate, PickQueryMetaResult, PickQueryMetaTableShapeReturnTypeWithData, WithDataItems, PickQueryTableMetaResultInputType, UnionToIntersection, SingleSqlItem, OrchidOrmError, AfterCommitStandaloneHook, PickQueryMetaResultReturnTypeWithDataWindowsThen, getValueKey, PickQueryWithData, QueryMetaIsSubQuery, QueryThenByReturnType, PickQueryReturnType, PickQueryWithDataColumnTypes, PickQueryMetaWithDataColumnTypes, QueryReturnTypeAll, QueryReturnTypeOptional, QueryThenShallowSimplifyOptional, QueryThenShallowSimplify, PickQueryResultReturnType, PickQueryShapeResultReturnTypeSinglePrimaryKey, PickQueryResultReturnTypeUniqueColumns, PickQueryTableMetaResultReturnTypeWithDataWindowsThen, PickQueryMetaShapeRelationsReturnType, QueryInternalBase, QueryBase, IsQueries, PickType, RecordKeyTrue, ColumnShapeOutput, OperatorsNullable, PickQueryMetaReturnType, UniqueColumn, TimestampHelpers, ShallowSimplify, Codes, ColumnDataCheckBase } from 'orchid-core';
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
2
|
import { QueryBuilder as QueryBuilder$1, QueryInternal as QueryInternal$1, QueryData as QueryData$1, UpsertThis as UpsertThis$1, UpsertResult as UpsertResult$1 } from 'pqb';
|
|
4
3
|
import { inspect } from 'node:util';
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
declare const colors: {
|
|
6
|
+
yellow: (s: string) => string;
|
|
7
|
+
green: (s: string) => string;
|
|
8
|
+
red: (s: string) => string;
|
|
9
|
+
blue: (s: string) => string;
|
|
10
|
+
bright: (s: string) => string;
|
|
11
|
+
blueBold: (s: string) => string;
|
|
12
|
+
yellowBold: (s: string) => string;
|
|
13
|
+
greenBold: (s: string) => string;
|
|
14
|
+
pale: (s: string) => string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
18
|
+
type MaybeArray<T> = T | T[];
|
|
19
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
20
|
+
interface FnUnknownToUnknown {
|
|
21
|
+
(a: unknown): unknown;
|
|
22
|
+
}
|
|
23
|
+
interface RecordKeyTrue {
|
|
24
|
+
[K: string]: true;
|
|
25
|
+
}
|
|
26
|
+
interface RecordString {
|
|
27
|
+
[K: string]: string;
|
|
28
|
+
}
|
|
29
|
+
interface RecordOptionalString {
|
|
30
|
+
[K: string]: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
interface RecordUnknown {
|
|
33
|
+
[K: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
interface RecordBoolean {
|
|
36
|
+
[K: string]: boolean;
|
|
37
|
+
}
|
|
38
|
+
type ShallowSimplify<T> = T extends any ? {
|
|
39
|
+
[K in keyof T]: T[K];
|
|
40
|
+
} : T;
|
|
41
|
+
/**
|
|
42
|
+
* Merge methods from multiple class into another class.
|
|
43
|
+
* @param derivedCtor - target class to merge methods into
|
|
44
|
+
* @param constructors - classes to merge methods from
|
|
45
|
+
*/
|
|
46
|
+
declare function applyMixins(derivedCtor: any, constructors: any[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* Join array of strings with '', ignoring empty strings, false, undefined.
|
|
49
|
+
* @param strings - array of strings, or false, or undefined
|
|
50
|
+
*/
|
|
51
|
+
declare const joinTruthy: (...strings: (string | false | undefined)[]) => string;
|
|
52
|
+
/**
|
|
53
|
+
* When array is passed, it is returned as is, otherwise, returns a new array with the provided value.
|
|
54
|
+
* @param item - array or a value to turn into array
|
|
55
|
+
*/
|
|
56
|
+
declare const toArray: <T>(item: T) => T extends unknown[] ? T : [T];
|
|
57
|
+
declare const noop: () => void;
|
|
58
|
+
declare const returnArg: <T>(a: T) => T;
|
|
59
|
+
type EmptyObject = {};
|
|
60
|
+
declare const emptyObject: {};
|
|
61
|
+
type EmptyTuple = [];
|
|
62
|
+
declare const emptyArray: never[];
|
|
63
|
+
/**
|
|
64
|
+
* Push a value into an array in the object if it's defined, or set a new array with a single value into the object.
|
|
65
|
+
* Does not mutate the array.
|
|
66
|
+
*
|
|
67
|
+
* @param obj - object that can contain the array by the key
|
|
68
|
+
* @param key - key to access an array in the object
|
|
69
|
+
* @param value - value to push into the array
|
|
70
|
+
*/
|
|
71
|
+
declare const pushOrNewArrayToObjectImmutable: (obj: object, key: string | number, value: unknown) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Set value into the object in data, create the object if it doesn't yet exist.
|
|
74
|
+
* Does not mutate the object.
|
|
75
|
+
*
|
|
76
|
+
* @param q - object
|
|
77
|
+
* @param object - query data key to get the object
|
|
78
|
+
* @param key - object key to set the value into
|
|
79
|
+
* @param value - value to set by the key
|
|
80
|
+
*/
|
|
81
|
+
declare const setObjectValueImmutable: <T>(q: T, object: string, key: PropertyKey, value: unknown) => T;
|
|
82
|
+
declare const spreadObjectValues: (q: object, object: string, value: RecordUnknown) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Push value into an array if it's defined, or return a new array with a single value.
|
|
85
|
+
* @param arr - array to push into, or `undefined`
|
|
86
|
+
* @param value - value to push into the array
|
|
87
|
+
*/
|
|
88
|
+
declare const pushOrNewArray: <Arr extends unknown[]>(arr: Arr | undefined, value: Arr[number]) => Arr;
|
|
89
|
+
/**
|
|
90
|
+
* For code generation: quote a string with a single quote, escape characters.
|
|
91
|
+
* @param s - string to quote
|
|
92
|
+
*/
|
|
93
|
+
declare const singleQuote: (s: string) => string;
|
|
94
|
+
/**
|
|
95
|
+
* For code generation: quote string with a backtick, escape characters.
|
|
96
|
+
* @param s - string to quote
|
|
97
|
+
*/
|
|
98
|
+
declare const backtickQuote: (s: string) => string;
|
|
99
|
+
/**
|
|
100
|
+
* For code generation: stringify array of strings using a single quote.
|
|
101
|
+
* @param arr
|
|
102
|
+
*/
|
|
103
|
+
declare const singleQuoteArray: (arr: string[]) => string;
|
|
104
|
+
/**
|
|
105
|
+
* For code generation: some strings must be quoted when used as an object key.
|
|
106
|
+
* This function quotes the strings when needed.
|
|
107
|
+
* @param key - object key to quote
|
|
108
|
+
* @param toCamel - change to camel case
|
|
109
|
+
*/
|
|
110
|
+
declare const quoteObjectKey: (key: string, toCamel: boolean | undefined) => string;
|
|
111
|
+
/**
|
|
112
|
+
* Check if the object has no values that are not `undefined`.
|
|
113
|
+
* @param obj
|
|
114
|
+
*/
|
|
115
|
+
declare const isObjectEmpty: (obj: object) => boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Check if the object has at least one value that is not `undefined`.
|
|
118
|
+
* Nulls counts.
|
|
119
|
+
* @param obj - any object
|
|
120
|
+
*/
|
|
121
|
+
declare const objectHasValues: (obj?: object) => boolean;
|
|
122
|
+
/**
|
|
123
|
+
* If we simply log file path as it is, it may be not clickable in the terminal.
|
|
124
|
+
* On Windows, it is clickable as it is, so it is returned as is.
|
|
125
|
+
* On Linux (at least in my JetBrains editor terminal) it's transformed to URL format to be clickable.
|
|
126
|
+
* @param path - file path
|
|
127
|
+
*/
|
|
128
|
+
declare const pathToLog: (path: string) => string;
|
|
129
|
+
/**
|
|
130
|
+
* Translate a string to camelCase
|
|
131
|
+
* @param str - string to translate
|
|
132
|
+
*/
|
|
133
|
+
declare const toCamelCase: (str: string) => string;
|
|
134
|
+
/**
|
|
135
|
+
* Translate a string to a PascalCase
|
|
136
|
+
* @param str - string to translate
|
|
137
|
+
*/
|
|
138
|
+
declare const toPascalCase: (str: string) => string;
|
|
139
|
+
/**
|
|
140
|
+
* Translate a string to a snake_case.
|
|
141
|
+
* @param str - string to translate
|
|
142
|
+
*/
|
|
143
|
+
declare const toSnakeCase: (str: string) => string;
|
|
144
|
+
/**
|
|
145
|
+
* Compare two values deeply.
|
|
146
|
+
* undefined and empty object are considered to be equal.
|
|
147
|
+
* @param a - any value
|
|
148
|
+
* @param b - any value
|
|
149
|
+
*/
|
|
150
|
+
declare const deepCompare: (a: unknown, b: unknown) => boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Returns a relative path to use as an `import` source to import one file from another.
|
|
153
|
+
* @param from - TS file where we want to place the `import`
|
|
154
|
+
* @param to - TS file that we're importing
|
|
155
|
+
*/
|
|
156
|
+
declare const getImportPath: (from: string, to: string) => string;
|
|
157
|
+
/**
|
|
158
|
+
* Get stack trace to collect info about who called the function
|
|
159
|
+
*/
|
|
160
|
+
declare const getStackTrace: () => NodeJS.CallSite[] | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Get a file path of the function which called the function which called this `getCallerFilePath`.
|
|
163
|
+
* Determines file path by error stack trace, skips any paths that are located in `node_modules`.
|
|
164
|
+
* @param stack - optionally provide an existing stack trace
|
|
165
|
+
*/
|
|
166
|
+
declare const getCallerFilePath: (stack?: NodeJS.CallSite[] | undefined) => string | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Call function passing `this` as an argument,
|
|
169
|
+
* micro-optimization for `map` and `forEach` to not define temporary inline function
|
|
170
|
+
* ```ts
|
|
171
|
+
* arrayOfFns.map(callWithThis, argument)
|
|
172
|
+
* ```
|
|
173
|
+
* @param cb
|
|
174
|
+
*/
|
|
175
|
+
declare const callWithThis: <T, R>(this: T, cb: (arg: T) => R) => R;
|
|
176
|
+
declare const pick: <T, Keys extends keyof T>(obj: T, keys: Keys[]) => Pick<T, Keys>;
|
|
177
|
+
declare const omit: <T, Keys extends keyof T>(obj: T, keys: Keys[]) => Omit<T, Keys>;
|
|
178
|
+
declare const addValue: (values: unknown[], value: unknown) => string;
|
|
179
|
+
declare const getFreeAlias: (obj: RecordUnknown | undefined, as: string) => string;
|
|
180
|
+
declare const getFreeSetAlias: (set: Set<string>, as: string, start?: number) => string;
|
|
181
|
+
declare const exhaustive: (_: never) => never;
|
|
182
|
+
declare const pluralize: (w: string, count: number, append?: string) => string;
|
|
183
|
+
declare const isIterable: (x: unknown) => x is Iterable<unknown>;
|
|
184
|
+
|
|
185
|
+
type ExpressionChain = (OperatorToSQL<unknown, unknown> | unknown)[];
|
|
186
|
+
interface ExpressionData {
|
|
187
|
+
chain?: ExpressionChain;
|
|
188
|
+
expr?: Expression;
|
|
189
|
+
}
|
|
190
|
+
declare abstract class Expression<T extends QueryColumn = QueryColumn> {
|
|
191
|
+
abstract result: {
|
|
192
|
+
value: T;
|
|
193
|
+
};
|
|
194
|
+
abstract q: ExpressionData;
|
|
195
|
+
meta: {
|
|
196
|
+
kind: 'select';
|
|
197
|
+
};
|
|
198
|
+
toSQL(ctx: {
|
|
199
|
+
values: unknown[];
|
|
200
|
+
}, quotedAs?: string): string;
|
|
201
|
+
abstract makeSQL(ctx: {
|
|
202
|
+
values: unknown[];
|
|
203
|
+
}, quotedAs?: string): string;
|
|
204
|
+
}
|
|
205
|
+
declare const isExpression: (arg: unknown) => arg is Expression<QueryColumn<unknown, any>>;
|
|
206
|
+
type TemplateLiteralArgs = [
|
|
207
|
+
strings: TemplateStringsArray,
|
|
208
|
+
...values: unknown[]
|
|
209
|
+
];
|
|
210
|
+
declare const isTemplateLiteralArgs: (args: unknown[]) => args is TemplateLiteralArgs;
|
|
211
|
+
type SQLArgs = StaticSQLArgs | [DynamicSQLArg<QueryColumn>];
|
|
212
|
+
interface DynamicSQLArg<T extends QueryColumn> {
|
|
213
|
+
(sql: (...args: StaticSQLArgs) => Expression<T>): Expression<T>;
|
|
214
|
+
}
|
|
215
|
+
type StaticSQLArgs = TemplateLiteralArgs | [{
|
|
216
|
+
raw: string;
|
|
217
|
+
values?: RawSQLValues;
|
|
218
|
+
}];
|
|
219
|
+
type RawSQLValues = RecordUnknown;
|
|
220
|
+
declare abstract class ExpressionTypeMethod {
|
|
221
|
+
type<T extends {
|
|
222
|
+
q: {
|
|
223
|
+
expr?: Expression;
|
|
224
|
+
};
|
|
225
|
+
columnTypes: unknown;
|
|
226
|
+
}, C extends QueryColumn>(this: T, fn: (types: T['columnTypes']) => C): // Omit is optimal
|
|
227
|
+
Omit<T, 'result'> & {
|
|
228
|
+
result: {
|
|
229
|
+
value: C;
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
interface RawSQLBase<T extends QueryColumn = QueryColumn, ColumnTypes = unknown> extends Expression<T>, ExpressionTypeMethod {
|
|
234
|
+
}
|
|
235
|
+
declare abstract class RawSQLBase<T extends QueryColumn = QueryColumn, ColumnTypes = unknown> extends Expression<T> {
|
|
236
|
+
_sql: string | TemplateLiteralArgs;
|
|
237
|
+
_values?: RecordUnknown | undefined;
|
|
238
|
+
result: {
|
|
239
|
+
value: T;
|
|
240
|
+
};
|
|
241
|
+
q: ExpressionData;
|
|
242
|
+
abstract columnTypes: ColumnTypes;
|
|
243
|
+
abstract makeSQL(ctx: {
|
|
244
|
+
values: unknown[];
|
|
245
|
+
}): string;
|
|
246
|
+
constructor(_sql: string | TemplateLiteralArgs, _values?: RecordUnknown | undefined);
|
|
247
|
+
values<Self extends RawSQLBase>(this: Self, values: RawSQLValues): Self;
|
|
248
|
+
toCode(t: string): string;
|
|
249
|
+
}
|
|
250
|
+
declare const templateLiteralSQLToCode: (sql: TemplateLiteralArgs) => string;
|
|
251
|
+
declare const isRawSQL: (arg: unknown) => arg is RawSQLBase<QueryColumn<unknown, any>, unknown>;
|
|
252
|
+
declare class ValExpression extends Expression {
|
|
253
|
+
value: unknown;
|
|
254
|
+
result: {
|
|
255
|
+
value: ColumnTypeBase<ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, ColumnDataBase>;
|
|
256
|
+
};
|
|
257
|
+
q: ExpressionData;
|
|
258
|
+
constructor(value: unknown);
|
|
259
|
+
makeSQL(ctx: {
|
|
260
|
+
values: unknown[];
|
|
261
|
+
}): string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
interface OperatorBase<Value> {
|
|
265
|
+
(this: any, arg: Value): any;
|
|
266
|
+
_opType: Value;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Function to turn the operator expression into SQL.
|
|
270
|
+
*
|
|
271
|
+
* @param key - SQL of the target to apply operator for, can be a quoted column name or an SQL expression wrapped with parens.
|
|
272
|
+
* @param args - arguments of operator function.
|
|
273
|
+
* @param ctx - context object for SQL conversions, for collecting query variables.
|
|
274
|
+
* @param quotedAs - quoted table name.
|
|
275
|
+
*/
|
|
276
|
+
interface OperatorToSQL<Value, Ctx> {
|
|
277
|
+
(key: string, args: [Value], ctx: Ctx, quotedAs?: string): string;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
interface ColumnSchemaGetterTableClass {
|
|
281
|
+
prototype: {
|
|
282
|
+
columns: {
|
|
283
|
+
shape: ColumnTypesBase;
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
inputSchema(): unknown;
|
|
287
|
+
querySchema(): unknown;
|
|
288
|
+
pkeySchema(): unknown;
|
|
289
|
+
createSchema(): unknown;
|
|
290
|
+
}
|
|
291
|
+
type ColumnSchemaGetterColumns<T extends ColumnSchemaGetterTableClass> = T['prototype']['columns']['shape'];
|
|
292
|
+
interface ColumnTypeSchemaArg {
|
|
293
|
+
type: unknown;
|
|
294
|
+
nullable<T extends ColumnTypeBase>(this: T): NullableColumn<T, unknown, unknown, unknown>;
|
|
295
|
+
encode: unknown;
|
|
296
|
+
parse: unknown;
|
|
297
|
+
parseNull: unknown;
|
|
298
|
+
asType: unknown;
|
|
299
|
+
narrowType: unknown;
|
|
300
|
+
narrowAllTypes: unknown;
|
|
301
|
+
error?: unknown;
|
|
302
|
+
}
|
|
303
|
+
interface ColumnSchemaConfig<T extends ColumnTypeBase = ColumnTypeBase> extends ColumnTypeSchemaArg {
|
|
304
|
+
dateAsNumber: unknown;
|
|
305
|
+
dateAsDate: unknown;
|
|
306
|
+
enum: unknown;
|
|
307
|
+
array: unknown;
|
|
308
|
+
boolean(): unknown;
|
|
309
|
+
buffer(): unknown;
|
|
310
|
+
unknown(): unknown;
|
|
311
|
+
never(): unknown;
|
|
312
|
+
stringSchema(): unknown;
|
|
313
|
+
stringMin(max: number): unknown;
|
|
314
|
+
stringMax(max: number): unknown;
|
|
315
|
+
stringMinMax(min: number, max: number): unknown;
|
|
316
|
+
number(): unknown;
|
|
317
|
+
int(): unknown;
|
|
318
|
+
stringNumberDate(): unknown;
|
|
319
|
+
timeInterval(): unknown;
|
|
320
|
+
bit(max?: number): unknown;
|
|
321
|
+
uuid(): unknown;
|
|
322
|
+
json(): T;
|
|
323
|
+
inputSchema(this: ColumnSchemaGetterTableClass): unknown;
|
|
324
|
+
outputSchema(this: ColumnSchemaGetterTableClass): unknown;
|
|
325
|
+
querySchema(this: ColumnSchemaGetterTableClass): unknown;
|
|
326
|
+
createSchema(this: ColumnSchemaGetterTableClass): unknown;
|
|
327
|
+
updateSchema(this: ColumnSchemaGetterTableClass): unknown;
|
|
328
|
+
pkeySchema(this: ColumnSchemaGetterTableClass): unknown;
|
|
329
|
+
smallint(): T;
|
|
330
|
+
integer(): T;
|
|
331
|
+
real(): T;
|
|
332
|
+
smallSerial(): T;
|
|
333
|
+
serial(): T;
|
|
334
|
+
bigint(): T;
|
|
335
|
+
decimal(precision?: number, scale?: number): T;
|
|
336
|
+
doublePrecision(): T;
|
|
337
|
+
bigSerial(): T;
|
|
338
|
+
money(): T;
|
|
339
|
+
varchar(limit?: number): T;
|
|
340
|
+
text(): T;
|
|
341
|
+
string(limit?: number): T;
|
|
342
|
+
citext(): T;
|
|
343
|
+
date(): T;
|
|
344
|
+
timestampNoTZ(precision?: number): T;
|
|
345
|
+
timestamp(precision?: number): T;
|
|
346
|
+
geographyPointSchema(): unknown;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
interface WithDataItem {
|
|
350
|
+
table: string;
|
|
351
|
+
shape: QueryColumns;
|
|
352
|
+
}
|
|
353
|
+
interface WithDataItems {
|
|
354
|
+
[K: string]: WithDataItem;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
interface RelationJoinQuery {
|
|
358
|
+
(joiningQuery: IsQuery, baseQuery: IsQuery): IsQuery;
|
|
359
|
+
}
|
|
360
|
+
interface RelationConfigQuery extends PickQueryTableMetaResult, PickQueryShape, PickQueryTable {
|
|
361
|
+
}
|
|
362
|
+
interface RelationConfigBase extends IsQuery {
|
|
363
|
+
returnsOne: boolean;
|
|
364
|
+
query: RelationConfigQuery;
|
|
365
|
+
joinQuery: RelationJoinQuery;
|
|
366
|
+
reverseJoin: RelationJoinQuery;
|
|
367
|
+
params: unknown;
|
|
368
|
+
queryRelated(params: unknown): unknown;
|
|
369
|
+
modifyRelatedQuery?(relatedQuery: IsQuery): (query: IsQuery) => void;
|
|
370
|
+
maybeSingle: PickQueryMetaReturnType;
|
|
371
|
+
omitForeignKeyInCreate: PropertyKey;
|
|
372
|
+
dataForCreate?: RelationConfigDataForCreate;
|
|
373
|
+
optionalDataForCreate: unknown;
|
|
374
|
+
dataForUpdate: unknown;
|
|
375
|
+
dataForUpdateOne: unknown;
|
|
376
|
+
primaryKeys: string[];
|
|
377
|
+
}
|
|
378
|
+
interface RelationConfigDataForCreate {
|
|
379
|
+
columns: PropertyKey;
|
|
380
|
+
nested: RecordUnknown;
|
|
381
|
+
}
|
|
382
|
+
interface RelationsBase {
|
|
383
|
+
[K: string]: RelationConfigBase;
|
|
384
|
+
}
|
|
385
|
+
declare const isRelationQuery: (q: IsQuery) => q is RelationConfigBase;
|
|
386
|
+
|
|
387
|
+
interface PickQueryTable {
|
|
388
|
+
table?: string;
|
|
389
|
+
}
|
|
390
|
+
interface PickQueryMeta {
|
|
391
|
+
meta: QueryMetaBase;
|
|
392
|
+
}
|
|
393
|
+
interface PickQueryResult {
|
|
394
|
+
result: QueryColumns;
|
|
395
|
+
}
|
|
396
|
+
interface PickQueryShape {
|
|
397
|
+
shape: QueryColumns;
|
|
398
|
+
}
|
|
399
|
+
interface PickQueryReturnType {
|
|
400
|
+
returnType: QueryReturnType;
|
|
401
|
+
}
|
|
402
|
+
interface PickQueryResultReturnType extends PickQueryResult, PickQueryReturnType {
|
|
403
|
+
}
|
|
404
|
+
interface PickQueryMetaShape extends PickQueryMeta, PickQueryShape {
|
|
405
|
+
}
|
|
406
|
+
interface PickQueryMetaResult extends PickQueryMeta, PickQueryResult {
|
|
407
|
+
}
|
|
408
|
+
interface PickQueryResultUniqueColumns extends PickQueryResult {
|
|
409
|
+
internal: {
|
|
410
|
+
uniqueColumns: unknown;
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
interface PickQueryResultReturnTypeUniqueColumns extends PickQueryResultUniqueColumns, PickQueryReturnType {
|
|
414
|
+
}
|
|
415
|
+
interface PickQueryUniqueProperties {
|
|
416
|
+
internal: {
|
|
417
|
+
uniqueColumnNames: unknown;
|
|
418
|
+
uniqueColumnTuples: unknown;
|
|
419
|
+
uniqueConstraints: unknown;
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
interface PickQueryMetaResultWindows extends PickQueryMetaResult {
|
|
423
|
+
windows: EmptyObject;
|
|
424
|
+
}
|
|
425
|
+
interface PickQueryTableMetaResult extends PickQueryTable, PickQueryMetaResult {
|
|
426
|
+
}
|
|
427
|
+
interface PickQueryInputType {
|
|
428
|
+
inputType: unknown;
|
|
429
|
+
}
|
|
430
|
+
interface PickQueryTableMetaResultInputType extends PickQueryTableMetaResult, PickQueryInputType {
|
|
431
|
+
}
|
|
432
|
+
interface PickQueryTableMetaShape extends PickQueryTable, PickQueryMetaShape {
|
|
433
|
+
}
|
|
434
|
+
interface PickQueryTableMetaResultShape extends PickQueryTableMetaResult, PickQueryMetaShape {
|
|
435
|
+
}
|
|
436
|
+
interface PickQueryMetaReturnType extends PickQueryMeta, PickQueryReturnType {
|
|
437
|
+
}
|
|
438
|
+
interface PickQueryMetaResultReturnType extends PickQueryMetaResult, PickQueryReturnType {
|
|
439
|
+
}
|
|
440
|
+
interface PickQueryWithData {
|
|
441
|
+
withData: WithDataItems;
|
|
442
|
+
}
|
|
443
|
+
interface PickQueryWindows {
|
|
444
|
+
windows: EmptyObject;
|
|
445
|
+
}
|
|
446
|
+
interface PickQueryRelations {
|
|
447
|
+
relations: RelationsBase;
|
|
448
|
+
}
|
|
449
|
+
interface PickQueryRelationQueries {
|
|
450
|
+
relationQueries: IsQueries;
|
|
451
|
+
}
|
|
452
|
+
interface PickQueryMetaRelations extends PickQueryMeta, PickQueryRelations {
|
|
453
|
+
}
|
|
454
|
+
interface PickQueryMetaRelationsResult extends PickQueryMetaRelations, PickQueryResult {
|
|
455
|
+
}
|
|
456
|
+
interface PickQueryMetaRelationsReturnType extends PickQueryMetaRelationsResult, PickQueryResultReturnType {
|
|
457
|
+
}
|
|
458
|
+
interface PickQueryMetaShapeRelationsReturnType extends PickQueryMetaRelationsReturnType, PickQueryShape {
|
|
459
|
+
}
|
|
460
|
+
interface PickQueryMetaRelationsResultReturnType extends PickQueryMetaRelationsReturnType, PickQueryResult {
|
|
461
|
+
}
|
|
462
|
+
interface PickQueryMetaResultRelations extends PickQueryResult, PickQueryMeta, PickQueryRelations {
|
|
463
|
+
}
|
|
464
|
+
interface PickQueryMetaResultRelationsWindows extends PickQueryMetaResultRelations, PickQueryWindows {
|
|
465
|
+
}
|
|
466
|
+
interface PickQueryColumnTypes {
|
|
467
|
+
columnTypes: unknown;
|
|
468
|
+
}
|
|
469
|
+
interface PickQueryMetaColumnTypes extends PickQueryMeta, PickQueryColumnTypes {
|
|
470
|
+
}
|
|
471
|
+
interface PickQueryMetaResultRelationsWindowsColumnTypes extends PickQueryMetaResultRelationsWindows, PickQueryColumnTypes {
|
|
472
|
+
}
|
|
473
|
+
interface PickQueryWithDataColumnTypes extends PickQueryWithData, PickQueryColumnTypes {
|
|
474
|
+
}
|
|
475
|
+
interface PickQueryResultColumnTypes extends PickQueryResult, PickQueryColumnTypes {
|
|
476
|
+
}
|
|
477
|
+
interface PickQueryMetaWithDataColumnTypes extends PickQueryMeta, PickQueryWithData, PickQueryColumnTypes {
|
|
478
|
+
}
|
|
479
|
+
interface PickQueryMetaTable extends PickQueryMeta, PickQueryTable {
|
|
480
|
+
}
|
|
481
|
+
interface PickQueryMetaTableShape extends PickQueryMetaTable, PickQueryShape {
|
|
482
|
+
}
|
|
483
|
+
interface PickQueryMetaWithData extends PickQueryMeta, PickQueryWithData {
|
|
484
|
+
}
|
|
485
|
+
interface PickQueryRelationsWithData extends PickQueryWithData, PickQueryRelations {
|
|
486
|
+
}
|
|
487
|
+
interface PickQueryMetaShapeRelationsWithData extends PickQueryMeta, PickQueryShape, PickQueryRelations, PickQueryWithData {
|
|
488
|
+
}
|
|
489
|
+
interface PickQueryMetaResultRelationsWithDataReturnType extends PickQueryMeta, PickQueryResult, PickQueryRelations, PickQueryWithData, PickQueryReturnType {
|
|
490
|
+
}
|
|
491
|
+
interface PickQueryMetaTableShapeReturnTypeWithData extends PickQueryMetaTableShape, PickQueryReturnType, PickQueryMetaWithData {
|
|
492
|
+
}
|
|
493
|
+
interface PickQueryMetaResultRelationsWithDataReturnTypeShape extends PickQueryMetaResultRelationsWithDataReturnType, PickQueryShape {
|
|
494
|
+
}
|
|
495
|
+
interface PickQueryMetaResultReturnTypeWithDataWindows extends PickQueryMetaResultReturnType, PickQueryWithData, PickQueryWindows {
|
|
496
|
+
}
|
|
497
|
+
interface PickQueryMetaResultReturnTypeWithDataWindowsThen extends PickQueryMetaResultReturnTypeWithDataWindows {
|
|
498
|
+
then: unknown;
|
|
499
|
+
}
|
|
500
|
+
interface PickQueryTableMetaResultReturnTypeWithDataWindowsThen extends PickQueryMetaResultReturnTypeWithDataWindowsThen, PickQueryTable {
|
|
501
|
+
}
|
|
502
|
+
interface PickQuerySinglePrimaryKey {
|
|
503
|
+
internal: {
|
|
504
|
+
singlePrimaryKey: unknown;
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
interface PickQueryShapeSinglePrimaryKey extends PickQueryShape, PickQuerySinglePrimaryKey {
|
|
508
|
+
}
|
|
509
|
+
interface PickQueryShapeResultSinglePrimaryKey extends PickQueryShapeSinglePrimaryKey, PickQueryResult {
|
|
510
|
+
}
|
|
511
|
+
interface PickQueryShapeResultReturnTypeSinglePrimaryKey extends PickQueryShapeResultSinglePrimaryKey, PickQueryReturnType {
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
declare class QueryHookUtils<T extends PickQueryInputType> {
|
|
515
|
+
query: IsQuery;
|
|
516
|
+
columns: string[];
|
|
517
|
+
private key;
|
|
518
|
+
constructor(query: IsQuery, columns: string[], key: 'hookCreateSet' | 'hookUpdateSet');
|
|
519
|
+
set: (data: { [K in keyof T["inputType"]]?: T["inputType"][K] | (() => QueryOrExpression<T["inputType"][K]>) | undefined; }) => void;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
type ColumnShapeInput<Shape extends QueryColumnsInit, AppReadOnly = {
|
|
523
|
+
[K in keyof Shape]: Shape[K]['data']['appReadOnly'] extends true ? K : never;
|
|
524
|
+
}[keyof Shape], Optional extends keyof Shape = {
|
|
525
|
+
[K in keyof Shape]: Shape[K]['data']['optional'] extends true ? K : never;
|
|
526
|
+
}[keyof Shape]> = {
|
|
527
|
+
[K in Exclude<keyof Shape, AppReadOnly | Optional>]: Shape[K]['inputType'];
|
|
528
|
+
} & {
|
|
529
|
+
[K in Exclude<Optional, AppReadOnly>]?: Shape[K]['inputType'];
|
|
530
|
+
};
|
|
531
|
+
type ColumnShapeInputPartial<Shape extends QueryColumnsInit> = {
|
|
532
|
+
[K in keyof Shape]?: Shape[K]['inputType'];
|
|
533
|
+
};
|
|
534
|
+
type ColumnShapeOutput<Shape extends QueryColumns> = {
|
|
535
|
+
[K in keyof Shape]: Shape[K]['outputType'];
|
|
536
|
+
};
|
|
537
|
+
type DefaultSelectOutput<Shape extends QueryColumnsInit> = {
|
|
538
|
+
[K in keyof Shape as Shape[K]['data']['explicitSelect'] extends true | undefined ? never : K]: Shape[K]['outputType'];
|
|
539
|
+
};
|
|
540
|
+
interface ColumnsShapeBase {
|
|
541
|
+
[K: string]: ColumnTypeBase;
|
|
542
|
+
}
|
|
543
|
+
type PrimaryKeyColumn<T, Name extends string> = T & {
|
|
544
|
+
data: {
|
|
545
|
+
primaryKey: Name;
|
|
546
|
+
};
|
|
547
|
+
};
|
|
548
|
+
type UniqueColumn<T, Name extends string> = T & {
|
|
549
|
+
data: {
|
|
550
|
+
unique: Name;
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
type NullableColumn<T extends ColumnTypeBase, InputSchema, OutputSchema, QuerySchema> = {
|
|
554
|
+
[K in keyof T]: K extends 'type' ? T['type'] | null : K extends 'inputType' ? T['inputType'] | null : K extends 'inputSchema' ? InputSchema : K extends 'outputType' ? T['outputType'] | (unknown extends T['nullType'] ? null : T['nullType']) : K extends 'outputSchema' ? OutputSchema : K extends 'queryType' ? T['queryType'] | null : K extends 'querySchema' ? QuerySchema : K extends 'data' ? T['data'] & DataNullable : K extends 'operators' ? // `Omit` here is faster than ternaries
|
|
555
|
+
Omit<T['operators'], 'equals' | 'not'> & OperatorsNullable<T['queryType']> : T[K];
|
|
556
|
+
};
|
|
557
|
+
interface DataNullable {
|
|
558
|
+
isNullable: true;
|
|
559
|
+
optional: true;
|
|
560
|
+
}
|
|
561
|
+
interface OperatorsNullable<T> {
|
|
562
|
+
equals: OperatorBase<T | null>;
|
|
563
|
+
not: OperatorBase<T | null>;
|
|
564
|
+
}
|
|
565
|
+
declare function makeColumnNullable<T extends ColumnTypeBase, InputSchema, OutputSchema, QuerySchema>(column: T, inputSchema: InputSchema, outputSchema: OutputSchema, querySchema: QuerySchema): NullableColumn<T, InputSchema, OutputSchema, QuerySchema>;
|
|
566
|
+
type EncodeColumn<T, InputSchema, Input> = {
|
|
567
|
+
[K in keyof T]: K extends 'inputType' ? Input : K extends 'inputSchema' ? InputSchema : T[K];
|
|
568
|
+
};
|
|
569
|
+
type ParseColumn<T extends ColumnTypeBase, OutputSchema, Output> = {
|
|
570
|
+
[K in keyof T]: K extends 'outputType' ? null extends T['type'] ? Exclude<Output, null> | (unknown extends T['nullType'] ? null : T['nullType']) : Output : K extends 'outputSchema' ? null extends T['type'] ? OutputSchema | T['nullSchema'] : OutputSchema : T[K];
|
|
571
|
+
};
|
|
572
|
+
type ParseNullColumn<T extends ColumnTypeBase, NullSchema, NullType> = {
|
|
573
|
+
[K in keyof T]: K extends 'outputType' ? null extends T['type'] ? Exclude<T['outputType'], null> | NullType : T['outputType'] : K extends 'nullType' ? NullType : K extends 'outputSchema' ? null extends T['type'] ? T['outputSchema'] | NullSchema : T['outputSchema'] : K extends 'nullSchema' ? NullSchema : T[K];
|
|
574
|
+
};
|
|
575
|
+
interface PickColumnBaseData {
|
|
576
|
+
data: ColumnDataBase;
|
|
577
|
+
}
|
|
578
|
+
type ColumnWithDefault<T extends PickColumnBaseData, Value> = {
|
|
579
|
+
[K in keyof T]: K extends 'data' ? {
|
|
580
|
+
[K in keyof T['data']]: K extends 'default' ? Value extends null ? never : Value : K extends 'optional' ? true : T['data'][K];
|
|
581
|
+
} : T[K];
|
|
582
|
+
};
|
|
583
|
+
type ColumnDefaultSelect<T extends PickColumnBaseData, Value extends boolean> = {
|
|
584
|
+
[K in keyof T]: K extends 'data' ? {
|
|
585
|
+
[K in keyof T['data']]: K extends 'explicitSelect' ? Value extends true ? false : true : T['data'][K];
|
|
586
|
+
} : T[K];
|
|
587
|
+
};
|
|
588
|
+
interface ColumnDataAppReadOnly {
|
|
589
|
+
data: {
|
|
590
|
+
appReadOnly: true;
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
type ColumnTypesBase = {
|
|
594
|
+
[K in string]: ColumnTypeBase;
|
|
595
|
+
};
|
|
596
|
+
type DefaultSelectColumns<S extends QueryColumnsInit> = {
|
|
597
|
+
[K in keyof S]: S[K]['data']['explicitSelect'] extends true | undefined ? never : K;
|
|
598
|
+
}[keyof S];
|
|
599
|
+
interface ForeignKeyTable {
|
|
600
|
+
new (): {
|
|
601
|
+
schema?: string;
|
|
602
|
+
table: string;
|
|
603
|
+
columns: {
|
|
604
|
+
shape: QueryColumns;
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
type ColumnNameOfTable<Table extends ForeignKeyTable> = keyof InstanceType<Table>['columns']['shape'] & string;
|
|
609
|
+
declare const setColumnData: <T extends PickColumnBaseData, K extends keyof T["data"]>(q: T, key: K, value: T['data'][K]) => T;
|
|
610
|
+
declare const pushColumnData: <T extends PickColumnBaseData, K extends keyof T["data"]>(q: T, key: K, value: unknown) => T;
|
|
611
|
+
type ErrorMessages = {
|
|
612
|
+
required?: string;
|
|
613
|
+
invalidType?: string;
|
|
614
|
+
};
|
|
615
|
+
type ErrorMessage = string | {
|
|
616
|
+
message?: string;
|
|
617
|
+
};
|
|
618
|
+
declare const setDataValue: <T extends PickColumnBaseData, Key extends string, Value>(item: T, key: Key, value: Value, params?: ErrorMessage) => T;
|
|
619
|
+
interface ColumnInputOutputQueryTypes {
|
|
620
|
+
inputType: unknown;
|
|
621
|
+
outputType: unknown;
|
|
622
|
+
queryType: unknown;
|
|
623
|
+
}
|
|
624
|
+
interface ColumnInputOutputQueryTypesWithSchemas extends ColumnInputOutputQueryTypes {
|
|
625
|
+
inputSchema: unknown;
|
|
626
|
+
outputSchema: unknown;
|
|
627
|
+
querySchema: unknown;
|
|
628
|
+
}
|
|
629
|
+
interface ColumnDataBase {
|
|
630
|
+
key: string;
|
|
631
|
+
name?: string;
|
|
632
|
+
optional: true | undefined;
|
|
633
|
+
isNullable?: true;
|
|
634
|
+
primaryKey?: string;
|
|
635
|
+
default: unknown;
|
|
636
|
+
defaultDefault: unknown;
|
|
637
|
+
runtimeDefault?(): unknown;
|
|
638
|
+
explicitSelect?: boolean;
|
|
639
|
+
as?: ColumnTypeBase;
|
|
640
|
+
unique?: string;
|
|
641
|
+
modifyQuery?(q: QueryBaseCommon, column: ColumnTypeBase): void;
|
|
642
|
+
checks?: ColumnDataCheckBase[];
|
|
643
|
+
isOfCustomType?: boolean;
|
|
644
|
+
errors?: RecordString;
|
|
645
|
+
defaultTimestamp?: 'createdAt' | 'updatedAt';
|
|
646
|
+
alias?: string;
|
|
647
|
+
extension?: string;
|
|
648
|
+
encode?(input: any): unknown;
|
|
649
|
+
parse?(input: any): unknown;
|
|
650
|
+
parseItem?(input: string): unknown;
|
|
651
|
+
parseNull?(): unknown;
|
|
652
|
+
jsonCast?: string;
|
|
653
|
+
readOnly?: boolean;
|
|
654
|
+
appReadOnly: true | undefined;
|
|
655
|
+
setOnCreate?(arg: QueryHookUtils<PickQueryInputType>): unknown;
|
|
656
|
+
setOnUpdate?(arg: QueryHookUtils<PickQueryInputType>): unknown;
|
|
657
|
+
setOnSave?(arg: QueryHookUtils<PickQueryInputType>): unknown;
|
|
658
|
+
typmod?: number;
|
|
659
|
+
virtual?: true;
|
|
660
|
+
}
|
|
661
|
+
interface ColumnDataCheckBase {
|
|
662
|
+
sql: RawSQLBase;
|
|
663
|
+
name?: string;
|
|
664
|
+
}
|
|
665
|
+
declare function setCurrentColumnName(name: string): void;
|
|
666
|
+
declare const consumeColumnName: () => string | undefined;
|
|
667
|
+
declare const setDefaultNowFn: (sql: string) => void;
|
|
668
|
+
declare const setDefaultLanguage: (lang?: string) => void;
|
|
669
|
+
declare const getDefaultLanguage: () => string;
|
|
670
|
+
interface AsTypeArgWithType<Schema> {
|
|
671
|
+
type: Schema;
|
|
672
|
+
input?: Schema;
|
|
673
|
+
output?: Schema;
|
|
674
|
+
query?: Schema;
|
|
675
|
+
}
|
|
676
|
+
interface AsTypeArgWithoutType<Schema> {
|
|
677
|
+
input: Schema;
|
|
678
|
+
output: Schema;
|
|
679
|
+
query: Schema;
|
|
680
|
+
}
|
|
681
|
+
type AsTypeArg<Schema> = AsTypeArgWithType<Schema> | AsTypeArgWithoutType<Schema>;
|
|
682
|
+
interface PickType {
|
|
683
|
+
type: unknown;
|
|
684
|
+
}
|
|
685
|
+
interface PickOutputType {
|
|
686
|
+
outputType: unknown;
|
|
687
|
+
}
|
|
688
|
+
interface PickOutputTypeAndOperators {
|
|
689
|
+
outputType: unknown;
|
|
690
|
+
operators: unknown;
|
|
691
|
+
}
|
|
692
|
+
interface QueryColumn<T = unknown, Op = any> {
|
|
693
|
+
dataType: string;
|
|
694
|
+
type: T;
|
|
695
|
+
outputType: T;
|
|
696
|
+
queryType: T;
|
|
697
|
+
operators: Op;
|
|
698
|
+
}
|
|
699
|
+
interface QueryColumnOfDataType<DataType extends string> extends QueryColumn {
|
|
700
|
+
dataType: DataType;
|
|
701
|
+
}
|
|
702
|
+
interface QueryColumns {
|
|
703
|
+
[K: string]: QueryColumn;
|
|
704
|
+
}
|
|
705
|
+
interface QueryColumnData {
|
|
706
|
+
explicitSelect?: boolean;
|
|
707
|
+
primaryKey?: string;
|
|
708
|
+
unique?: string;
|
|
709
|
+
optional?: true;
|
|
710
|
+
isNullable?: true;
|
|
711
|
+
default?: unknown;
|
|
712
|
+
name?: string;
|
|
713
|
+
readOnly?: boolean;
|
|
714
|
+
appReadOnly: true | undefined;
|
|
715
|
+
}
|
|
716
|
+
interface QueryColumnInit extends QueryColumn {
|
|
717
|
+
inputType: unknown;
|
|
718
|
+
data: QueryColumnData;
|
|
719
|
+
}
|
|
720
|
+
interface QueryColumnsInit {
|
|
721
|
+
[K: string]: QueryColumnInit;
|
|
722
|
+
}
|
|
723
|
+
type QueryColumnToNullable<C extends QueryColumn> = {
|
|
724
|
+
[K in keyof C]: K extends 'outputType' | 'queryType' ? C[K] | null : C[K];
|
|
725
|
+
};
|
|
726
|
+
interface ColumnToCodeCtx {
|
|
727
|
+
t: string;
|
|
728
|
+
table: string;
|
|
729
|
+
currentSchema: string;
|
|
730
|
+
migration?: boolean;
|
|
731
|
+
snakeCase?: boolean;
|
|
732
|
+
}
|
|
733
|
+
declare abstract class ColumnTypeBase<Schema extends ColumnTypeSchemaArg = ColumnTypeSchemaArg, Type = unknown, InputSchema = any, Ops = any, InputType = Type, OutputType = Type, OutputSchema = InputSchema, QueryType = InputType, QuerySchema = InputSchema, Data extends ColumnDataBase = ColumnDataBase> {
|
|
734
|
+
inputSchema: InputSchema;
|
|
735
|
+
outputSchema: OutputSchema;
|
|
736
|
+
querySchema: QuerySchema;
|
|
737
|
+
abstract dataType: string;
|
|
738
|
+
abstract operators: Ops;
|
|
739
|
+
abstract toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
740
|
+
abstract toSQL(): string;
|
|
741
|
+
type: Type;
|
|
742
|
+
inputType: InputType;
|
|
743
|
+
outputType: OutputType;
|
|
744
|
+
queryType: QueryType;
|
|
745
|
+
nullType: unknown;
|
|
746
|
+
nullSchema: unknown;
|
|
747
|
+
isNullable: boolean;
|
|
748
|
+
data: Data;
|
|
749
|
+
error: Schema['error'];
|
|
750
|
+
_parse?: (input: unknown) => unknown;
|
|
751
|
+
constructor(schema: ColumnTypeSchemaArg, inputSchema: InputSchema, outputSchema?: OutputSchema, querySchema?: QuerySchema);
|
|
752
|
+
/**
|
|
753
|
+
* Set a default value to a column. Columns that have defaults become optional when creating a record.
|
|
754
|
+
*
|
|
755
|
+
* If you provide a value or a raw SQL, such default should be set on the column in migration to be applied on a database level.
|
|
756
|
+
*
|
|
757
|
+
* Or you can specify a callback that returns a value. This function will be called for each creating record. Such a default won't be applied to a database.
|
|
758
|
+
*
|
|
759
|
+
* ```ts
|
|
760
|
+
* export class Table extends BaseTable {
|
|
761
|
+
* readonly table = 'table';
|
|
762
|
+
* columns = this.setColumns((t) => ({
|
|
763
|
+
* // values as defaults:
|
|
764
|
+
* int: t.integer().default(123),
|
|
765
|
+
* text: t.text().default('text'),
|
|
766
|
+
*
|
|
767
|
+
* // raw SQL default:
|
|
768
|
+
* timestamp: t.timestamp().default(t.sql`now()`),
|
|
769
|
+
*
|
|
770
|
+
* // runtime default, each new records gets a new random value:
|
|
771
|
+
* random: t.numeric().default(() => Math.random()),
|
|
772
|
+
* }));
|
|
773
|
+
* }
|
|
774
|
+
* ```
|
|
775
|
+
*
|
|
776
|
+
* @param value - default value or a function returning a value
|
|
777
|
+
*/
|
|
778
|
+
default<T extends Pick<ColumnTypeBase, 'type' | 'inputType' | 'data'>, Value extends T['inputType'] | null | RawSQLBase | (() => T['inputType'])>(this: T, value: Value): ColumnWithDefault<T, Value>;
|
|
779
|
+
/**
|
|
780
|
+
* Use `hasDefault` to let the column be omitted when creating records.
|
|
781
|
+
*
|
|
782
|
+
* It's better to use {@link default} instead so the value is explicit and serves as a hint.
|
|
783
|
+
*/
|
|
784
|
+
hasDefault<T extends PickColumnBaseData>(this: T): ColumnWithDefault<T, RawSQLBase>;
|
|
785
|
+
/**
|
|
786
|
+
* Set a database-level validation check to a column. `check` accepts a raw SQL.
|
|
787
|
+
*
|
|
788
|
+
* ```ts
|
|
789
|
+
* import { change } from '../dbScript';
|
|
790
|
+
*
|
|
791
|
+
* change(async (db) => {
|
|
792
|
+
* await db.createTable('table', (t) => ({
|
|
793
|
+
* // validate rank to be from 1 to 10
|
|
794
|
+
* rank: t.integer().check(t.sql`1 >= "rank" AND "rank" <= 10`),
|
|
795
|
+
* // constraint name can be passed as a second argument
|
|
796
|
+
* column: t.integer().check(t.sql`...`, 'check_name'),
|
|
797
|
+
* // a single column can have multiple checks
|
|
798
|
+
* multiChecksColumn: t
|
|
799
|
+
* .integer()
|
|
800
|
+
* .check(t.sql`...`)
|
|
801
|
+
* .check(t.sql`...`, 'optional_name'),
|
|
802
|
+
* }));
|
|
803
|
+
* });
|
|
804
|
+
* ```
|
|
805
|
+
*
|
|
806
|
+
* @param sql - raw SQL expression
|
|
807
|
+
* @param name - to specify a constraint name
|
|
808
|
+
*/
|
|
809
|
+
check<T extends PickColumnBaseData>(this: T, sql: RawSQLBase, name?: string): T;
|
|
810
|
+
/**
|
|
811
|
+
* Use `nullable` to mark the column as nullable. By default, all columns are required.
|
|
812
|
+
*
|
|
813
|
+
* Nullable columns are optional when creating records.
|
|
814
|
+
*
|
|
815
|
+
* ```ts
|
|
816
|
+
* export class Table extends BaseTable {
|
|
817
|
+
* readonly table = 'table';
|
|
818
|
+
* columns = this.setColumns((t) => ({
|
|
819
|
+
* name: t.integer().nullable(),
|
|
820
|
+
* }));
|
|
821
|
+
* }
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
824
|
+
nullable: Schema['nullable'];
|
|
825
|
+
/**
|
|
826
|
+
* Set a custom function to process value for the column when creating or updating a record.
|
|
827
|
+
*
|
|
828
|
+
* The type of `input` argument will be used as the type of the column when creating and updating.
|
|
829
|
+
*
|
|
830
|
+
* If you have a validation library [installed and configured](/guide/columns-validation-methods.html),
|
|
831
|
+
* first argument is a schema to validate the input.
|
|
832
|
+
*
|
|
833
|
+
* ```ts
|
|
834
|
+
* import { z } from 'zod';
|
|
835
|
+
*
|
|
836
|
+
* export class Table extends BaseTable {
|
|
837
|
+
* readonly table = 'table';
|
|
838
|
+
* columns = this.setColumns((t) => ({
|
|
839
|
+
* // encode boolean, number, or string to text before saving
|
|
840
|
+
* column: t
|
|
841
|
+
* .string()
|
|
842
|
+
* // when having validation library, the first argument is a validation schema
|
|
843
|
+
* .encode(
|
|
844
|
+
* z.boolean().or(z.number()).or(z.string()),
|
|
845
|
+
* (input: boolean | number | string) => String(input),
|
|
846
|
+
* )
|
|
847
|
+
* // no schema argument otherwise
|
|
848
|
+
* .encode((input: boolean | number | string) => String(input)),
|
|
849
|
+
* }));
|
|
850
|
+
* }
|
|
851
|
+
*
|
|
852
|
+
* // numbers and booleans will be converted to a string:
|
|
853
|
+
* await db.table.create({ column: 123 });
|
|
854
|
+
* await db.table.create({ column: true });
|
|
855
|
+
* await db.table.where({ column: 'true' }).update({ column: false });
|
|
856
|
+
* ```
|
|
857
|
+
*
|
|
858
|
+
* @param fn - function to encode value for a database, argument type is specified by you, return type must be compatible with a database
|
|
859
|
+
*/
|
|
860
|
+
encode: Schema['encode'];
|
|
861
|
+
/**
|
|
862
|
+
* Set a custom function to process value after loading it from a database.
|
|
863
|
+
*
|
|
864
|
+
* The type of input is the type of column before `.parse`, the resulting type will replace the type of column.
|
|
865
|
+
*
|
|
866
|
+
* If you have a validation library [installed and configured](/guide/columns-validation-methods.html),
|
|
867
|
+
* first argument is a schema for validating the output.
|
|
868
|
+
*
|
|
869
|
+
* For handling `null` values use {@link parseNull} instead or in addition.
|
|
870
|
+
*
|
|
871
|
+
* ```ts
|
|
872
|
+
* import { z } from 'zod';
|
|
873
|
+
* import { number, integer } from 'valibot';
|
|
874
|
+
*
|
|
875
|
+
* export class Table extends BaseTable {
|
|
876
|
+
* readonly table = 'table';
|
|
877
|
+
* columns = this.setColumns((t) => ({
|
|
878
|
+
* columnZod: t
|
|
879
|
+
* .string()
|
|
880
|
+
* // when having validation library, the first argument is a schema
|
|
881
|
+
* .parse(z.number().int(), (input) => parseInt(input))
|
|
882
|
+
* // no schema argument otherwise
|
|
883
|
+
* .parse((input) => parseInt(input)),
|
|
884
|
+
*
|
|
885
|
+
* columnValibot: t
|
|
886
|
+
* .string()
|
|
887
|
+
* .parse(number([integer()]), (input) => parseInt(input))
|
|
888
|
+
* .parse((input) => parseInt(input)),
|
|
889
|
+
* }));
|
|
890
|
+
* }
|
|
891
|
+
*
|
|
892
|
+
* // column will be parsed to a number
|
|
893
|
+
* const value: number = await db.table.get('column');
|
|
894
|
+
* ```
|
|
895
|
+
*
|
|
896
|
+
* @param fn - function to parse a value from the database, argument is the type of this column, return type is up to you
|
|
897
|
+
*/
|
|
898
|
+
parse: Schema['parse'];
|
|
899
|
+
/**
|
|
900
|
+
* Use `parseNull` to specify runtime defaults at selection time.
|
|
901
|
+
*
|
|
902
|
+
* The `parseNull` function is only triggered for `nullable` columns.
|
|
903
|
+
*
|
|
904
|
+
* ```ts
|
|
905
|
+
* export class Table extends BaseTable {
|
|
906
|
+
* readonly table = 'table';
|
|
907
|
+
* columns = this.setColumns((t) => ({
|
|
908
|
+
* column: t
|
|
909
|
+
* .integer()
|
|
910
|
+
* .parse(String) // parse non-nulls to string
|
|
911
|
+
* .parseNull(() => false), // replace nulls with false
|
|
912
|
+
* .nullable(),
|
|
913
|
+
* }));
|
|
914
|
+
* }
|
|
915
|
+
*
|
|
916
|
+
* const record = await db.table.take()
|
|
917
|
+
* record.column // can be a string or boolean, not null
|
|
918
|
+
* ```
|
|
919
|
+
*
|
|
920
|
+
* If you have a validation library [installed and configured](/guide/columns-validation-methods),
|
|
921
|
+
* first argument is a schema for validating the output.
|
|
922
|
+
*
|
|
923
|
+
* ```ts
|
|
924
|
+
* export class Table extends BaseTable {
|
|
925
|
+
* readonly table = 'table';
|
|
926
|
+
* columns = this.setColumns((t) => ({
|
|
927
|
+
* column: t
|
|
928
|
+
* .integer()
|
|
929
|
+
* .parse(z.string(), String) // parse non-nulls to string
|
|
930
|
+
* .parseNull(z.literal(false), () => false), // replace nulls with false
|
|
931
|
+
* .nullable(),
|
|
932
|
+
* }));
|
|
933
|
+
* }
|
|
934
|
+
*
|
|
935
|
+
* const record = await db.table.take()
|
|
936
|
+
* record.column // can be a string or boolean, not null
|
|
937
|
+
*
|
|
938
|
+
* Table.outputSchema().parse({
|
|
939
|
+
* column: false, // the schema expects strings or `false` literals, not nulls
|
|
940
|
+
* })
|
|
941
|
+
* ```
|
|
942
|
+
*/
|
|
943
|
+
parseNull: Schema['parseNull'];
|
|
944
|
+
/**
|
|
945
|
+
* This method changes a column type without modifying its behavior.
|
|
946
|
+
* This is needed when converting columns to a validation schema, the converter will pick a different type specified by `.as`.
|
|
947
|
+
*
|
|
948
|
+
* Before calling `.as` need to use `.encode` with the input of the same type as the input of the target column,
|
|
949
|
+
* and `.parse` which returns the correct type.
|
|
950
|
+
*
|
|
951
|
+
* ```ts
|
|
952
|
+
* // column has the same type as t.integer()
|
|
953
|
+
* const column = t
|
|
954
|
+
* .string()
|
|
955
|
+
* .encode((input: number) => input)
|
|
956
|
+
* .parse((text) => parseInt(text))
|
|
957
|
+
* .as(t.integer());
|
|
958
|
+
* ```
|
|
959
|
+
*
|
|
960
|
+
* @param column - other column type to inherit from
|
|
961
|
+
*/
|
|
962
|
+
as<T extends {
|
|
963
|
+
inputType: unknown;
|
|
964
|
+
outputType: unknown;
|
|
965
|
+
data: ColumnDataBase;
|
|
966
|
+
}, C extends Omit<ColumnTypeBase, 'inputType' | 'outputType'> & {
|
|
967
|
+
inputType: T['inputType'];
|
|
968
|
+
outputType: T['outputType'];
|
|
969
|
+
}>(this: T, column: C): C;
|
|
970
|
+
/**
|
|
971
|
+
* @deprecated use narrowType instead
|
|
972
|
+
*/
|
|
973
|
+
asType: Schema['asType'];
|
|
974
|
+
/**
|
|
975
|
+
* `narrowType` narrows TypeScript types of a column. It sets input, output, query type altogether.
|
|
976
|
+
*
|
|
977
|
+
* For example, to narrow a `string` type to a union of string literals.
|
|
978
|
+
*
|
|
979
|
+
* When _not_ integrating with [validation libraries](/guide/columns-validation-methods), `narrowType` has the following syntax:
|
|
980
|
+
*
|
|
981
|
+
* ```ts
|
|
982
|
+
* export class Table extends BaseTable {
|
|
983
|
+
* readonly table = 'table';
|
|
984
|
+
* columns = this.setColumns((t) => ({
|
|
985
|
+
* size: t.string().narrowType((t) => t<'small' | 'medium' | 'large'>()),
|
|
986
|
+
* }));
|
|
987
|
+
* }
|
|
988
|
+
*
|
|
989
|
+
* // size will be typed as 'small' | 'medium' | 'large'
|
|
990
|
+
* const size = await db.table.get('size');
|
|
991
|
+
* ```
|
|
992
|
+
*
|
|
993
|
+
* - `input` is for `create`, `update` methods.
|
|
994
|
+
* - `output` is for the data that is loaded from a database and parsed if the column has `parse`.
|
|
995
|
+
* - `query` is used in `where` and other query methods, it should be compatible with the actual database column type.
|
|
996
|
+
*
|
|
997
|
+
* When integrating with a [validation library](/guide/columns-validation-methods), also provide validation schemas:
|
|
998
|
+
*
|
|
999
|
+
* ```ts
|
|
1000
|
+
* const sizeSchema = z.union([
|
|
1001
|
+
* z.literal('small'),
|
|
1002
|
+
* z.literal('medium'),
|
|
1003
|
+
* z.literal('large'),
|
|
1004
|
+
* ]);
|
|
1005
|
+
*
|
|
1006
|
+
* export class Table extends BaseTable {
|
|
1007
|
+
* readonly table = 'table';
|
|
1008
|
+
* columns = this.setColumns((t) => ({
|
|
1009
|
+
* size: t.text().narrowType(sizeSchema),
|
|
1010
|
+
* }));
|
|
1011
|
+
* }
|
|
1012
|
+
*
|
|
1013
|
+
* // size will be typed as 'small' | 'medium' | 'large'
|
|
1014
|
+
* const size = await db.table.get('size');
|
|
1015
|
+
* ```
|
|
1016
|
+
*/
|
|
1017
|
+
narrowType: Schema['narrowType'];
|
|
1018
|
+
/**
|
|
1019
|
+
* Allows to narrow different TypeScript types of a column granularly.
|
|
1020
|
+
*
|
|
1021
|
+
* Use it when the column's input is different from output.
|
|
1022
|
+
*
|
|
1023
|
+
* When _not_ integrating with [validation libraries](/guide/columns-validation-methods), `narrowAllTypes` has the following syntax:
|
|
1024
|
+
*
|
|
1025
|
+
* ```ts
|
|
1026
|
+
* export class Table extends BaseTable {
|
|
1027
|
+
* readonly table = 'table';
|
|
1028
|
+
* columns = this.setColumns((t) => ({
|
|
1029
|
+
* size: t.string().narrowAllTypes((t) =>
|
|
1030
|
+
* t<{
|
|
1031
|
+
* // what types are accepted when creating/updating
|
|
1032
|
+
* input: 'small' | 'medium' | 'large';
|
|
1033
|
+
* // how types are retured from a database
|
|
1034
|
+
* output: 'small' | 'medium' | 'large';
|
|
1035
|
+
* // what types the column accepts in `where` and similar
|
|
1036
|
+
* query: 'small' | 'medium' | 'large';
|
|
1037
|
+
* }>(),
|
|
1038
|
+
* ),
|
|
1039
|
+
* }));
|
|
1040
|
+
* }
|
|
1041
|
+
*
|
|
1042
|
+
* // size will be typed as 'small' | 'medium' | 'large'
|
|
1043
|
+
* const size = await db.table.get('size');
|
|
1044
|
+
* ```
|
|
1045
|
+
*
|
|
1046
|
+
* - `input` is for `create`, `update` methods.
|
|
1047
|
+
* - `output` is for the data that is loaded from a database and parsed if the column has `parse`.
|
|
1048
|
+
* - `query` is used in `where` and other query methods, it should be compatible with the actual database column type.
|
|
1049
|
+
*
|
|
1050
|
+
* When integrating with a [validation library](/guide/columns-validation-methods), also provide validation schemas:
|
|
1051
|
+
*
|
|
1052
|
+
* ```ts
|
|
1053
|
+
* const sizeSchema = z.union([
|
|
1054
|
+
* z.literal('small'),
|
|
1055
|
+
* z.literal('medium'),
|
|
1056
|
+
* z.literal('large'),
|
|
1057
|
+
* ]);
|
|
1058
|
+
*
|
|
1059
|
+
* export class Table extends BaseTable {
|
|
1060
|
+
* readonly table = 'table';
|
|
1061
|
+
* columns = this.setColumns((t) => ({
|
|
1062
|
+
* size: t.text().narrowAllTypes({
|
|
1063
|
+
* input: sizeSchema,
|
|
1064
|
+
* output: sizeSchema,
|
|
1065
|
+
* query: sizeSchema,
|
|
1066
|
+
* }),
|
|
1067
|
+
* }));
|
|
1068
|
+
* }
|
|
1069
|
+
*
|
|
1070
|
+
* // size will be typed as 'small' | 'medium' | 'large'
|
|
1071
|
+
* const size = await db.table.get('size');
|
|
1072
|
+
* ```
|
|
1073
|
+
*/
|
|
1074
|
+
narrowAllTypes: Schema['narrowAllTypes'];
|
|
1075
|
+
input<T extends {
|
|
1076
|
+
inputSchema: unknown;
|
|
1077
|
+
}, InputSchema extends Schema['type']>(this: T, fn: (schema: T['inputSchema']) => InputSchema): {
|
|
1078
|
+
[K in keyof T]: K extends 'inputSchema' ? InputSchema : T[K];
|
|
1079
|
+
};
|
|
1080
|
+
output<T extends {
|
|
1081
|
+
outputSchema: unknown;
|
|
1082
|
+
}, OutputSchema extends Schema['type']>(this: T, fn: (schema: T['outputSchema']) => OutputSchema): {
|
|
1083
|
+
[K in keyof T]: K extends 'outputSchema' ? OutputSchema : T[K];
|
|
1084
|
+
};
|
|
1085
|
+
query<T extends {
|
|
1086
|
+
querySchema: unknown;
|
|
1087
|
+
}, QuerySchema extends Schema['type']>(this: T, fn: (schema: T['querySchema']) => QuerySchema): {
|
|
1088
|
+
[K in keyof T]: K extends 'querySchema' ? QuerySchema : T[K];
|
|
1089
|
+
};
|
|
1090
|
+
/**
|
|
1091
|
+
* Set a database column name.
|
|
1092
|
+
*
|
|
1093
|
+
* @param name - name of the column in database.
|
|
1094
|
+
*/
|
|
1095
|
+
name<T extends PickColumnBaseData>(this: T, name: string): T;
|
|
1096
|
+
/**
|
|
1097
|
+
* Append `select(false)` to a column to exclude it from the default selection.
|
|
1098
|
+
* It won't be selected with `selectAll` or `select('*')` as well.
|
|
1099
|
+
*
|
|
1100
|
+
* ```ts
|
|
1101
|
+
* export class UserTable extends BaseTable {
|
|
1102
|
+
* readonly table = 'user';
|
|
1103
|
+
* columns = this.setColumns((t) => ({
|
|
1104
|
+
* id: t.identity().primaryKey(),
|
|
1105
|
+
* name: t.string(),
|
|
1106
|
+
* password: t.string().select(false),
|
|
1107
|
+
* }));
|
|
1108
|
+
* }
|
|
1109
|
+
*
|
|
1110
|
+
* // only id and name are selected, without password
|
|
1111
|
+
* const user = await db.user.find(123);
|
|
1112
|
+
*
|
|
1113
|
+
* // password is still omitted, even with the wildcard
|
|
1114
|
+
* const same = await db.user.find(123).select('*');
|
|
1115
|
+
*
|
|
1116
|
+
* const comment = await db.comment.find(123).select({
|
|
1117
|
+
* // password is omitted in the sub-selects as well
|
|
1118
|
+
* author: (q) => q.author,
|
|
1119
|
+
* });
|
|
1120
|
+
*
|
|
1121
|
+
* // password is omitted here as well
|
|
1122
|
+
* const created = await db.user.create(userData);
|
|
1123
|
+
* ```
|
|
1124
|
+
*
|
|
1125
|
+
* Such a column can only be selected explicitly.
|
|
1126
|
+
*
|
|
1127
|
+
* ```ts
|
|
1128
|
+
* const userWithPassword = await db.user.find(123).select('*', 'password');
|
|
1129
|
+
* ```
|
|
1130
|
+
*/
|
|
1131
|
+
select<T extends PickColumnBaseData, Value extends boolean>(this: T, value: Value): ColumnDefaultSelect<T, Value>;
|
|
1132
|
+
/**
|
|
1133
|
+
* Forbid the column to be used in [create](/guide/create-update-delete.html#create-insert) and [update](/guide/create-update-delete.html#update) methods.
|
|
1134
|
+
*
|
|
1135
|
+
* `readOnly` column is still can be set from a [hook](http://localhost:5173/guide/hooks.html#set-values-before-create-or-update).
|
|
1136
|
+
*
|
|
1137
|
+
* `readOnly` column can be used together with a `default`.
|
|
1138
|
+
*
|
|
1139
|
+
* ```ts
|
|
1140
|
+
* export class Table extends BaseTable {
|
|
1141
|
+
* readonly table = 'table';
|
|
1142
|
+
* columns = this.setColumns((t) => ({
|
|
1143
|
+
* id: t.identity().primaryKey(),
|
|
1144
|
+
* column: t.string().default(() => 'default value'),
|
|
1145
|
+
* another: t.string().readOnly(),
|
|
1146
|
+
* }));
|
|
1147
|
+
*
|
|
1148
|
+
* init(orm: typeof db) {
|
|
1149
|
+
* this.beforeSave(({ set }) => {
|
|
1150
|
+
* set({ another: 'value' });
|
|
1151
|
+
* });
|
|
1152
|
+
* }
|
|
1153
|
+
* }
|
|
1154
|
+
*
|
|
1155
|
+
* // later in the code
|
|
1156
|
+
* db.table.create({ column: 'value' }); // TS error, runtime error
|
|
1157
|
+
* ```
|
|
1158
|
+
*/
|
|
1159
|
+
readOnly<T>(this: T): T & ColumnDataAppReadOnly;
|
|
1160
|
+
/**
|
|
1161
|
+
* Set a column value when creating a record.
|
|
1162
|
+
* This works for [readOnly](#readonly) columns as well.
|
|
1163
|
+
*
|
|
1164
|
+
* If no value or undefined is returned, the hook won't have any effect.
|
|
1165
|
+
*
|
|
1166
|
+
* ```ts
|
|
1167
|
+
* export class Table extends BaseTable {
|
|
1168
|
+
* readonly table = 'table';
|
|
1169
|
+
* columns = this.setColumns((t) => ({
|
|
1170
|
+
* id: t.identity().primaryKey(),
|
|
1171
|
+
* column: t.string().setOnCreate(() => 'value'),
|
|
1172
|
+
* }));
|
|
1173
|
+
* }
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
setOnCreate<T extends QueryColumnInit>(this: T, fn: (arg: QueryHookUtils<PickQueryInputType>) => T['inputType'] | void): T;
|
|
1177
|
+
/**
|
|
1178
|
+
* Set a column value when updating a record.
|
|
1179
|
+
* This works for [readOnly](#readonly) columns as well.
|
|
1180
|
+
*
|
|
1181
|
+
* If no value or undefined is returned, the hook won't have any effect.
|
|
1182
|
+
*
|
|
1183
|
+
* ```ts
|
|
1184
|
+
* export class Table extends BaseTable {
|
|
1185
|
+
* readonly table = 'table';
|
|
1186
|
+
* columns = this.setColumns((t) => ({
|
|
1187
|
+
* id: t.identity().primaryKey(),
|
|
1188
|
+
* column: t.string().setOnUpdate(() => 'value'),
|
|
1189
|
+
* }));
|
|
1190
|
+
* }
|
|
1191
|
+
* ```
|
|
1192
|
+
*/
|
|
1193
|
+
setOnUpdate<T extends QueryColumnInit>(this: T, fn: (arg: QueryHookUtils<PickQueryInputType>) => T['inputType'] | void): T;
|
|
1194
|
+
/**
|
|
1195
|
+
* Set a column value when creating or updating a record.
|
|
1196
|
+
* This works for [readOnly](#readonly) columns as well.
|
|
1197
|
+
*
|
|
1198
|
+
* If no value or undefined is returned, the hook won't have any effect.
|
|
1199
|
+
*
|
|
1200
|
+
* ```ts
|
|
1201
|
+
* export class Table extends BaseTable {
|
|
1202
|
+
* readonly table = 'table';
|
|
1203
|
+
* columns = this.setColumns((t) => ({
|
|
1204
|
+
* id: t.identity().primaryKey(),
|
|
1205
|
+
* column: t.string().setOnSave(() => 'value'),
|
|
1206
|
+
* }));
|
|
1207
|
+
* }
|
|
1208
|
+
* ```
|
|
1209
|
+
*/
|
|
1210
|
+
setOnSave<T extends QueryColumnInit>(this: T, fn: (arg: QueryHookUtils<PickQueryInputType>) => T['inputType'] | void): T;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
interface BaseNumberData extends ColumnDataBase {
|
|
1214
|
+
lt?: number;
|
|
1215
|
+
lte?: number;
|
|
1216
|
+
gt?: number;
|
|
1217
|
+
gte?: number;
|
|
1218
|
+
step?: number;
|
|
1219
|
+
int?: boolean;
|
|
1220
|
+
finite?: boolean;
|
|
1221
|
+
safe?: boolean;
|
|
1222
|
+
}
|
|
1223
|
+
interface StringTypeData extends ColumnDataBase {
|
|
1224
|
+
min?: number;
|
|
1225
|
+
max?: number;
|
|
1226
|
+
length?: number;
|
|
1227
|
+
email?: boolean;
|
|
1228
|
+
url?: boolean;
|
|
1229
|
+
emoji?: boolean;
|
|
1230
|
+
uuid?: boolean;
|
|
1231
|
+
cuid?: boolean;
|
|
1232
|
+
cuid2?: boolean;
|
|
1233
|
+
ulid?: boolean;
|
|
1234
|
+
regex?: RegExp;
|
|
1235
|
+
includes?: string;
|
|
1236
|
+
startsWith?: string;
|
|
1237
|
+
endsWith?: string;
|
|
1238
|
+
datetime?: {
|
|
1239
|
+
offset?: boolean;
|
|
1240
|
+
precision?: number;
|
|
1241
|
+
};
|
|
1242
|
+
ipv4?: true;
|
|
1243
|
+
ipv6?: true;
|
|
1244
|
+
nonEmpty?: boolean;
|
|
1245
|
+
trim?: boolean;
|
|
1246
|
+
toLowerCase?: boolean;
|
|
1247
|
+
toUpperCase?: boolean;
|
|
1248
|
+
}
|
|
1249
|
+
interface DateColumnData extends ColumnDataBase {
|
|
1250
|
+
min?: Date;
|
|
1251
|
+
max?: Date;
|
|
1252
|
+
}
|
|
1253
|
+
interface ArrayMethodsData {
|
|
1254
|
+
min?: number;
|
|
1255
|
+
max?: number;
|
|
1256
|
+
length?: number;
|
|
1257
|
+
nonEmpty?: boolean;
|
|
1258
|
+
}
|
|
1259
|
+
interface ArrayMethodsDataForBaseColumn extends ColumnDataBase, ArrayMethodsData {
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
type Code = string | Codes;
|
|
1263
|
+
type Codes = Code[];
|
|
1264
|
+
/**
|
|
1265
|
+
* Push code: this will append a code string to the last code array element when possible.
|
|
1266
|
+
* @param code - array of code to push into
|
|
1267
|
+
* @param add - code to push
|
|
1268
|
+
*/
|
|
1269
|
+
declare const addCode: (code: Code[], add: Code) => void;
|
|
1270
|
+
/**
|
|
1271
|
+
* Convert the code item into string.
|
|
1272
|
+
*
|
|
1273
|
+
* @param code - code item
|
|
1274
|
+
* @param tabs - each new line will be prefixed with the tabs. Each element of the code represents a new line
|
|
1275
|
+
* @param shift - array elements of the given code will be shifted with this sting
|
|
1276
|
+
*/
|
|
1277
|
+
declare const codeToString: (code: Code, tabs: string, shift: string) => string;
|
|
1278
|
+
/**
|
|
1279
|
+
* Convert a column default value into code string.
|
|
1280
|
+
*
|
|
1281
|
+
* @param t - column types variable name
|
|
1282
|
+
* @param value - column default
|
|
1283
|
+
*/
|
|
1284
|
+
declare const columnDefaultArgumentToCode: (t: string, value: unknown) => string;
|
|
1285
|
+
declare const stringDataToCode: (data: StringTypeData, migration: boolean | undefined, skipLocal?: RecordKeyTrue) => string;
|
|
1286
|
+
declare const numberDataToCode: (data: BaseNumberData, migration: boolean | undefined, skipLocal?: RecordKeyTrue) => string;
|
|
1287
|
+
declare const dateDataToCode: (data: DateColumnData, migration: boolean | undefined, skipLocal?: RecordKeyTrue) => string;
|
|
1288
|
+
declare const arrayDataToCode: (data: ArrayMethodsDataForBaseColumn, migration: boolean | undefined, skipLocal?: RecordKeyTrue) => string;
|
|
1289
|
+
/**
|
|
1290
|
+
* Converts column type and JSON type custom errors into code
|
|
1291
|
+
*
|
|
1292
|
+
* @param errors - custom error messages
|
|
1293
|
+
*/
|
|
1294
|
+
declare const columnErrorMessagesToCode: (errors: RecordString) => Code;
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Symbol that turns on a snake case column names.
|
|
1298
|
+
* It is set on the column types.
|
|
1299
|
+
* When it's on, column names in ORM are still as user types them, but they are translated to snake_case when generating SQL.
|
|
1300
|
+
*/
|
|
1301
|
+
declare const snakeCaseKey: unique symbol;
|
|
1302
|
+
interface TimeInterval {
|
|
1303
|
+
years?: number;
|
|
1304
|
+
months?: number;
|
|
1305
|
+
days?: number;
|
|
1306
|
+
hours?: number;
|
|
1307
|
+
minutes?: number;
|
|
1308
|
+
seconds?: number;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
interface Timestamps<T extends ColumnTypeBase> {
|
|
1312
|
+
createdAt: ColumnWithDefault<T, RawSQLBase>;
|
|
1313
|
+
updatedAt: ColumnWithDefault<T, RawSQLBase>;
|
|
1314
|
+
}
|
|
1315
|
+
interface TimestampHelpers {
|
|
1316
|
+
/**
|
|
1317
|
+
* Add `createdAt` and `updatedAt` timestamps. Both have `now()` as a default, `updatedAt` is automatically updated during update.
|
|
1318
|
+
*/
|
|
1319
|
+
timestamps<T extends ColumnTypeBase>(this: {
|
|
1320
|
+
timestamp(): T;
|
|
1321
|
+
}): Timestamps<T>;
|
|
1322
|
+
/**
|
|
1323
|
+
* The same as {@link timestamps}, for the timestamp without time zone time.
|
|
1324
|
+
*/
|
|
1325
|
+
timestampsNoTZ<T extends ColumnTypeBase>(this: {
|
|
1326
|
+
timestampNoTZ(): T;
|
|
1327
|
+
}): Timestamps<T>;
|
|
1328
|
+
}
|
|
1329
|
+
declare const timestampHelpers: TimestampHelpers;
|
|
1330
|
+
|
|
1331
|
+
type DelayedRelationSelect = {
|
|
1332
|
+
query: QueryBase;
|
|
1333
|
+
value?: {
|
|
1334
|
+
[K: string]: IsQuery;
|
|
1335
|
+
};
|
|
1336
|
+
};
|
|
1337
|
+
declare const newDelayedRelationSelect: (query: QueryBase) => {
|
|
1338
|
+
query: QueryBase;
|
|
1339
|
+
};
|
|
1340
|
+
declare const setDelayedRelation: (d: DelayedRelationSelect, as: string, value: IsQuery) => void;
|
|
1341
|
+
|
|
1342
|
+
interface QueryInternalColumnNameToKey {
|
|
1343
|
+
columnNameToKeyMap?: Map<string, string>;
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* In snake case mode, or when columns have custom names,
|
|
1347
|
+
* use this method to exchange a db column name to its runtime key.
|
|
1348
|
+
*/
|
|
1349
|
+
declare const queryColumnNameToKey: (q: QueryBase, name: string) => string | undefined;
|
|
1350
|
+
|
|
1351
|
+
interface PickQueryDataAliases {
|
|
1352
|
+
aliases?: RecordString;
|
|
1353
|
+
}
|
|
1354
|
+
interface QueryDataAliases extends PickQueryDataAliases {
|
|
1355
|
+
as?: string;
|
|
1356
|
+
outerAliases?: RecordString;
|
|
1357
|
+
}
|
|
1358
|
+
type AliasOrTable<T extends PickQueryMetaTable> = T['meta']['as'] extends string ? T['meta']['as'] : T['table'] extends string ? T['table'] : never;
|
|
1359
|
+
type SetQueryTableAlias<T extends PickQueryMetaTableShape, As extends string> = {
|
|
1360
|
+
[K in keyof T]: K extends 'meta' ? {
|
|
1361
|
+
[K in keyof T['meta'] | 'as']: K extends 'as' ? As : K extends 'selectable' ? Omit<T['meta']['selectable'], `${AliasOrTable<T>}.${keyof T['shape'] & string}`> & {
|
|
1362
|
+
[K in keyof T['shape'] & string as `${As}.${K}`]: {
|
|
1363
|
+
as: K;
|
|
1364
|
+
column: T['shape'][K];
|
|
1365
|
+
};
|
|
1366
|
+
} : T['meta'][K];
|
|
1367
|
+
} : T[K];
|
|
1368
|
+
};
|
|
1369
|
+
type AsQueryArg = PickQueryMetaTableShape;
|
|
1370
|
+
/** getters **/
|
|
1371
|
+
declare const _getQueryAs: (q: QueryBase) => string | undefined;
|
|
1372
|
+
declare const _getQueryFreeAlias: (q: QueryDataAliases, as: string) => string;
|
|
1373
|
+
declare const _checkIfAliased: (q: QueryBase, as: string, name: string) => boolean;
|
|
1374
|
+
declare const _getQueryAliasOrName: (q: PickQueryDataAliases, as: string) => string;
|
|
1375
|
+
declare const _getQueryOuterAliases: (q: QueryDataBase) => RecordString | undefined;
|
|
1376
|
+
/** setters **/
|
|
1377
|
+
declare const _setQueryAs: <T extends PickQueryMetaTableShape, As extends string>(self: T, as: As) => SetQueryTableAlias<T, As>;
|
|
1378
|
+
declare const _setQueryAlias: (q: QueryBase, name: string, as: string) => void;
|
|
1379
|
+
declare const _setSubQueryAliases: (q: QueryBase) => void;
|
|
1380
|
+
/**
|
|
1381
|
+
* Is used in `chain`: combines query and its relation aliases,
|
|
1382
|
+
* stores the result to the relation query data.
|
|
1383
|
+
*/
|
|
1384
|
+
declare const _applyRelationAliases: (query: QueryBase, relQueryData: QueryDataBase) => void;
|
|
1385
|
+
declare const _copyQueryAliasToQuery: (fromQuery: QueryBase, toQuery: QueryBase, key: string) => string;
|
|
1386
|
+
|
|
1387
|
+
interface HasCteHooks {
|
|
1388
|
+
cteHooks?: CteHooks;
|
|
1389
|
+
}
|
|
1390
|
+
interface CteHooks {
|
|
1391
|
+
hasSelect: boolean;
|
|
1392
|
+
tableHooks: CteTableHooks;
|
|
1393
|
+
}
|
|
1394
|
+
interface CteTableHooks {
|
|
1395
|
+
[K: string]: CteTableHook;
|
|
1396
|
+
}
|
|
1397
|
+
interface CteTableHook {
|
|
1398
|
+
shape: ColumnsShapeBase;
|
|
1399
|
+
tableHook: TableHook;
|
|
1400
|
+
}
|
|
1401
|
+
interface TableHook {
|
|
1402
|
+
select?: HookSelect;
|
|
1403
|
+
after?: ((data: unknown, query: any) => unknown | Promise<unknown>)[];
|
|
1404
|
+
afterCommit?: ((data: unknown, query: any) => unknown | Promise<unknown>)[];
|
|
1405
|
+
}
|
|
1406
|
+
type HookSelect = Map<string, HookSelectValue>;
|
|
1407
|
+
interface HookSelectValue {
|
|
1408
|
+
select: string | {
|
|
1409
|
+
sql: string;
|
|
1410
|
+
};
|
|
1411
|
+
as?: string;
|
|
1412
|
+
temp?: string;
|
|
1413
|
+
}
|
|
1414
|
+
interface HasTableHook {
|
|
1415
|
+
tableHook?: TableHook;
|
|
1416
|
+
}
|
|
1417
|
+
interface HasHookSelect {
|
|
1418
|
+
hookSelect?: HookSelect;
|
|
1419
|
+
}
|
|
1420
|
+
declare const _addToHookSelect: (query: IsQuery, selects: string[]) => void;
|
|
1421
|
+
declare const _addToHookSelectWithTable: (query: IsQuery, selects: string[], table: string) => void;
|
|
1422
|
+
|
|
1423
|
+
interface PickQueryDataParsers {
|
|
1424
|
+
defaultParsers?: ColumnsParsers;
|
|
1425
|
+
parsers?: ColumnsParsers;
|
|
1426
|
+
batchParsers?: BatchParsers;
|
|
1427
|
+
}
|
|
1428
|
+
type ColumnParser = FnUnknownToUnknown;
|
|
1429
|
+
interface BatchParser {
|
|
1430
|
+
path: string[];
|
|
1431
|
+
fn: (path: string[], queryResult: {
|
|
1432
|
+
rows: unknown[];
|
|
1433
|
+
}) => MaybePromise<void>;
|
|
1434
|
+
}
|
|
1435
|
+
type ColumnsParsers = {
|
|
1436
|
+
[K in string | getValueKey]?: ColumnParser;
|
|
1437
|
+
};
|
|
1438
|
+
type BatchParsers = BatchParser[];
|
|
1439
|
+
/**
|
|
1440
|
+
* generic utility to add a parser to the query object
|
|
1441
|
+
* @param query - the query object, it will be mutated
|
|
1442
|
+
* @param key - the name of the column in the data loaded by the query
|
|
1443
|
+
* @param parser - function to process the value of the column with.
|
|
1444
|
+
*/
|
|
1445
|
+
declare const setParserToQuery: (query: {
|
|
1446
|
+
parsers?: ColumnsParsers;
|
|
1447
|
+
}, key: string | getValueKey, parser: ColumnParser) => void;
|
|
1448
|
+
declare const getQueryParsers: (q: QueryBase, hookSelect?: HookSelect) => ColumnsParsers | undefined;
|
|
1449
|
+
|
|
1450
|
+
interface QueryDataBase extends QueryDataAliases, PickQueryDataParsers, HasHookSelect {
|
|
1451
|
+
shape: QueryColumnsInit;
|
|
1452
|
+
select?: unknown;
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
interface SqlCommonOptions extends HasTableHook, HasCteHooks {
|
|
1456
|
+
delayedRelationSelect?: DelayedRelationSelect;
|
|
1457
|
+
}
|
|
1458
|
+
interface SingleSqlItem {
|
|
1459
|
+
text: string;
|
|
1460
|
+
values?: unknown[];
|
|
1461
|
+
}
|
|
1462
|
+
interface SingleSql extends SingleSqlItem, SqlCommonOptions {
|
|
1463
|
+
}
|
|
1464
|
+
interface BatchSql extends SqlCommonOptions {
|
|
1465
|
+
batch: SingleSql[];
|
|
1466
|
+
}
|
|
1467
|
+
type Sql = SingleSql | BatchSql;
|
|
1468
|
+
interface QueryMetaBase<Scopes extends RecordKeyTrue = RecordKeyTrue> {
|
|
1469
|
+
kind: string;
|
|
1470
|
+
as?: string;
|
|
1471
|
+
subQuery: boolean;
|
|
1472
|
+
hasSelect?: true;
|
|
1473
|
+
hasWhere?: true;
|
|
1474
|
+
defaults: EmptyObject;
|
|
1475
|
+
tsQuery?: string;
|
|
1476
|
+
scopes: Scopes;
|
|
1477
|
+
selectable: SelectableBase;
|
|
1478
|
+
defaultSelect: PropertyKey;
|
|
1479
|
+
}
|
|
1480
|
+
interface QueryMetaIsSubQuery {
|
|
1481
|
+
meta: {
|
|
1482
|
+
subQuery: true;
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
interface QueryInternalTableDataPrimaryKey {
|
|
1486
|
+
columns: string[];
|
|
1487
|
+
name?: string;
|
|
1488
|
+
}
|
|
1489
|
+
interface QueryInternalTableDataBase {
|
|
1490
|
+
primaryKey?: QueryInternalTableDataPrimaryKey;
|
|
1491
|
+
}
|
|
1492
|
+
interface QueryInternalBase extends QueryInternalColumnNameToKey {
|
|
1493
|
+
runtimeDefaultColumns?: string[];
|
|
1494
|
+
transactionStorage: AsyncLocalStorage<TransactionState>;
|
|
1495
|
+
scopes?: RecordUnknown;
|
|
1496
|
+
snakeCase?: boolean;
|
|
1497
|
+
noPrimaryKey: boolean;
|
|
1498
|
+
comment?: string;
|
|
1499
|
+
primaryKeys?: string[];
|
|
1500
|
+
tableData: QueryInternalTableDataBase;
|
|
1501
|
+
}
|
|
1502
|
+
type CoreQueryScopes<Keys extends string> = {
|
|
1503
|
+
[K in Keys]: unknown;
|
|
1504
|
+
};
|
|
1505
|
+
type QueryReturnType = QueryReturnTypeAll | 'one' | 'oneOrThrow' | 'rows' | 'pluck' | 'value' | 'valueOrThrow' | 'void';
|
|
1506
|
+
type QueryReturnTypeAll = undefined | 'all';
|
|
1507
|
+
type QueryReturnTypeOptional = 'one' | 'value';
|
|
1508
|
+
interface IsQuery {
|
|
1509
|
+
__isQuery: true;
|
|
1510
|
+
}
|
|
1511
|
+
interface IsQueries {
|
|
1512
|
+
[K: string]: IsQuery;
|
|
1513
|
+
}
|
|
1514
|
+
interface QueryBase extends IsQuery {
|
|
1515
|
+
internal: QueryInternalBase;
|
|
1516
|
+
shape: QueryColumns;
|
|
1517
|
+
q: QueryDataBase;
|
|
1518
|
+
table?: string;
|
|
1519
|
+
}
|
|
1520
|
+
interface QueryBaseCommon<Scopes extends RecordKeyTrue = RecordKeyTrue> extends QueryBase {
|
|
1521
|
+
meta: QueryMetaBase<Scopes>;
|
|
1522
|
+
}
|
|
1523
|
+
interface SelectableBase {
|
|
1524
|
+
[K: PropertyKey]: {
|
|
1525
|
+
as: string;
|
|
1526
|
+
column: QueryColumn;
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
type getValueKey = typeof getValueKey;
|
|
1530
|
+
declare const getValueKey: unique symbol;
|
|
1531
|
+
type QueryDataTransform = QueryDataTransformFn | {
|
|
1532
|
+
map: (record: unknown, index: number, array: unknown) => unknown;
|
|
1533
|
+
thisArg?: unknown;
|
|
1534
|
+
};
|
|
1535
|
+
interface QueryDataTransformFn {
|
|
1536
|
+
(data: unknown, queryData: unknown): unknown;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* See `transform` query method.
|
|
1540
|
+
* This helper applies all transform functions to a result.
|
|
1541
|
+
*
|
|
1542
|
+
* @param queryData - query data
|
|
1543
|
+
* @param returnType - return type of the query, for proper `map` handling
|
|
1544
|
+
* @param fns - array of transform functions, can be undefined
|
|
1545
|
+
* @param result - query result to transform
|
|
1546
|
+
*/
|
|
1547
|
+
declare const applyTransforms: (queryData: unknown, returnType: QueryReturnType, fns: QueryDataTransform[], result: unknown) => unknown;
|
|
1548
|
+
/**
|
|
1549
|
+
* Push a new element into an array in the query data - immutable version
|
|
1550
|
+
*
|
|
1551
|
+
* @param q - query
|
|
1552
|
+
* @param key - key to get the array
|
|
1553
|
+
* @param value - new element to push
|
|
1554
|
+
*/
|
|
1555
|
+
declare const pushQueryValueImmutable: <T extends IsQuery>(q: T, key: string, value: unknown) => T;
|
|
1556
|
+
interface QueryOrExpression<T> {
|
|
1557
|
+
result: {
|
|
1558
|
+
value: QueryColumn<T>;
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
interface QueryLogObject {
|
|
1563
|
+
colors: boolean;
|
|
1564
|
+
beforeQuery(sql: SingleSql): unknown;
|
|
1565
|
+
afterQuery(sql: SingleSql, logData: unknown): void;
|
|
1566
|
+
onError(error: Error, sql: SingleSql, logData: unknown): void;
|
|
1567
|
+
}
|
|
1568
|
+
interface QueryLogger {
|
|
1569
|
+
log(message: string): void;
|
|
1570
|
+
warn(message: string): void;
|
|
1571
|
+
error(message: string): void;
|
|
1572
|
+
}
|
|
1573
|
+
interface QueryLogOptions {
|
|
1574
|
+
log?: boolean | Partial<QueryLogObject>;
|
|
1575
|
+
logger?: QueryLogger;
|
|
1576
|
+
}
|
|
1577
|
+
declare const logColors: {
|
|
1578
|
+
boldCyanBright: (message: string) => string;
|
|
1579
|
+
boldBlue: (message: string) => string;
|
|
1580
|
+
boldYellow: (message: string) => string;
|
|
1581
|
+
boldMagenta: (message: string) => string;
|
|
1582
|
+
boldRed: (message: string) => string;
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1585
|
+
declare abstract class OrchidOrmError extends Error {
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* When we search for a single record, and it is not found, it can either throw an error, or return `undefined`.
|
|
1589
|
+
*
|
|
1590
|
+
* Unlike other database libraries, `Orchid ORM` decided to throw errors by default when using methods `take`, `find`, `findBy`, `get` and the record is not found.
|
|
1591
|
+
* It is a [good practice](https://github.com/goldbergyoni/nodebestpractices/blob/master/sections/errorhandling/centralizedhandling.md) to catch common errors in a centralized place (see [global error handling](https://orchid-orm.netlify.app/guide/error-handling.html#global-error-handling)), and this allows for a more concise code.
|
|
1592
|
+
*
|
|
1593
|
+
* If it's more suitable to get the `undefined` value instead of throwing, use `takeOptional`, `findOptional`, `findByOptional`, `getOptional` instead.
|
|
1594
|
+
*/
|
|
1595
|
+
declare class NotFoundError extends OrchidOrmError {
|
|
1596
|
+
#private;
|
|
1597
|
+
constructor(query: QueryBase, message?: string);
|
|
1598
|
+
get query(): QueryBase;
|
|
1599
|
+
}
|
|
1600
|
+
declare class OrchidOrmInternalError extends Error {
|
|
1601
|
+
#private;
|
|
1602
|
+
data?: RecordUnknown | undefined;
|
|
1603
|
+
constructor(query: QueryBase, message?: string, data?: RecordUnknown | undefined);
|
|
1604
|
+
get query(): QueryBase;
|
|
1605
|
+
}
|
|
1606
|
+
type QueryErrorName = 'parseComplete' | 'bindComplete' | 'closeComplete' | 'noData' | 'portalSuspended' | 'replicationStart' | 'emptyQuery' | 'copyDone' | 'copyData' | 'rowDescription' | 'parameterDescription' | 'parameterStatus' | 'backendKeyData' | 'notification' | 'readyForQuery' | 'commandComplete' | 'dataRow' | 'copyInResponse' | 'copyOutResponse' | 'authenticationOk' | 'authenticationMD5Password' | 'authenticationCleartextPassword' | 'authenticationSASL' | 'authenticationSASLContinue' | 'authenticationSASLFinal' | 'error' | 'notice';
|
|
1607
|
+
declare abstract class QueryError<T extends PickQueryShape = PickQueryShape> extends OrchidOrmInternalError {
|
|
1608
|
+
message: string;
|
|
1609
|
+
name: QueryErrorName;
|
|
1610
|
+
stack: string | undefined;
|
|
1611
|
+
code: string | undefined;
|
|
1612
|
+
detail: string | undefined;
|
|
1613
|
+
severity: string | undefined;
|
|
1614
|
+
hint: string | undefined;
|
|
1615
|
+
position: string | undefined;
|
|
1616
|
+
internalPosition: string | undefined;
|
|
1617
|
+
internalQuery: string | undefined;
|
|
1618
|
+
where: string | undefined;
|
|
1619
|
+
schema: string | undefined;
|
|
1620
|
+
table: string | undefined;
|
|
1621
|
+
column: string | undefined;
|
|
1622
|
+
dataType: string | undefined;
|
|
1623
|
+
constraint: string | undefined;
|
|
1624
|
+
file: string | undefined;
|
|
1625
|
+
line: string | undefined;
|
|
1626
|
+
routine: string | undefined;
|
|
1627
|
+
get isUnique(): boolean;
|
|
1628
|
+
columnsCache?: {
|
|
1629
|
+
[K in keyof T['shape']]?: true;
|
|
1630
|
+
};
|
|
1631
|
+
get columns(): { [K in keyof T["shape"]]?: true | undefined; };
|
|
1632
|
+
}
|
|
1633
|
+
declare class MoreThanOneRowError extends OrchidOrmInternalError {
|
|
1634
|
+
constructor(query: QueryBase, message?: string);
|
|
1635
|
+
}
|
|
1636
|
+
declare class UnhandledTypeError extends OrchidOrmInternalError {
|
|
1637
|
+
constructor(query: QueryBase, value: never);
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
/**
|
|
1641
|
+
* Generic result returning from query methods.
|
|
1642
|
+
*/
|
|
1643
|
+
interface QueryResultRow {
|
|
1644
|
+
[K: string]: any;
|
|
1645
|
+
}
|
|
1646
|
+
interface QueryResult<T extends QueryResultRow = any> {
|
|
1647
|
+
rowCount: number;
|
|
1648
|
+
rows: T[];
|
|
1649
|
+
fields: {
|
|
1650
|
+
name: string;
|
|
1651
|
+
}[];
|
|
1652
|
+
}
|
|
1653
|
+
interface QueryArraysResult<R extends any[] = any[]> {
|
|
1654
|
+
rowCount: number;
|
|
1655
|
+
rows: R[];
|
|
1656
|
+
fields: {
|
|
1657
|
+
name: string;
|
|
1658
|
+
}[];
|
|
1659
|
+
}
|
|
1660
|
+
interface AdapterConfigBase {
|
|
1661
|
+
databaseURL?: string;
|
|
1662
|
+
/**
|
|
1663
|
+
* This option may be useful in CI when database container has started, CI starts performing next steps,
|
|
1664
|
+
* migrations begin to apply though database may be not fully ready for connections yet.
|
|
1665
|
+
*
|
|
1666
|
+
* Set `connectRetry: true` for the default backoff strategy. It performs 10 attempts starting with 50ms delay and increases delay exponentially according to this formula:
|
|
1667
|
+
*
|
|
1668
|
+
* ```
|
|
1669
|
+
* (factor, defaults to 1.5) ** (currentAttempt - 1) * (delay, defaults to 50)
|
|
1670
|
+
* ```
|
|
1671
|
+
*
|
|
1672
|
+
* So the 2nd attempt will happen in 50ms from start, 3rd attempt in 125ms, 3rd in 237ms, and so on.
|
|
1673
|
+
*
|
|
1674
|
+
* You can customize max attempts to be made, `factor` multiplier and the starting delay by passing:
|
|
1675
|
+
*
|
|
1676
|
+
* ```ts
|
|
1677
|
+
* const options = {
|
|
1678
|
+
* databaseURL: process.env.DATABASE_URL,
|
|
1679
|
+
* connectRetry: {
|
|
1680
|
+
* attempts: 15, // max attempts
|
|
1681
|
+
* strategy: {
|
|
1682
|
+
* delay: 100, // initial delay
|
|
1683
|
+
* factor: 2, // multiplier for the formula above
|
|
1684
|
+
* }
|
|
1685
|
+
* }
|
|
1686
|
+
* };
|
|
1687
|
+
*
|
|
1688
|
+
* rakeDb(options, { ... });
|
|
1689
|
+
* ```
|
|
1690
|
+
*
|
|
1691
|
+
* You can pass a custom function to `strategy` to customize delay behavior:
|
|
1692
|
+
*
|
|
1693
|
+
* ```ts
|
|
1694
|
+
* import { setTimeout } from 'timers/promises';
|
|
1695
|
+
*
|
|
1696
|
+
* const options = {
|
|
1697
|
+
* databaseURL: process.env.DATABASE_URL,
|
|
1698
|
+
* connectRetry: {
|
|
1699
|
+
* attempts: 5,
|
|
1700
|
+
* stragegy(currentAttempt: number, maxAttempts: number) {
|
|
1701
|
+
* // linear: wait 100ms after 1st attempt, then 200m after 2nd, and so on.
|
|
1702
|
+
* return setTimeout(currentAttempt * 100);
|
|
1703
|
+
* },
|
|
1704
|
+
* },
|
|
1705
|
+
* };
|
|
1706
|
+
* ```
|
|
1707
|
+
*/
|
|
1708
|
+
connectRetry?: AdapterConfigConnectRetryParam | true;
|
|
1709
|
+
}
|
|
1710
|
+
interface AdapterConfigConnectRetryParam {
|
|
1711
|
+
attempts?: number;
|
|
1712
|
+
strategy?: AdapterConfigConnectRetryStrategyParam | AdapterConfigConnectRetryStrategy;
|
|
1713
|
+
}
|
|
1714
|
+
interface AdapterConfigConnectRetryStrategyParam {
|
|
1715
|
+
delay?: number;
|
|
1716
|
+
factor?: number;
|
|
1717
|
+
}
|
|
1718
|
+
interface AdapterConfigConnectRetry {
|
|
1719
|
+
attempts: number;
|
|
1720
|
+
strategy: AdapterConfigConnectRetryStrategy;
|
|
1721
|
+
}
|
|
1722
|
+
interface AdapterConfigConnectRetryStrategy {
|
|
1723
|
+
(attempt: number, attempts: number): Promise<void> | void;
|
|
1724
|
+
}
|
|
1725
|
+
interface AdapterBase {
|
|
1726
|
+
connectRetryConfig?: AdapterConfigConnectRetry;
|
|
1727
|
+
schema?: string;
|
|
1728
|
+
errorClass: new (...args: any[]) => Error;
|
|
1729
|
+
assignError(to: QueryError, from: Error): void;
|
|
1730
|
+
reconfigure(params: {
|
|
1731
|
+
database?: string;
|
|
1732
|
+
user?: string;
|
|
1733
|
+
password?: string;
|
|
1734
|
+
schema?: string;
|
|
1735
|
+
}): AdapterBase;
|
|
1736
|
+
getDatabase(): string;
|
|
1737
|
+
getUser(): string;
|
|
1738
|
+
getSchema(): string | undefined;
|
|
1739
|
+
getHost(): string;
|
|
1740
|
+
connect?(): Promise<unknown>;
|
|
1741
|
+
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[]): Promise<QueryResult<T>>;
|
|
1742
|
+
arrays<R extends any[] = any[]>(text: string, values?: unknown[]): Promise<QueryArraysResult<R>>;
|
|
1743
|
+
/**
|
|
1744
|
+
* Run a transaction
|
|
1745
|
+
*
|
|
1746
|
+
* @param options - optional transaction parameters
|
|
1747
|
+
* @param cb - callback will be called with a db client with a dedicated connection.
|
|
1748
|
+
*/
|
|
1749
|
+
transaction<T>(options: string | undefined, cb: (adapter: AdapterBase) => Promise<T>): Promise<T>;
|
|
1750
|
+
close(): Promise<void>;
|
|
1751
|
+
}
|
|
1752
|
+
interface TransactionState {
|
|
1753
|
+
adapter: AdapterBase;
|
|
1754
|
+
transactionId: number;
|
|
1755
|
+
afterCommit?: TransactionAfterCommitHook[];
|
|
1756
|
+
log?: QueryLogObject;
|
|
1757
|
+
testTransactionCount?: number;
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Element of `afterCommit` transaction array. See {@link TransactionState.afterCommit}.
|
|
1761
|
+
*/
|
|
1762
|
+
type TransactionAfterCommitHook = unknown[] | QueryBaseCommon | AfterCommitHook[] | AfterCommitStandaloneHook;
|
|
1763
|
+
interface AfterCommitHook {
|
|
1764
|
+
(data: unknown[], q: QueryBaseCommon): unknown | Promise<unknown>;
|
|
1765
|
+
}
|
|
1766
|
+
interface AfterCommitStandaloneHook {
|
|
1767
|
+
(): unknown | Promise<unknown>;
|
|
1768
|
+
}
|
|
1769
|
+
declare const setConnectRetryConfig: (adapter: AdapterBase, config: AdapterConfigConnectRetryParam) => void;
|
|
1770
|
+
declare const wrapAdapterFnWithConnectRetry: <Fn extends (this: unknown, ...args: any[]) => Promise<unknown>>(adapter: AdapterBase, fn: Fn) => Fn;
|
|
1771
|
+
|
|
1772
|
+
interface QueryThen<T> {
|
|
1773
|
+
<TResult1 = T, TResult2 = never>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>;
|
|
1774
|
+
}
|
|
1775
|
+
type QueryThenShallowSimplify<T> = QueryThen<ShallowSimplify<T>>;
|
|
1776
|
+
type QueryThenShallowSimplifyArr<T> = QueryThen<ShallowSimplify<T>[]>;
|
|
1777
|
+
type QueryThenShallowSimplifyOptional<T> = QueryThen<ShallowSimplify<T> | undefined>;
|
|
1778
|
+
type QueryThenByQuery<T extends PickQueryReturnType, Result extends QueryColumns> = T['returnType'] extends undefined | 'all' ? QueryThenShallowSimplifyArr<ColumnShapeOutput<Result>> : T['returnType'] extends 'one' ? QueryThenShallowSimplifyOptional<ColumnShapeOutput<Result>> : T['returnType'] extends 'oneOrThrow' ? QueryThenShallowSimplify<ColumnShapeOutput<Result>> : T['returnType'] extends 'value' ? QueryThen<Result['value']['outputType'] | undefined> : T['returnType'] extends 'valueOrThrow' ? QueryThen<Result['value']['outputType']> : T['returnType'] extends 'rows' ? QueryThen<ColumnShapeOutput<Result>[keyof Result][][]> : T['returnType'] extends 'pluck' ? QueryThen<Result['pluck']['outputType'][]> : QueryThen<void>;
|
|
1779
|
+
type QueryThenByReturnType<T extends QueryReturnType, Result extends QueryColumns> = T extends undefined | 'all' ? QueryThenShallowSimplifyArr<ColumnShapeOutput<Result>> : T extends 'one' ? QueryThenShallowSimplifyOptional<ColumnShapeOutput<Result>> : T extends 'oneOrThrow' ? QueryThenShallowSimplify<ColumnShapeOutput<Result>> : T extends 'value' ? QueryThen<Result['value']['outputType'] | undefined> : T extends 'valueOrThrow' ? QueryThen<Result['value']['outputType']> : T extends 'rows' ? QueryThen<ColumnShapeOutput<Result>[keyof Result][][]> : T extends 'pluck' ? QueryThen<Result['pluck']['outputType'][]> : QueryThen<void>;
|
|
1780
|
+
interface QueryCatch {
|
|
1781
|
+
<Q, TResult = never>(this: {
|
|
1782
|
+
then: (onfulfilled?: (value: Q) => any) => any;
|
|
1783
|
+
}, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<Q | TResult>;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
type SQLQueryArgs = TemplateLiteralArgs | [RawSQLBase];
|
|
1787
|
+
|
|
1788
|
+
declare const getPrimaryKeys: (q: QueryBase) => string[];
|
|
1789
|
+
declare const requirePrimaryKeys: (q: QueryBase, message: string) => string[];
|
|
6
1790
|
|
|
7
1791
|
declare const checkIfASimpleQuery: (q: Query) => boolean;
|
|
8
1792
|
interface WithItem {
|
|
@@ -188,7 +1972,7 @@ type OnConflictMerge = string | string[] | {
|
|
|
188
1972
|
except: string | string[];
|
|
189
1973
|
};
|
|
190
1974
|
|
|
191
|
-
declare module '
|
|
1975
|
+
declare module '../core' {
|
|
192
1976
|
interface ColumnDataBase {
|
|
193
1977
|
computed?: Expression;
|
|
194
1978
|
}
|
|
@@ -500,7 +2284,7 @@ declare class DynamicRawSQL<T extends QueryColumn, ColumnTypes = DefaultColumnTy
|
|
|
500
2284
|
}
|
|
501
2285
|
declare function raw<T = never>(...args: StaticSQLArgs): RawSQL<QueryColumn<T>>;
|
|
502
2286
|
declare function raw<T = never>(...args: [DynamicSQLArg<QueryColumn<T>>]): DynamicRawSQL<QueryColumn<T>>;
|
|
503
|
-
declare const countSelect: RawSQL<QueryColumn<unknown, any>, DefaultColumnTypes<ColumnSchemaConfig<
|
|
2287
|
+
declare const countSelect: RawSQL<QueryColumn<unknown, any>, DefaultColumnTypes<ColumnSchemaConfig<ColumnTypeBase<ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, ColumnDataBase>>>>[];
|
|
504
2288
|
declare function sqlQueryArgsToExpression(args: SQLQueryArgs): RawSQL<QueryColumn>;
|
|
505
2289
|
interface SqlFn {
|
|
506
2290
|
<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>;
|
|
@@ -3710,12 +5494,13 @@ interface DbResult<ColumnTypes> extends Db<string, never, never, never, never, n
|
|
|
3710
5494
|
* })
|
|
3711
5495
|
* ```
|
|
3712
5496
|
*/
|
|
3713
|
-
declare const createDbWithAdapter: <SchemaConfig extends ColumnSchemaConfig<ColumnTypeBase<
|
|
5497
|
+
declare const createDbWithAdapter: <SchemaConfig extends ColumnSchemaConfig<ColumnTypeBase<ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, ColumnDataBase>> = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({ log, logger, snakeCase, schemaConfig, columnTypes: ctOrFn, ...options }: DbOptionsWithAdapter<SchemaConfig, ColumnTypes>) => DbResult<ColumnTypes>;
|
|
3714
5498
|
declare const _initQueryBuilder: (adapter: AdapterBase, columnTypes: unknown, transactionStorage: AsyncLocalStorage<TransactionState>, commonOptions: DbTableOptions<unknown, undefined, QueryColumns>, options: DbSharedOptions) => Db;
|
|
3715
5499
|
|
|
3716
|
-
interface ToSqlOptionsInternal extends ToSQLOptions {
|
|
5500
|
+
interface ToSqlOptionsInternal extends ToSQLOptions, HasCteHooks {
|
|
3717
5501
|
aliasValue?: true;
|
|
3718
5502
|
skipBatchCheck?: true;
|
|
5503
|
+
selectedCount?: number;
|
|
3719
5504
|
}
|
|
3720
5505
|
interface ToSQLCtx extends ToSqlOptionsInternal, ToSQLOptions {
|
|
3721
5506
|
qb: QueryBuilder;
|
|
@@ -3743,7 +5528,8 @@ interface ToSQLQuery {
|
|
|
3743
5528
|
result: Query['result'];
|
|
3744
5529
|
shape: Query['shape'];
|
|
3745
5530
|
}
|
|
3746
|
-
declare const
|
|
5531
|
+
declare const toSubSqlText: (q: ToSQLQuery, cteName: string, options: ToSqlOptionsInternal) => string;
|
|
5532
|
+
declare const toSQL: (table: ToSQLQuery, options?: ToSqlOptionsInternal, isSubSql?: boolean) => Sql;
|
|
3747
5533
|
declare function pushLimitSQL(sql: string[], values: unknown[], q: QueryData): void;
|
|
3748
5534
|
|
|
3749
5535
|
declare const getSqlText: (sql: Sql) => string;
|
|
@@ -4286,10 +6072,10 @@ type CreateManyFromResult<T extends CreateSelf> = T extends {
|
|
|
4286
6072
|
isCount: true;
|
|
4287
6073
|
} ? SetQueryKind<T, 'create'> : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKind<T, 'create'> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKind<T, 'create'> : SetQueryKind<T, 'create'>;
|
|
4288
6074
|
type InsertManyFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKind<T, 'create'> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKind<T, 'create'> : SetQueryKind<T, 'create'> : SetQueryReturnsRowCountMany<T, 'create'>;
|
|
4289
|
-
declare const _queryCreateOneFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data?: Omit<CreateData<T
|
|
4290
|
-
declare const _queryInsertOneFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data?: Omit<CreateData<T
|
|
4291
|
-
declare const _queryCreateManyFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data: Omit<CreateData<T
|
|
4292
|
-
declare const _queryInsertManyFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data: Omit<CreateData<T
|
|
6075
|
+
declare const _queryCreateOneFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data?: Omit<CreateData<T>, keyof Q['result']>) => CreateRawOrFromResult<T>;
|
|
6076
|
+
declare const _queryInsertOneFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data?: Omit<CreateData<T>, keyof Q['result']>) => InsertRawOrFromResult<T>;
|
|
6077
|
+
declare const _queryCreateManyFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data: Omit<CreateData<T>, keyof Q['result']>[]) => CreateManyFromResult<T>;
|
|
6078
|
+
declare const _queryInsertManyFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data: Omit<CreateData<T>, keyof Q['result']>[]) => InsertManyFromResult<T>;
|
|
4293
6079
|
declare const _queryCreateForEachFrom: <T extends CreateSelf>(q: T, query: IsQuery) => CreateManyFromResult<T>;
|
|
4294
6080
|
declare const _queryInsertForEachFrom: <T extends CreateSelf>(q: T, query: IsQuery) => InsertManyFromResult<T>;
|
|
4295
6081
|
declare class QueryCreateFrom {
|
|
@@ -4344,14 +6130,14 @@ declare class QueryCreateFrom {
|
|
|
4344
6130
|
* @param query - query to create new records from
|
|
4345
6131
|
* @param data - additionally you can set some columns
|
|
4346
6132
|
*/
|
|
4347
|
-
createOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: Omit<CreateData<T
|
|
6133
|
+
createOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: Omit<CreateData<T>, keyof Q['result']>): CreateRawOrFromResult<T>;
|
|
4348
6134
|
/**
|
|
4349
6135
|
* Works exactly as {@link createOneFrom}, except that it returns inserted row count by default.
|
|
4350
6136
|
*
|
|
4351
6137
|
* @param query - query to create new records from
|
|
4352
6138
|
* @param data - additionally you can set some columns
|
|
4353
6139
|
*/
|
|
4354
|
-
insertOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: Omit<CreateData<T
|
|
6140
|
+
insertOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: Omit<CreateData<T>, keyof Q['result']>): InsertRawOrFromResult<T>;
|
|
4355
6141
|
/**
|
|
4356
6142
|
* Inserts multiple records based on a query that selects a single record.
|
|
4357
6143
|
*
|
|
@@ -4411,14 +6197,14 @@ declare class QueryCreateFrom {
|
|
|
4411
6197
|
* @param query - query to create new records from
|
|
4412
6198
|
* @param data - array of records to create
|
|
4413
6199
|
*/
|
|
4414
|
-
createManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data: Omit<CreateData<T
|
|
6200
|
+
createManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data: Omit<CreateData<T>, keyof Q['result']>[]): CreateManyFromResult<T>;
|
|
4415
6201
|
/**
|
|
4416
6202
|
* Works exactly as {@link createManyFrom}, except that it returns inserted row count by default.
|
|
4417
6203
|
*
|
|
4418
6204
|
* @param query - query to create new records from
|
|
4419
6205
|
* @param data - array of records to create
|
|
4420
6206
|
*/
|
|
4421
|
-
insertManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data: Omit<CreateData<T
|
|
6207
|
+
insertManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data: Omit<CreateData<T>, keyof Q['result']>[]): InsertManyFromResult<T>;
|
|
4422
6208
|
/**
|
|
4423
6209
|
* Inserts a single record per every record found in a given query.
|
|
4424
6210
|
*
|
|
@@ -4448,7 +6234,7 @@ declare class QueryCreateFrom {
|
|
|
4448
6234
|
interface CreateSelf extends IsQuery, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryUniqueProperties {
|
|
4449
6235
|
inputType: RecordUnknown;
|
|
4450
6236
|
}
|
|
4451
|
-
type CreateData<T extends CreateSelf
|
|
6237
|
+
type CreateData<T extends CreateSelf> = EmptyObject extends T['relations'] ? CreateDataWithDefaults<T, keyof T['meta']['defaults']> : CreateRelationsData<T>;
|
|
4452
6238
|
type CreateDataWithDefaults<T extends CreateSelf, Defaults extends PropertyKey> = {
|
|
4453
6239
|
[K in keyof T['inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T, K>;
|
|
4454
6240
|
} & {
|
|
@@ -4460,10 +6246,10 @@ type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends k
|
|
|
4460
6246
|
[K in Defaults as K extends OmitFKeys ? never : K]?: CreateColumn<T, K>;
|
|
4461
6247
|
};
|
|
4462
6248
|
type CreateColumn<T extends CreateSelf, K extends keyof T['inputType']> = T['inputType'][K] | ((q: T) => QueryOrExpression<T['inputType'][K]>);
|
|
4463
|
-
type CreateRelationsData<T extends CreateSelf
|
|
6249
|
+
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['meta']['defaults'], T['relations'][keyof T['relations']]['omitForeignKeyInCreate']> & CreateBelongsToData<T> & T['relations'][keyof T['relations']]['optionalDataForCreate'];
|
|
4464
6250
|
type CreateBelongsToData<T extends CreateSelf> = [
|
|
4465
6251
|
T['relations'][keyof T['relations']]['dataForCreate']
|
|
4466
|
-
] extends [never] ?
|
|
6252
|
+
] extends [never] ? EmptyObject : CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['dataForCreate']>;
|
|
4467
6253
|
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union extends RelationConfigDataForCreate ? (u: Union['columns'] extends keyof T['meta']['defaults'] ? {
|
|
4468
6254
|
[P in Exclude<Union['columns'] & keyof T['inputType'], keyof T['meta']['defaults']>]: CreateColumn<T, P>;
|
|
4469
6255
|
} & {
|
|
@@ -4471,25 +6257,21 @@ type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union exte
|
|
|
4471
6257
|
} & Partial<Union['nested']> : {
|
|
4472
6258
|
[P in Union['columns'] & keyof T['inputType']]: CreateColumn<T, P>;
|
|
4473
6259
|
} | Union['nested']) => void : never) extends (u: infer Obj) => void ? Obj : never;
|
|
4474
|
-
type CreateResult<T extends CreateSelf
|
|
6260
|
+
type CreateResult<T extends CreateSelf> = T extends {
|
|
4475
6261
|
isCount: true;
|
|
4476
|
-
} ? SetQueryKind<T, 'create'> : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T
|
|
4477
|
-
type InsertResult<T extends CreateSelf
|
|
4478
|
-
type CreateManyResult<T extends CreateSelf
|
|
6262
|
+
} ? SetQueryKind<T, 'create'> : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKindResult<T, 'create', NarrowCreateResult<T>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T>>;
|
|
6263
|
+
type InsertResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKindResult<T, 'create', NarrowCreateResult<T>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T>> : SetQueryReturnsRowCount<T, 'create'>;
|
|
6264
|
+
type CreateManyResult<T extends CreateSelf> = T extends {
|
|
4479
6265
|
isCount: true;
|
|
4480
|
-
} ? SetQueryKindResult<T, 'create', NarrowCreateResult<T
|
|
4481
|
-
type InsertManyResult<T extends CreateSelf
|
|
6266
|
+
} ? SetQueryKindResult<T, 'create', NarrowCreateResult<T>> : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKindResult<T, 'create', NarrowCreateResult<T>> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKindResult<T, 'create', NarrowCreateResult<T>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T>>;
|
|
6267
|
+
type InsertManyResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKindResult<T, 'create', NarrowCreateResult<T>> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKindResult<T, 'create', NarrowCreateResult<T>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T>> : SetQueryReturnsRowCountMany<T, 'create'>;
|
|
4482
6268
|
/**
|
|
4483
6269
|
* When creating a record with a *belongs to* nested record,
|
|
4484
6270
|
* un-nullify foreign key columns of the result.
|
|
4485
6271
|
*
|
|
4486
6272
|
* The same should work as well with any non-null columns passed to `create`, but it's to be implemented later.
|
|
4487
6273
|
*/
|
|
4488
|
-
type NarrowCreateResult<T extends CreateSelf
|
|
4489
|
-
{
|
|
4490
|
-
[K in keyof T['relations']]: T['relations'][K]['omitForeignKeyInCreate'];
|
|
4491
|
-
}[keyof T['relations'] & keyof Bt]
|
|
4492
|
-
] extends [never] ? T['result'] : {
|
|
6274
|
+
type NarrowCreateResult<T extends CreateSelf> = EmptyObject extends T['relations'] ? T['result'] : {
|
|
4493
6275
|
[K in keyof T['result']]: K extends T['relations'][keyof T['relations']]['omitForeignKeyInCreate'] ? QueryColumn<Exclude<T['result'][K]['type'], null>, T['result'][K]['operators']> : T['result'][K];
|
|
4494
6276
|
};
|
|
4495
6277
|
type IgnoreResult<T extends CreateSelf> = T['returnType'] extends 'oneOrThrow' ? QueryTakeOptional<T> : T['returnType'] extends 'valueOrThrow' ? SetQueryReturnsColumnOptional<T, T['result']['value']> : T;
|
|
@@ -4510,11 +6292,11 @@ interface CreateCtx {
|
|
|
4510
6292
|
returnTypeAll?: true;
|
|
4511
6293
|
resultAll: RecordUnknown[];
|
|
4512
6294
|
}
|
|
4513
|
-
declare const _queryCreate: <T extends CreateSelf
|
|
4514
|
-
declare const _queryInsert: <T extends CreateSelf
|
|
4515
|
-
declare const _queryCreateMany: <T extends CreateSelf
|
|
4516
|
-
declare const _queryInsertMany: <T extends CreateSelf
|
|
4517
|
-
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T
|
|
6295
|
+
declare const _queryCreate: <T extends CreateSelf>(q: T, data: CreateData<T>) => CreateResult<T>;
|
|
6296
|
+
declare const _queryInsert: <T extends CreateSelf>(query: T, data: CreateData<T>) => InsertResult<T>;
|
|
6297
|
+
declare const _queryCreateMany: <T extends CreateSelf>(q: T, data: CreateData<T>[]) => CreateManyResult<T>;
|
|
6298
|
+
declare const _queryInsertMany: <T extends CreateSelf>(q: T, data: CreateData<T>[]) => InsertManyResult<T>;
|
|
6299
|
+
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T>>>(q: T, data: Data) => AddQueryDefaults<T, { [K in keyof Data]: true; }>;
|
|
4518
6300
|
/**
|
|
4519
6301
|
* Names of all create methods,
|
|
4520
6302
|
* is used in relational query to remove these methods if chained relation shouldn't have them,
|
|
@@ -4572,13 +6354,13 @@ declare class QueryCreate {
|
|
|
4572
6354
|
*
|
|
4573
6355
|
* @param data - data for the record, may have values, raw SQL, queries, relation operations.
|
|
4574
6356
|
*/
|
|
4575
|
-
create<T extends CreateSelf
|
|
6357
|
+
create<T extends CreateSelf>(this: T, data: CreateData<T>): CreateResult<T>;
|
|
4576
6358
|
/**
|
|
4577
6359
|
* Works exactly as {@link create}, except that it returns inserted row count by default.
|
|
4578
6360
|
*
|
|
4579
6361
|
* @param data - data for the record, may have values, raw SQL, queries, relation operations.
|
|
4580
6362
|
*/
|
|
4581
|
-
insert<T extends CreateSelf
|
|
6363
|
+
insert<T extends CreateSelf>(this: T, data: CreateData<T>): InsertResult<T>;
|
|
4582
6364
|
/**
|
|
4583
6365
|
* `createMany` and `insertMany` will create a batch of records.
|
|
4584
6366
|
*
|
|
@@ -4620,13 +6402,13 @@ declare class QueryCreate {
|
|
|
4620
6402
|
*
|
|
4621
6403
|
* @param data - array of records data, may have values, raw SQL, queries, relation operations
|
|
4622
6404
|
*/
|
|
4623
|
-
createMany<T extends CreateSelf
|
|
6405
|
+
createMany<T extends CreateSelf>(this: T, data: CreateData<T>[]): CreateManyResult<T>;
|
|
4624
6406
|
/**
|
|
4625
6407
|
* Works exactly as {@link createMany}, except that it returns inserted row count by default.
|
|
4626
6408
|
*
|
|
4627
6409
|
* @param data - array of records data, may have values, raw SQL, queries, relation operations
|
|
4628
6410
|
*/
|
|
4629
|
-
insertMany<T extends CreateSelf
|
|
6411
|
+
insertMany<T extends CreateSelf>(this: T, data: CreateData<T>[]): InsertManyResult<T>;
|
|
4630
6412
|
/**
|
|
4631
6413
|
* `defaults` allows setting values that will be used later in `create`.
|
|
4632
6414
|
*
|
|
@@ -4649,7 +6431,7 @@ declare class QueryCreate {
|
|
|
4649
6431
|
*
|
|
4650
6432
|
* @param data - default values for `create` and `createMany` which will follow `defaults`
|
|
4651
6433
|
*/
|
|
4652
|
-
defaults<T extends CreateSelf, Data extends Partial<CreateData<T
|
|
6434
|
+
defaults<T extends CreateSelf, Data extends Partial<CreateData<T>>>(this: T, data: Data): AddQueryDefaults<T, {
|
|
4653
6435
|
[K in keyof Data]: true;
|
|
4654
6436
|
}>;
|
|
4655
6437
|
/**
|
|
@@ -7072,12 +8854,12 @@ interface QueryUpsert {
|
|
|
7072
8854
|
*
|
|
7073
8855
|
* @param data - `update` property for the data to update, `create` property for the data to create
|
|
7074
8856
|
*/
|
|
7075
|
-
upsert<T extends UpsertThis, Update extends UpdateData<T
|
|
8857
|
+
upsert<T extends UpsertThis, Update extends UpdateData<T>>(this: T, data: {
|
|
7076
8858
|
update: Update;
|
|
7077
|
-
create: CreateData<T
|
|
8859
|
+
create: CreateData<T> | ((update: Update) => CreateData<T>);
|
|
7078
8860
|
} | {
|
|
7079
8861
|
data: Update;
|
|
7080
|
-
create: UpsertCreate<keyof Update, CreateData<T
|
|
8862
|
+
create: UpsertCreate<keyof Update, CreateData<T>> | ((update: Update) => UpsertCreate<keyof Update, CreateData<T>>);
|
|
7081
8863
|
}): UpsertResult<T>;
|
|
7082
8864
|
}
|
|
7083
8865
|
declare const QueryUpsert: QueryUpsert;
|
|
@@ -7282,7 +9064,7 @@ interface QueryOrCreate {
|
|
|
7282
9064
|
*
|
|
7283
9065
|
* @param data - the same data as for `create`, it may be returned from a callback
|
|
7284
9066
|
*/
|
|
7285
|
-
orCreate<T extends UpsertThis$1
|
|
9067
|
+
orCreate<T extends UpsertThis$1>(this: T, data: OrCreateArg<CreateData<T>>): UpsertResult$1<T>;
|
|
7286
9068
|
}
|
|
7287
9069
|
declare const QueryOrCreate: QueryOrCreate;
|
|
7288
9070
|
|
|
@@ -8707,9 +10489,9 @@ interface DefaultColumnTypes<SchemaConfig extends ColumnSchemaConfig> extends Ti
|
|
|
8707
10489
|
point(): PostgisGeographyPointColumn<SchemaConfig>;
|
|
8708
10490
|
};
|
|
8709
10491
|
}
|
|
8710
|
-
declare const makeColumnTypes: <SchemaConfig extends ColumnSchemaConfig<
|
|
10492
|
+
declare const makeColumnTypes: <SchemaConfig extends ColumnSchemaConfig<ColumnTypeBase<ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, ColumnDataBase>>>(schema: SchemaConfig) => DefaultColumnTypes<SchemaConfig>;
|
|
8711
10493
|
|
|
8712
|
-
declare const simplifyColumnDefault: (value?: string) => RawSQL<
|
|
10494
|
+
declare const simplifyColumnDefault: (value?: string) => RawSQL<QueryColumn<unknown, any>, DefaultColumnTypes<ColumnSchemaConfig<ColumnTypeBase<ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, ColumnDataBase>>>> | undefined;
|
|
8713
10495
|
declare const assignDbDataToColumn: (column: ColumnTypeBase, params: ColumnFromDbParams) => ColumnTypeBase;
|
|
8714
10496
|
|
|
8715
10497
|
interface ColumnsShape {
|
|
@@ -8981,4 +10763,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
8981
10763
|
*/
|
|
8982
10764
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
8983
10765
|
|
|
8984
|
-
export { type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorHandler, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, ArrayColumn, type ArrayColumnValue, type ArrayData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsConfig, type ComputedOptionsFactory, type CopyOptions, type CreateBelongsToData, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbOptionsWithAdapter, type DbResult, type DbSharedOptions, type DbSqlQuery, type DbStructureDomainsMap, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, type ExpressionOutput, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, For, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratedColumn, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, Having, type HavingItem, type HookAction, type HookSelectArg, type IdentityColumn, InetColumn, type InsertQueryDataObjectValues, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinResultFromArgs, type JoinResultRequireMain, type JoinResultSelectable, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MergeQuery, MergeQueryMethods, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, type OnConflictSet$1 as OnConflictSet, type OnConflictTarget, OnMethods, type Operator, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNumber, type OperatorsOrdinalText, type OperatorsText, type OperatorsTime, OrExpression, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, PathColumn, type PickColumnData, type PickQueryBaseQuery, type PickQueryDataShapeAndJoinedShapes, type PickQueryDataShapeAndJoinedShapesAndAliases, type PickQueryInternal, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, QueryAsMethods, type QueryBatchResult, type QueryBeforeHook, type QueryBeforeHookInternal, type QueryBuilder, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryIfResultThen, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpressionBooleanOrNullResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, type QueryTake, type QueryTakeOptional, QueryUpsert, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type ReturnsQueryOrExpression, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsArg, type SelectAsFnArg, type SelectAsValue, type SelectItem, type SelectSelf, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsValueOrThrowKind, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, type TransactionOptions, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfig, type WithConfigs, type WithItem, type WithItems, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _addWith, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryChangeCounter, _queryCreate, _queryCreateForEachFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateOneFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertForEachFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertOneFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _querySelectAll, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDbWithAdapter, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, performQuery, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|
|
10766
|
+
export { type AdapterBase, type AdapterConfigBase, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorHandler, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterCommitHook, type AfterCommitStandaloneHook, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, type AliasOrTable, ArrayColumn, type ArrayColumnValue, type ArrayData, type ArrayMethodsData, type AsQueryArg, type AsTypeArg, type BaseNumberData, type BatchParser, type BatchParsers, type BatchSql, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type Code, type Codes, type ColumnData, type ColumnDataAppReadOnly, type ColumnDataBase, type ColumnDataCheckBase, type ColumnDataGenerated, type ColumnFromDbParams, type ColumnInputOutputQueryTypes, type ColumnInputOutputQueryTypesWithSchemas, type ColumnNameOfTable, type ColumnParser, ColumnRefExpression, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnShapeInput, type ColumnShapeInputPartial, type ColumnShapeOutput, type ColumnToCodeCtx, ColumnType, ColumnTypeBase, type ColumnTypeSchemaArg, type ColumnTypesBase, type ColumnWithDefault, type ColumnsByType, type ColumnsParsers, type ColumnsShape, type ColumnsShapeBase, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsConfig, type ComputedOptionsFactory, type CopyOptions, type CoreQueryScopes, type CreateBelongsToData, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, type CteTableHook, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbOptionsWithAdapter, type DbResult, type DbSharedOptions, type DbSqlQuery, type DbStructureDomainsMap, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, type DefaultSelectColumns, type DefaultSelectOutput, type DelayedRelationSelect, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, type DynamicSQLArg, type EmptyObject, type EmptyTuple, type EncodeColumn, EnumColumn, type ErrorMessage, type ErrorMessages, Expression, type ExpressionChain, type ExpressionData, ExpressionMethods, type ExpressionOutput, ExpressionTypeMethod, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, type FnUnknownToUnknown, For, type ForeignKeyTable, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratedColumn, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, type HasCteHooks, Having, type HavingItem, type HookAction, type HookSelect, type HookSelectArg, type HookSelectValue, type IdentityColumn, InetColumn, type InsertQueryDataObjectValues, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQueries, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinResultFromArgs, type JoinResultRequireMain, type JoinResultSelectable, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, type NullableColumn, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, type OnConflictSet$1 as OnConflictSet, type OnConflictTarget, OnMethods, type Operator, type OperatorToSQL, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNullable, type OperatorsNumber, type OperatorsOrdinalText, type OperatorsText, type OperatorsTime, OrExpression, OrchidOrmError, OrchidOrmInternalError, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, type ParseColumn, type ParseNullColumn, PathColumn, type PickColumnBaseData, type PickColumnData, type PickOutputType, type PickOutputTypeAndOperators, type PickQueryBaseQuery, type PickQueryColumnTypes, type PickQueryDataShapeAndJoinedShapes, type PickQueryDataShapeAndJoinedShapesAndAliases, type PickQueryInputType, type PickQueryInternal, type PickQueryMeta, type PickQueryMetaColumnTypes, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaRelationsResultReturnType, type PickQueryMetaRelationsReturnType, type PickQueryMetaResult, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnType, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsThen, type PickQueryMetaResultWindows, type PickQueryMetaReturnType, type PickQueryMetaShape, type PickQueryMetaShapeRelationsReturnType, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelationQueries, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResult, type PickQueryResultColumnTypes, type PickQueryResultReturnType, type PickQueryResultReturnTypeUniqueColumns, type PickQueryReturnType, type PickQueryShape, type PickQueryShapeResultReturnTypeSinglePrimaryKey, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryTable, type PickQueryTableMetaResult, type PickQueryTableMetaResultInputType, type PickQueryTableMetaResultReturnTypeWithDataWindowsThen, type PickQueryTableMetaResultShape, type PickQueryTableMetaShape, type PickQueryUniqueProperties, type PickQueryWindows, type PickQueryWithData, type PickQueryWithDataColumnTypes, type PickType, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type PrimaryKeyColumn, type Query, type QueryAfterHook, type QueryArraysResult, QueryAsMethods, type QueryBase, type QueryBaseCommon, type QueryBatchResult, type QueryBeforeHook, type QueryBeforeHookInternal, type QueryBuilder, type QueryCatch, type QueryColumn, type QueryColumnInit, type QueryColumnOfDataType, type QueryColumnToNullable, type QueryColumns, type QueryColumnsInit, type QueryComputedArg, type QueryData, type QueryDataAliases, type QueryDataBase, type QueryDataFromItem, type QueryDataJoinTo, type QueryDataTransform, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryIfResultThen, type QueryInternal, type QueryInternalBase, QueryLog, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryMetaBase, type QueryMetaHasSelect, type QueryMetaHasWhere, type QueryMetaIsSubQuery, QueryMethods, type QueryOrExpression, type QueryOrExpressionBooleanOrNullResult, type QueryResult, type QueryResultRow, type QueryReturnType, type QueryReturnTypeAll, type QueryReturnTypeOptional, type QueryScopeData, type QueryScopes, type QuerySourceItem, type QueryTake, type QueryTakeOptional, type QueryThen, type QueryThenByQuery, type QueryThenByReturnType, type QueryThenShallowSimplify, type QueryThenShallowSimplifyArr, type QueryThenShallowSimplifyOptional, QueryUpsert, RawSQL, RawSQLBase, type RawSQLValues, RealColumn, type RecordBoolean, type RecordKeyTrue, type RecordOfColumnsShapeBase, type RecordOptionalString, type RecordString, type RecordUnknown, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationConfigQuery, type RelationJoinQuery, type RelationsBase, type ReturnsQueryOrExpression, type RuntimeComputedQueryColumn, type SQLArgs, type SQLQueryArgs, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsArg, type SelectAsFnArg, type SelectAsValue, type SelectItem, type SelectSelf, type SelectSubQueryResult, type SelectableBase, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsValueOrThrowKind, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type SetQueryTableAlias, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItemNonSubQueryArgs, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type SortDir, type Sql, type SqlFn, SqlMethod, type StaticSQLArgs, StringColumn$1 as StringColumn, type StringTypeData, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TableHook, type TemplateLiteralArgs, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, type TimeInterval, TimestampColumn, type TimestampHelpers, TimestampTZColumn, type Timestamps, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, type TransactionAfterCommitHook, type TransactionOptions, type TransactionState, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UnionToIntersection, type UniqueColumn, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, ValExpression, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfig, type WithConfigs, type WithDataItem, type WithDataItems, type WithItem, type WithItems, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _addToHookSelect, _addToHookSelectWithTable, _addWith, _applyRelationAliases, _checkIfAliased, _clone, _copyQueryAliasToQuery, _getQueryAliasOrName, _getQueryAs, _getQueryFreeAlias, _getQueryOuterAliases, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryChangeCounter, _queryCreate, _queryCreateForEachFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateOneFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertForEachFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertOneFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _querySelectAll, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, _setQueryAlias, _setQueryAs, _setSubQueryAliases, addCode, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, addValue, anyShape, applyComputedColumns, applyMixins, applyTransforms, arrayDataToCode, assignDbDataToColumn, backtickQuote, callWithThis, checkIfASimpleQuery, cloneQueryBaseUnscoped, codeToString, colors, columnCheckToCode, columnCode, columnDefaultArgumentToCode, columnErrorMessagesToCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, consumeColumnName, copyTableData, countSelect, createDbWithAdapter, dateDataToCode, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, exhaustive, extendQuery, filterResult, foreignKeyArgumentToCode, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getDefaultLanguage, getFreeAlias, getFreeSetAlias, getFullColumnTable, getImportPath, getPrimaryKeys, getQueryAs, getQueryParsers, getShapeFromSelect, getSqlText, getStackTrace, getValueKey, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isExpression, isInUserTransaction, isIterable, isObjectEmpty, isQueryReturnsAll, isRawSQL, isRelationQuery, isSelectingCount, isTemplateLiteralArgs, joinSubQuery, joinTruthy, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, newDelayedRelationSelect, noop, numberDataToCode, objectHasValues, omit, parseRecord, parseTableData, parseTableDataInput, pathToLog, performQuery, pick, pluralize, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushColumnData, pushLimitSQL, pushOrNewArray, pushOrNewArrayToObjectImmutable, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValueImmutable, pushTableDataCode, queryColumnNameToKey, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quoteObjectKey, raw, referencesArgsToCode, requirePrimaryKeys, resolveSubQueryCallbackV2, returnArg, rollbackSql, saveAliasedShape, setColumnData, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setConnectRetryConfig, setCurrentColumnName, setDataValue, setDefaultLanguage, setDefaultNowFn, setDelayedRelation, setObjectValueImmutable, setParserForSelectedString, setParserToQuery, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, singleQuote, singleQuoteArray, snakeCaseKey, spreadObjectValues, sqlFn, sqlQueryArgsToExpression, stringDataToCode, tableDataMethods, templateLiteralSQLToCode, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, timestampHelpers, toArray, toCamelCase, toPascalCase, toSQL, toSnakeCase, toSubSqlText, wrapAdapterFnWithConnectRetry };
|