pqb 0.2.3 → 0.2.4
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 +706 -678
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/queryMethods/insert.ts +38 -8
- package/src/relations.ts +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -230,6 +230,239 @@ declare class WhereQueryBuilder<Q extends QueryBase = QueryBase> extends Where i
|
|
|
230
230
|
clone<T extends this>(this: T): T;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
declare type AggregateArg<T extends Query> = Expression<T> | Record<string, Expression<T>> | [Expression<T>, string];
|
|
234
|
+
declare type AggregateOptions<T extends Query = Query, As extends string | undefined = any> = {
|
|
235
|
+
as?: As;
|
|
236
|
+
distinct?: boolean;
|
|
237
|
+
order?: OrderArg<T> | OrderArg<T>[];
|
|
238
|
+
filter?: WhereArg<T>;
|
|
239
|
+
filterOr?: WhereArg<T>[];
|
|
240
|
+
withinGroup?: boolean;
|
|
241
|
+
over?: T['windows'][number] | WindowArgDeclaration<T>;
|
|
242
|
+
};
|
|
243
|
+
declare type Aggregate1ArgumentTypes<T extends Query = Query, C extends ColumnType = ColumnType> = {
|
|
244
|
+
count: Expression<T, C>;
|
|
245
|
+
avg: NumberExpression<T, C>;
|
|
246
|
+
min: Expression<T, C>;
|
|
247
|
+
max: Expression<T, C>;
|
|
248
|
+
sum: NumberExpression<T, C>;
|
|
249
|
+
bitAnd: NumberExpression<T, C>;
|
|
250
|
+
bitOr: NumberExpression<T, C>;
|
|
251
|
+
boolAnd: BooleanExpression<T, C>;
|
|
252
|
+
boolOr: BooleanExpression<T, C>;
|
|
253
|
+
every: BooleanExpression<T, C>;
|
|
254
|
+
jsonAgg: Expression<T, C>;
|
|
255
|
+
jsonbAgg: Expression<T, C>;
|
|
256
|
+
xmlAgg: Expression<T, C>;
|
|
257
|
+
};
|
|
258
|
+
declare const aggregate1FunctionNames: {
|
|
259
|
+
readonly count: "count";
|
|
260
|
+
readonly avg: "avg";
|
|
261
|
+
readonly min: "min";
|
|
262
|
+
readonly max: "max";
|
|
263
|
+
readonly sum: "sum";
|
|
264
|
+
readonly bitAnd: "bit_and";
|
|
265
|
+
readonly bitOr: "bit_or";
|
|
266
|
+
readonly boolAnd: "bool_and";
|
|
267
|
+
readonly boolOr: "bool_or";
|
|
268
|
+
readonly every: "every";
|
|
269
|
+
readonly jsonAgg: "json_agg";
|
|
270
|
+
readonly jsonbAgg: "jsonb_agg";
|
|
271
|
+
readonly xmlAgg: "xmlagg";
|
|
272
|
+
};
|
|
273
|
+
declare type SelectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType> = AddQuerySelect<T, Record<CoalesceString<As, Func>, Value>>;
|
|
274
|
+
declare type AT1<T extends Query> = Aggregate1ArgumentTypes<T>;
|
|
275
|
+
declare type WindowFunctionOptions<T extends Query = Query, As extends string | undefined = any> = {
|
|
276
|
+
as?: As;
|
|
277
|
+
} & WindowArgDeclaration<T>;
|
|
278
|
+
declare class Aggregate {
|
|
279
|
+
selectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType>(this: T, functionName: Func, arg: AggregateArg<T>, options?: AggregateOptions<T, As>): SelectAgg<T, Func, As, Value>;
|
|
280
|
+
_selectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType>(this: T, functionName: Func, arg: AggregateArg<T>, options?: AggregateOptions<T, As>, columnType?: ColumnType): SelectAgg<T, Func, As, Value>;
|
|
281
|
+
count<T extends Query>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T>): SetQueryReturnsValue<T, NumberColumn>;
|
|
282
|
+
_count<T extends Query>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T>): SetQueryReturnsValue<T, NumberColumn>;
|
|
283
|
+
selectCount<T extends Query, As extends string | undefined = undefined>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T, As>): SelectAgg<T, 'count', As, NumberColumn>;
|
|
284
|
+
_selectCount<T extends Query, As extends string | undefined = undefined>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T, As>): SelectAgg<T, 'count', As, NumberColumn>;
|
|
285
|
+
avg<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['avg'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
286
|
+
_avg<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['avg'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
287
|
+
selectAvg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'avg', As, NullableColumn<NumberColumn>>;
|
|
288
|
+
_selectAvg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'avg', As, NullableColumn<NumberColumn>>;
|
|
289
|
+
min<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['min'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
290
|
+
_min<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['min'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
291
|
+
selectMin<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'min', As, NullableColumn<NumberColumn>>;
|
|
292
|
+
_selectMin<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'min', As, NullableColumn<NumberColumn>>;
|
|
293
|
+
max<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['max'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
294
|
+
_max<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['max'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
295
|
+
selectMax<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'max', As, NullableColumn<NumberColumn>>;
|
|
296
|
+
_selectMax<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'max', As, NullableColumn<NumberColumn>>;
|
|
297
|
+
sum<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['sum'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
298
|
+
_sum<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['sum'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
299
|
+
selectSum<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'sum', As, NullableColumn<NumberColumn>>;
|
|
300
|
+
_selectSum<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'sum', As, NullableColumn<NumberColumn>>;
|
|
301
|
+
bitAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
302
|
+
_bitAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
303
|
+
selectBitAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_and', As, NullableColumn<NumberColumn>>;
|
|
304
|
+
_selectBitAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_and', As, NullableColumn<NumberColumn>>;
|
|
305
|
+
bitOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
306
|
+
_bitOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
307
|
+
selectBitOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_or', As, NullableColumn<NumberColumn>>;
|
|
308
|
+
_selectBitOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_or', As, NullableColumn<NumberColumn>>;
|
|
309
|
+
boolAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
310
|
+
_boolAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
311
|
+
selectBoolAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_and', As, NullableColumn<BooleanColumn>>;
|
|
312
|
+
_selectBoolAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_and', As, NullableColumn<BooleanColumn>>;
|
|
313
|
+
boolOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
314
|
+
_boolOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
315
|
+
selectBoolOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_or', As, NullableColumn<BooleanColumn>>;
|
|
316
|
+
_selectBoolOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_or', As, NullableColumn<BooleanColumn>>;
|
|
317
|
+
every<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['every'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
318
|
+
_every<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['every'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
319
|
+
selectEvery<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'every', As, NullableColumn<BooleanColumn>>;
|
|
320
|
+
_selectEvery<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'every', As, NullableColumn<BooleanColumn>>;
|
|
321
|
+
jsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
322
|
+
_jsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
323
|
+
selectJsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
324
|
+
_selectJsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
325
|
+
jsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
326
|
+
_jsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
327
|
+
selectJsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
328
|
+
_selectJsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
329
|
+
xmlAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['xmlAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
330
|
+
_xmlAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['xmlAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
331
|
+
selectXmlAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Aggregate1ArgumentTypes<T>['xmlAgg'], options?: AggregateOptions<T, As>): SelectAgg<T, 'xmlagg', As, NullableColumn<StringColumn>>;
|
|
332
|
+
_selectXmlAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Aggregate1ArgumentTypes<T>['xmlAgg'], options?: AggregateOptions<T, As>): SelectAgg<T, 'xmlagg', As, NullableColumn<StringColumn>>;
|
|
333
|
+
jsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
334
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
335
|
+
}>>>;
|
|
336
|
+
_jsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
337
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
338
|
+
}>>>;
|
|
339
|
+
selectJsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_object_agg', As, NullableColumn<ColumnType<{
|
|
340
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
341
|
+
}>>>;
|
|
342
|
+
_selectJsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_object_agg', As, NullableColumn<ColumnType<{
|
|
343
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
344
|
+
}>>>;
|
|
345
|
+
jsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
346
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
347
|
+
}>>>;
|
|
348
|
+
_jsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
349
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
350
|
+
}>>>;
|
|
351
|
+
selectJsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_object_agg', As, NullableColumn<ColumnType<{
|
|
352
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
353
|
+
}>>>;
|
|
354
|
+
_selectJsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_object_agg', As, NullableColumn<ColumnType<{
|
|
355
|
+
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
356
|
+
}>>>;
|
|
357
|
+
stringAgg<T extends Query>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
358
|
+
_stringAgg<T extends Query>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
359
|
+
selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
360
|
+
_selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
declare type BeforeCallback<T extends Query> = (query: T) => void | Promise<void>;
|
|
364
|
+
declare type AfterCallback<T extends Query> = (query: T, data: unknown) => void | Promise<void>;
|
|
365
|
+
declare class QueryCallbacks {
|
|
366
|
+
beforeQuery<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
367
|
+
_beforeQuery<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
368
|
+
afterQuery<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
369
|
+
_afterQuery<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
370
|
+
beforeInsert<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
371
|
+
_beforeInsert<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
372
|
+
afterInsert<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
373
|
+
_afterInsert<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
374
|
+
beforeUpdate<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
375
|
+
_beforeUpdate<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
376
|
+
afterUpdate<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
377
|
+
_afterUpdate<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
declare type ClearStatement = 'with' | 'select' | 'where' | 'union' | 'using' | 'join' | 'group' | 'order' | 'having' | 'limit' | 'offset' | 'counters';
|
|
381
|
+
declare class Clear {
|
|
382
|
+
clear<T extends Query>(this: T, ...clears: ClearStatement[]): T;
|
|
383
|
+
_clear<T extends Query>(this: T, ...clears: ClearStatement[]): T;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
declare type ColumnInfo = {
|
|
387
|
+
defaultValue: unknown;
|
|
388
|
+
type: string;
|
|
389
|
+
maxLength: number | null;
|
|
390
|
+
nullable: boolean;
|
|
391
|
+
};
|
|
392
|
+
declare class ColumnInfoMethods {
|
|
393
|
+
columnInfo<T extends Query, Column extends keyof T['shape'] | undefined = undefined>(this: T, column?: Column): SetQueryReturnsColumnInfo<T, Column>;
|
|
394
|
+
_columnInfo<T extends Query, Column extends keyof T['shape'] | undefined = undefined>(this: T, column?: Column): SetQueryReturnsColumnInfo<T, Column>;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
declare type DeleteArgs<T extends Query> = T['hasWhere'] extends true ? [forceAll?: boolean] : [true];
|
|
398
|
+
declare type DeleteResult<T extends Query> = T['hasSelect'] extends false ? SetQueryReturnsRowCount<T> : T;
|
|
399
|
+
declare class Delete {
|
|
400
|
+
del<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
401
|
+
_del<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
402
|
+
delete<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
403
|
+
_delete<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
declare type ForQueryBuilder<Q extends Query> = Q & {
|
|
407
|
+
noWait<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
408
|
+
_noWait<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
409
|
+
skipLocked<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
410
|
+
_skipLocked<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
411
|
+
};
|
|
412
|
+
declare class For {
|
|
413
|
+
forUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
414
|
+
_forUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
415
|
+
forNoKeyUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
416
|
+
_forNoKeyUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
417
|
+
forShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
418
|
+
_forShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
419
|
+
forKeyShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
420
|
+
_forKeyShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
declare type FromArgs<T extends Query> = [
|
|
424
|
+
first: string | Query | RawExpression | Exclude<keyof T['withData'], symbol | number>,
|
|
425
|
+
second?: string | {
|
|
426
|
+
as?: string;
|
|
427
|
+
only?: boolean;
|
|
428
|
+
}
|
|
429
|
+
];
|
|
430
|
+
declare type FromResult<T extends Query, Args extends FromArgs<T>> = Args[1] extends string ? SetQueryTableAlias<T, Args[1]> : Args[1] extends {
|
|
431
|
+
as: string;
|
|
432
|
+
} ? SetQueryTableAlias<T, Args[1]['as']> : Args[0] extends string ? SetQueryTableAlias<T, Args[0]> : Args[0] extends Query ? SetQueryTableAlias<T, AliasOrTable<Args[0]>> : T;
|
|
433
|
+
declare class From {
|
|
434
|
+
from<T extends Query, Args extends FromArgs<T>>(this: T, ...args: Args): FromResult<T, Args>;
|
|
435
|
+
_from<T extends Query, Args extends FromArgs<T>>(this: T, ...args: Args): FromResult<T, Args>;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
declare type GetArg<T extends QueryBase> = StringKey<keyof T['selectable']> | RawExpression;
|
|
439
|
+
declare type UnwrapRaw<T extends Query, Arg extends GetArg<T>> = Arg extends RawExpression ? Arg['__column'] : Exclude<Arg, RawExpression>;
|
|
440
|
+
declare type GetResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValue<T, UnwrapRaw<T, Arg>>;
|
|
441
|
+
declare type GetOptionalResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValueOptional<T, UnwrapRaw<T, Arg>>;
|
|
442
|
+
declare type getValueKey = typeof getValueKey;
|
|
443
|
+
declare const getValueKey: unique symbol;
|
|
444
|
+
declare class QueryGet {
|
|
445
|
+
get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
446
|
+
_get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
447
|
+
getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
448
|
+
_getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
declare type HavingArgObject<T extends Query, Agg extends keyof Aggregate1ArgumentTypes<T>> = {
|
|
452
|
+
[Column in Exclude<Aggregate1ArgumentTypes<T>[Agg], RawExpression>]?: T['selectable'][Column]['column']['type'] | (ColumnOperators<T['selectable'], Column> & AggregateOptions<T>);
|
|
453
|
+
};
|
|
454
|
+
declare type HavingArg<T extends Query = Query> = ({
|
|
455
|
+
[Agg in keyof Aggregate1ArgumentTypes<T>]?: HavingArgObject<T, Agg>;
|
|
456
|
+
} & {
|
|
457
|
+
count?: number | HavingArgObject<T, 'count'>;
|
|
458
|
+
}) | Query | RawExpression;
|
|
459
|
+
declare class Having {
|
|
460
|
+
having<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
461
|
+
_having<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
462
|
+
havingOr<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
463
|
+
_havingOr<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
464
|
+
}
|
|
465
|
+
|
|
233
466
|
declare type InsertData<T extends Query, DefaultKeys extends PropertyKey = keyof T[defaultsKey], Data = SetOptional<T['inputType'], DefaultKeys>> = [keyof T['relations']] extends [never] ? Data : OmitBelongsToForeignKeys<T['relations'], Data> & InsertRelationData<T>;
|
|
234
467
|
declare type OmitBelongsToForeignKeys<R extends RelationsBase, Data> = Omit<Data, {
|
|
235
468
|
[K in keyof R]: R[K] extends BelongsToRelation ? R[K]['options']['foreignKey'] : never;
|
|
@@ -241,14 +474,38 @@ declare type InsertBelongsToData<T extends Query, Key extends keyof T['relations
|
|
|
241
474
|
[K in Rel['options']['foreignKey']]: Rel['options']['foreignKey'] extends keyof T['inputType'] ? T['inputType'][Rel['options']['foreignKey']] : never;
|
|
242
475
|
}, keyof T[defaultsKey]> | {
|
|
243
476
|
[K in Key]: {
|
|
244
|
-
create
|
|
245
|
-
connect?:
|
|
477
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
478
|
+
connect?: never;
|
|
479
|
+
connectOrCreate?: never;
|
|
480
|
+
} | {
|
|
481
|
+
create?: never;
|
|
482
|
+
connect: WhereArg<Rel['model']>;
|
|
483
|
+
connectOrCreate?: never;
|
|
484
|
+
} | {
|
|
485
|
+
create?: never;
|
|
486
|
+
connect?: never;
|
|
487
|
+
connectOrCreate: {
|
|
488
|
+
where: WhereArg<Rel['model']>;
|
|
489
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
490
|
+
};
|
|
246
491
|
};
|
|
247
492
|
};
|
|
248
493
|
declare type InsertHasOneData<T extends Query, Key extends keyof T['relations'], Rel extends HasOneRelation> = 'through' extends Rel['options'] ? {} : {
|
|
249
494
|
[K in Key]?: {
|
|
250
|
-
create
|
|
251
|
-
connect?:
|
|
495
|
+
create: InsertData<Rel['nestedCreateQuery']>;
|
|
496
|
+
connect?: never;
|
|
497
|
+
connectOrCreate?: never;
|
|
498
|
+
} | {
|
|
499
|
+
create?: never;
|
|
500
|
+
connect: WhereArg<Rel['model']>;
|
|
501
|
+
connectOrCreate?: never;
|
|
502
|
+
} | {
|
|
503
|
+
create?: never;
|
|
504
|
+
connect?: never;
|
|
505
|
+
connectOrCreate: {
|
|
506
|
+
where?: WhereArg<Rel['model']>;
|
|
507
|
+
create?: InsertData<Rel['nestedCreateQuery']>;
|
|
508
|
+
};
|
|
252
509
|
};
|
|
253
510
|
};
|
|
254
511
|
declare type InsertHasManyData<T extends Query, Key extends keyof T['relations'], Rel extends HasManyRelation | HasAndBelongsToManyRelation> = 'through' extends Rel['options'] ? {} : {
|
|
@@ -298,21 +555,202 @@ declare class OnConflictQueryBuilder<T extends Query, Arg extends OnConflictArg<
|
|
|
298
555
|
merge(update?: keyof T['shape'] | (keyof T['shape'])[] | Partial<T['inputType']> | RawExpression): T;
|
|
299
556
|
}
|
|
300
557
|
|
|
301
|
-
declare type
|
|
302
|
-
[K in keyof T['
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
558
|
+
declare type JsonColumnName<T extends Pick<Query, 'selectable'>> = StringKey<{
|
|
559
|
+
[K in keyof T['selectable']]: T['selectable'][K]['column']['dataType'] extends 'jsonb' ? K : never;
|
|
560
|
+
}[keyof T['selectable']]>;
|
|
561
|
+
declare type ColumnOrJsonMethod<T extends Query> = JsonColumnName<T> | JsonItem;
|
|
562
|
+
declare type JsonSetResult<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string, Type extends ColumnType = Column extends keyof T['shape'] ? T['shape'][Column] : Column extends JsonItem ? Column['__json'][2] : ColumnType> = JsonItem<As, Type> & (Type extends ColumnType ? AddQuerySelect<T, Record<As, Type>> : T);
|
|
563
|
+
declare type JsonPathQueryResult<T extends Query, As extends string, Type extends ColumnType> = JsonItem & AddQuerySelect<T, {
|
|
564
|
+
[K in As]: Type;
|
|
565
|
+
}>;
|
|
566
|
+
declare class Json {
|
|
567
|
+
json<T extends Query>(this: T): SetQueryReturnsValueOptional<T, StringColumn>;
|
|
568
|
+
_json<T extends Query>(this: T): SetQueryReturnsValueOptional<T, StringColumn>;
|
|
569
|
+
jsonSet<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
570
|
+
as?: As;
|
|
571
|
+
createIfMissing?: boolean;
|
|
572
|
+
}): JsonSetResult<T, Column, As>;
|
|
573
|
+
_jsonSet<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
574
|
+
as?: As;
|
|
575
|
+
createIfMissing?: boolean;
|
|
576
|
+
}): JsonSetResult<T, Column, As>;
|
|
577
|
+
jsonInsert<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, ...args: [
|
|
578
|
+
column: Column,
|
|
579
|
+
path: Array<string | number>,
|
|
580
|
+
value: unknown,
|
|
581
|
+
options?: {
|
|
582
|
+
as?: As;
|
|
583
|
+
insertAfter?: boolean;
|
|
584
|
+
}
|
|
585
|
+
]): JsonSetResult<T, Column, As>;
|
|
586
|
+
_jsonInsert<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
587
|
+
as?: As;
|
|
588
|
+
insertAfter?: boolean;
|
|
589
|
+
}): JsonSetResult<T, Column, As>;
|
|
590
|
+
jsonRemove<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, ...args: [
|
|
591
|
+
column: Column,
|
|
592
|
+
path: Array<string | number>,
|
|
593
|
+
options?: {
|
|
594
|
+
as?: As;
|
|
595
|
+
}
|
|
596
|
+
]): JsonSetResult<T, Column, As>;
|
|
597
|
+
_jsonRemove<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, options?: {
|
|
598
|
+
as?: As;
|
|
599
|
+
}): JsonSetResult<T, Column, As>;
|
|
600
|
+
jsonPathQuery<T extends Query, As extends string, Type extends ColumnType>(this: T, ...args: [
|
|
601
|
+
type: Type,
|
|
602
|
+
column: ColumnOrJsonMethod<T>,
|
|
603
|
+
path: string,
|
|
604
|
+
as: As,
|
|
605
|
+
options?: {
|
|
606
|
+
vars?: string;
|
|
607
|
+
silent?: boolean;
|
|
608
|
+
}
|
|
609
|
+
]): JsonPathQueryResult<T, As, Type>;
|
|
610
|
+
_jsonPathQuery<T extends Query, As extends string, Type extends ColumnType>(this: T, type: Type, column: ColumnOrJsonMethod<T>, path: string, as: As, options?: {
|
|
611
|
+
vars?: string;
|
|
612
|
+
silent?: boolean;
|
|
613
|
+
}): JsonPathQueryResult<T, As, Type>;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
declare type QueryLogObject = {
|
|
617
|
+
colors: boolean;
|
|
618
|
+
beforeQuery(sql: Sql): unknown;
|
|
619
|
+
afterQuery(sql: Sql, logData: unknown): void;
|
|
620
|
+
onError(error: Error, sql: Sql, logData: unknown): void;
|
|
621
|
+
};
|
|
622
|
+
declare type QueryLogger = {
|
|
623
|
+
log(message: string): void;
|
|
624
|
+
error(message: string): void;
|
|
625
|
+
};
|
|
626
|
+
declare type QueryLogOptions = {
|
|
627
|
+
log?: boolean | Partial<QueryLogObject>;
|
|
628
|
+
logger?: QueryLogger;
|
|
629
|
+
};
|
|
630
|
+
declare const logColors: {
|
|
631
|
+
boldCyanBright: (message: string) => string;
|
|
632
|
+
boldBlue: (message: string) => string;
|
|
633
|
+
boldYellow: (message: string) => string;
|
|
634
|
+
boldMagenta: (message: string) => string;
|
|
635
|
+
boldRed: (message: string) => string;
|
|
636
|
+
};
|
|
637
|
+
declare const logParamToLogObject: (logger: QueryLogger, log: QueryLogOptions['log']) => QueryLogObject | undefined;
|
|
638
|
+
declare class QueryLog {
|
|
639
|
+
log<T extends Query>(this: T, log?: boolean): T;
|
|
640
|
+
_log<T extends Query>(this: T, log?: boolean): T;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
declare type SelectArg<T extends QueryBase> = StringKey<keyof T['selectable']> | (T['relations'] extends Record<string, Relation> ? StringKey<keyof T['relations']> : never) | SelectAsArg<T>;
|
|
644
|
+
declare type SelectAsArg<T extends QueryBase> = Record<string, StringKey<keyof T['selectable']> | RawExpression | ((q: T) => Query)>;
|
|
645
|
+
declare type SelectResult<T extends Query, Args extends SelectArg<T>[], SelectAsArgs = SimpleSpread<FilterTuple<Args, SelectAsArg<T>>>> = AddQuerySelect<T, {
|
|
646
|
+
[Arg in Args[number] as Arg extends keyof T['selectable'] ? T['selectable'][Arg]['as'] : Arg extends keyof T['relations'] ? Arg : never]: Arg extends keyof T['selectable'] ? T['selectable'][Arg]['column'] : T['relations'] extends Record<string, Relation> ? Arg extends keyof T['relations'] ? T['relations'][Arg]['returns'] extends 'many' ? ArrayOfColumnsObjects<T['relations'][Arg]['model']['result']> : T['relations'][Arg]['options']['required'] extends true ? ColumnsObject<T['relations'][Arg]['model']['result']> : NullableColumn<ColumnsObject<T['relations'][Arg]['model']['result']>> : never : never;
|
|
647
|
+
} & {
|
|
648
|
+
[K in keyof SelectAsArgs]: SelectAsArgs[K] extends keyof T['selectable'] ? T['selectable'][SelectAsArgs[K]]['column'] : SelectAsArgs[K] extends RawExpression ? SelectAsArgs[K]['__column'] : SelectAsArgs[K] extends (q: T) => Query ? SelectSubQueryResult<ReturnType<SelectAsArgs[K]>> : never;
|
|
649
|
+
}>;
|
|
650
|
+
declare type SelectSubQueryResult<Arg extends Query & {
|
|
651
|
+
[isRequiredRelationKey]?: boolean;
|
|
652
|
+
}> = Arg['returnType'] extends 'all' ? ArrayOfColumnsObjects<Arg['result']> : Arg['returnType'] extends 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? PluckResultColumnType<Arg['result']['pluck']> : Arg[isRequiredRelationKey] extends true ? ColumnsObject<Arg['result']> : NullableColumn<ColumnsObject<Arg['result']>>;
|
|
653
|
+
declare const addParserForRawExpression: (q: Query, key: string | getValueKey, raw: RawExpression) => void;
|
|
654
|
+
declare const addParserForSelectItem: <T extends Query>(q: T, as: string | getValueKey | undefined, key: string, arg: RawExpression<ColumnType<unknown, Operators, unknown>> | Exclude<keyof T["selectable"], number | symbol> | ((q: T) => Query)) => string | RawExpression | Query;
|
|
655
|
+
declare const addParserToQuery: (query: QueryData, key: string | getValueKey, parser: ColumnParser) => void;
|
|
656
|
+
declare const processSelectArg: <T extends Query>(q: T, as: string | undefined, arg: SelectArg<T>, columnAs?: string | getValueKey) => SelectItem;
|
|
657
|
+
declare class Select {
|
|
658
|
+
select<T extends Query, K extends SelectArg<T>[]>(this: T, ...args: K): SelectResult<T, K>;
|
|
659
|
+
_select<T extends Query, K extends SelectArg<T>[]>(this: T, ...args: K): SelectResult<T, K>;
|
|
660
|
+
selectAll<T extends Query>(this: T): QuerySelectAll<T>;
|
|
661
|
+
_selectAll<T extends Query>(this: T): QuerySelectAll<T>;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
interface QueryResultRow {
|
|
665
|
+
[column: string]: any;
|
|
666
|
+
}
|
|
667
|
+
declare type TypeParsers = Record<number, (input: string) => unknown>;
|
|
668
|
+
declare type QueryInput = string | {
|
|
669
|
+
text: string;
|
|
670
|
+
values?: unknown[];
|
|
671
|
+
};
|
|
672
|
+
declare type QueryResult<T extends QueryResultRow = any> = {
|
|
673
|
+
rowCount: number;
|
|
674
|
+
rows: T[];
|
|
675
|
+
};
|
|
676
|
+
declare type QueryArraysResult<R extends any[] = any[]> = {
|
|
677
|
+
rowCount: number;
|
|
678
|
+
rows: R[];
|
|
679
|
+
fields: {
|
|
680
|
+
name: string;
|
|
681
|
+
}[];
|
|
682
|
+
};
|
|
683
|
+
declare type AdapterOptions = Omit<PoolConfig, 'types'> & {
|
|
684
|
+
types?: TypeParsers;
|
|
685
|
+
};
|
|
686
|
+
declare class Adapter {
|
|
687
|
+
types: TypeParsers;
|
|
688
|
+
pool: Pool;
|
|
689
|
+
constructor({ types, ...config }: AdapterOptions);
|
|
690
|
+
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
691
|
+
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
692
|
+
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
693
|
+
destroy(): Promise<void>;
|
|
694
|
+
}
|
|
695
|
+
declare class TransactionAdapter implements Adapter {
|
|
696
|
+
pool: Pool;
|
|
697
|
+
client: PoolClient;
|
|
698
|
+
types: TypeParsers;
|
|
699
|
+
constructor(pool: Pool, client: PoolClient, types: TypeParsers);
|
|
700
|
+
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
701
|
+
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
702
|
+
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
703
|
+
destroy(): Promise<void>;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
declare type ThenResult<Res> = (resolve?: (value: Res) => any, reject?: (error: any) => any) => Promise<Res | never>;
|
|
707
|
+
declare const queryMethodByReturnType: Record<QueryReturnType, 'query' | 'arrays'>;
|
|
708
|
+
declare class Then {
|
|
709
|
+
then(this: Query, resolve?: (result: any) => any, reject?: (error: any) => any): Promise<any>;
|
|
710
|
+
}
|
|
711
|
+
declare const handleResult: CommonQueryData['handleResult'];
|
|
712
|
+
declare const parseResult: (q: Query, returnType: QueryReturnType, result: QueryResult) => unknown;
|
|
713
|
+
declare const parseRecord: (parsers: ColumnsParsers, row: any) => any;
|
|
714
|
+
|
|
715
|
+
declare class Transaction {
|
|
716
|
+
transaction<T extends Query, Result>(this: T, cb: (query: T) => Promise<Result>): Promise<Result>;
|
|
717
|
+
transacting<T extends Query>(this: T, query: Query): T;
|
|
718
|
+
_transacting<T extends Query>(this: T, query: Query): T;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
declare type UnionArg<T extends Query> = (Omit<Query, 'result'> & {
|
|
722
|
+
result: T['result'];
|
|
723
|
+
}) | RawExpression;
|
|
724
|
+
declare class Union {
|
|
725
|
+
union<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
726
|
+
_union<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
727
|
+
unionAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
728
|
+
_unionAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
729
|
+
intersect<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
730
|
+
_intersect<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
731
|
+
intersectAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
732
|
+
_intersectAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
733
|
+
except<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
734
|
+
_except<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
735
|
+
exceptAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
736
|
+
_exceptAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
declare type UpdateData<T extends Query> = {
|
|
740
|
+
[K in keyof T['type']]?: T['type'][K] | RawExpression;
|
|
741
|
+
} & (T['relations'] extends Record<string, Relation> ? {
|
|
742
|
+
[K in keyof T['relations']]?: T['relations'][K]['type'] extends 'belongsTo' ? {
|
|
743
|
+
disconnect: boolean;
|
|
744
|
+
} | {
|
|
745
|
+
set: WhereArg<T['relations'][K]['model']>;
|
|
746
|
+
} | {
|
|
747
|
+
delete: boolean;
|
|
748
|
+
} | {
|
|
749
|
+
update: UpdateData<T['relations'][K]['model']>;
|
|
750
|
+
} | {
|
|
751
|
+
create: InsertData<T['relations'][K]['nestedCreateQuery']>;
|
|
752
|
+
} | (T['returnType'] extends 'one' | 'oneOrThrow' ? {
|
|
753
|
+
upsert: {
|
|
316
754
|
update: UpdateData<T['relations'][K]['model']>;
|
|
317
755
|
create: InsertData<T['relations'][K]['nestedCreateQuery']>;
|
|
318
756
|
};
|
|
@@ -373,62 +811,255 @@ declare class Update {
|
|
|
373
811
|
_decrement<T extends Query>(this: T, data: ChangeCountArg<T>): UpdateResult<T>;
|
|
374
812
|
}
|
|
375
813
|
|
|
376
|
-
declare type
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
};
|
|
380
|
-
declare type NestedInsertManyItems = {
|
|
381
|
-
create?: Record<string, unknown>[];
|
|
382
|
-
connect?: WhereArg<QueryBase>[];
|
|
383
|
-
connectOrCreate?: {
|
|
384
|
-
where: WhereArg<QueryBase>;
|
|
385
|
-
create: Record<string, unknown>;
|
|
386
|
-
}[];
|
|
387
|
-
};
|
|
388
|
-
declare type NestedInsertItem = NestedInsertOneItem | NestedInsertManyItems;
|
|
389
|
-
declare type BelongsToNestedInsert = (query: Query, relationData: NestedInsertOneItem[]) => Promise<Record<string, unknown>[]>;
|
|
390
|
-
declare type HasOneNestedInsert = (query: Query, data: [
|
|
391
|
-
selfData: Record<string, unknown>,
|
|
392
|
-
relationData: NestedInsertOneItem
|
|
393
|
-
][]) => Promise<void>;
|
|
394
|
-
declare type HasManyNestedInsert = (query: Query, data: [
|
|
395
|
-
selfData: Record<string, unknown>,
|
|
396
|
-
relationData: NestedInsertManyItems
|
|
397
|
-
][]) => Promise<void>;
|
|
398
|
-
declare type NestedUpdateOneItem = {
|
|
399
|
-
disconnect?: boolean;
|
|
400
|
-
set?: WhereArg<QueryBase>;
|
|
401
|
-
delete?: boolean;
|
|
402
|
-
update?: UpdateData<Query>;
|
|
403
|
-
upsert?: {
|
|
404
|
-
update: UpdateData<Query>;
|
|
405
|
-
create: Record<string, unknown>;
|
|
406
|
-
};
|
|
407
|
-
create: Record<string, unknown>;
|
|
814
|
+
declare type UpsertData<T extends Query> = {
|
|
815
|
+
update: UpdateData<T>;
|
|
816
|
+
create: InsertData<T>;
|
|
408
817
|
};
|
|
409
|
-
declare type
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
delete?: MaybeArray<WhereArg<QueryBase>>;
|
|
413
|
-
update?: {
|
|
414
|
-
where: MaybeArray<WhereArg<QueryBase>>;
|
|
415
|
-
data: UpdateData<Query>;
|
|
416
|
-
};
|
|
417
|
-
create: Record<string, unknown>[];
|
|
818
|
+
declare type UpsertResult<T extends Query> = T['hasSelect'] extends true ? SetQueryReturnsOne<T> : SetQueryReturnsVoid<T>;
|
|
819
|
+
declare type UpsertThis = WhereResult<Query> & {
|
|
820
|
+
returnType: 'one' | 'oneOrThrow';
|
|
418
821
|
};
|
|
419
|
-
declare
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
declare type
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
822
|
+
declare class QueryUpsert {
|
|
823
|
+
upsert<T extends UpsertThis>(this: T, data: UpsertData<T>): UpsertResult<T>;
|
|
824
|
+
_upsert<T extends UpsertThis>(this: T, data: UpsertData<T>): UpsertResult<T>;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
declare type DbTableOptions = {
|
|
828
|
+
schema?: string;
|
|
829
|
+
} & QueryLogOptions;
|
|
830
|
+
interface Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> extends QueryMethods {
|
|
831
|
+
new (adapter: Adapter, queryBuilder: Db, table?: Table, shape?: Shape, options?: DbTableOptions): this;
|
|
832
|
+
adapter: Adapter;
|
|
833
|
+
queryBuilder: Db;
|
|
834
|
+
whereQueryBuilder: Query['whereQueryBuilder'];
|
|
835
|
+
table: Table;
|
|
836
|
+
shape: Shape;
|
|
837
|
+
schema: TableSchema<Shape>;
|
|
838
|
+
type: ColumnShapeOutput<Shape>;
|
|
839
|
+
inputType: ColumnShapeInput<Shape>;
|
|
840
|
+
returnType: 'all';
|
|
841
|
+
then: ThenResult<Pick<ColumnShapeOutput<Shape>, DefaultSelectColumns<Shape>[number]>[]>;
|
|
842
|
+
query: QueryData;
|
|
843
|
+
columns: (keyof ColumnShapeOutput<Shape>)[];
|
|
844
|
+
defaultSelectColumns: DefaultSelectColumns<Shape>;
|
|
845
|
+
columnsParsers?: ColumnsParsers;
|
|
846
|
+
result: Pick<Shape, DefaultSelectColumns<Shape>[number]>;
|
|
847
|
+
hasSelect: false;
|
|
848
|
+
hasWhere: boolean;
|
|
849
|
+
selectable: {
|
|
850
|
+
[K in keyof Shape]: {
|
|
851
|
+
as: K;
|
|
852
|
+
column: Shape[K];
|
|
853
|
+
};
|
|
854
|
+
} & {
|
|
855
|
+
[K in keyof Shape as `${Table}.${StringKey<K>}`]: {
|
|
856
|
+
as: K;
|
|
857
|
+
column: Shape[K];
|
|
858
|
+
};
|
|
859
|
+
};
|
|
860
|
+
tableAlias: undefined;
|
|
861
|
+
windows: PropertyKey[];
|
|
862
|
+
withData: Query['withData'];
|
|
863
|
+
joinedTables: Query['joinedTables'];
|
|
864
|
+
relations: Relations;
|
|
865
|
+
[defaultsKey]: Record<{
|
|
866
|
+
[K in keyof Shape]: Shape[K]['hasDefault'] extends true ? K : never;
|
|
867
|
+
}[keyof Shape], true>;
|
|
868
|
+
}
|
|
869
|
+
declare class Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> implements Query {
|
|
870
|
+
adapter: Adapter;
|
|
871
|
+
queryBuilder: Db;
|
|
872
|
+
table: Table;
|
|
873
|
+
shape: Shape;
|
|
874
|
+
whereQueryBuilder: typeof WhereQueryBuilder;
|
|
875
|
+
onQueryBuilder: typeof OnQueryBuilder;
|
|
876
|
+
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: Shape, options: DbTableOptions);
|
|
877
|
+
}
|
|
878
|
+
declare type DbResult<CT extends ColumnTypesBase> = Db & {
|
|
879
|
+
<Table extends string, Shape extends ColumnsShape = ColumnsShape>(table: Table, shape?: ((t: CT) => Shape) | Shape, options?: DbTableOptions): Db<Table, Shape>;
|
|
880
|
+
adapter: Adapter;
|
|
881
|
+
destroy: Adapter['destroy'];
|
|
882
|
+
};
|
|
883
|
+
declare type DbOptions<CT extends ColumnTypesBase = ColumnTypes> = ({
|
|
884
|
+
adapter: Adapter;
|
|
885
|
+
} | Omit<AdapterOptions, 'log'>) & QueryLogOptions & {
|
|
886
|
+
columnTypes?: CT;
|
|
887
|
+
};
|
|
888
|
+
declare const createDb: <CT extends ColumnTypesBase = {
|
|
889
|
+
smallint: () => SmallIntColumn;
|
|
890
|
+
integer: () => IntegerColumn;
|
|
891
|
+
bigint: () => BigIntColumn;
|
|
892
|
+
numeric: <Precision extends number | undefined = undefined, Scale extends number | undefined = undefined>(precision?: Precision | undefined, scale?: Scale | undefined) => DecimalColumn<Precision, Scale>;
|
|
893
|
+
decimal: <Precision_1 extends number | undefined = undefined, Scale_1 extends number | undefined = undefined>(precision?: Precision_1 | undefined, scale?: Scale_1 | undefined) => DecimalColumn<Precision_1, Scale_1>;
|
|
894
|
+
real: () => RealColumn;
|
|
895
|
+
doublePrecision: () => DoublePrecisionColumn;
|
|
896
|
+
smallSerial: () => SmallSerialColumn;
|
|
897
|
+
serial: () => SerialColumn;
|
|
898
|
+
bigSerial: () => BigSerialColumn;
|
|
899
|
+
money: () => MoneyColumn;
|
|
900
|
+
varchar: <Limit extends number | undefined = undefined>(limit?: Limit | undefined) => VarCharColumn<Limit>;
|
|
901
|
+
char: <Limit_1 extends number | undefined = undefined>(limit?: Limit_1 | undefined) => CharColumn<Limit_1>;
|
|
902
|
+
text: () => TextColumn;
|
|
903
|
+
string: () => TextColumn;
|
|
904
|
+
bytea: () => ByteaColumn;
|
|
905
|
+
date: () => DateColumn;
|
|
906
|
+
timestamp: <Precision_2 extends number | undefined = undefined>(precision?: Precision_2 | undefined) => TimestampColumn<Precision_2>;
|
|
907
|
+
timestampWithTimeZone: <Precision_3 extends number | undefined = undefined>(precision?: Precision_3 | undefined) => TimestampWithTimeZoneColumn<Precision_3>;
|
|
908
|
+
time: <Precision_4 extends number | undefined = undefined>(precision?: Precision_4 | undefined) => TimeColumn<Precision_4>;
|
|
909
|
+
timeWithTimeZone: <Precision_5 extends number | undefined = undefined>(precision?: Precision_5 | undefined) => TimeWithTimeZoneColumn<Precision_5>;
|
|
910
|
+
interval: <Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(fields?: Fields | undefined, precision?: Precision_6 | undefined) => IntervalColumn<Fields, Precision_6>;
|
|
911
|
+
boolean: () => BooleanColumn;
|
|
912
|
+
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) => EnumColumn<U, T>;
|
|
913
|
+
point: () => PointColumn;
|
|
914
|
+
line: () => LineColumn;
|
|
915
|
+
lseg: () => LsegColumn;
|
|
916
|
+
box: () => BoxColumn;
|
|
917
|
+
path: () => PathColumn;
|
|
918
|
+
polygon: () => PolygonColumn;
|
|
919
|
+
circle: () => CircleColumn;
|
|
920
|
+
cidr: () => CidrColumn;
|
|
921
|
+
inet: () => InetColumn;
|
|
922
|
+
macaddr: () => MacAddrColumn;
|
|
923
|
+
macaddr8: () => MacAddr8Column;
|
|
924
|
+
bit: <Length extends number>(length: Length) => BitColumn<Length>;
|
|
925
|
+
bitVarying: <Length_1 extends number | undefined = undefined>(length?: Length_1 | undefined) => BitVaryingColumn<Length_1 | undefined>;
|
|
926
|
+
tsvector: () => TsVectorColumn;
|
|
927
|
+
tsquery: () => TsQueryColumn;
|
|
928
|
+
uuid: () => UUIDColumn;
|
|
929
|
+
xml: () => XMLColumn;
|
|
930
|
+
json: <Type extends JSONTypeAny>(schemaOrFn: Type | ((j: {
|
|
931
|
+
set: <Value extends JSONTypeAny>(valueType: Value) => JSONSet<Value>;
|
|
932
|
+
tuple: <T_1 extends [] | JSONTupleItems, Rest extends JSONTypeAny | null = null>(items: T_1, rest?: Rest) => JSONTuple<T_1, Rest>;
|
|
933
|
+
union: <T_2 extends [JSONTypeAny, JSONTypeAny, ...JSONTypeAny[]]>(types: T_2) => JSONUnion<T_2>;
|
|
934
|
+
any: () => JSONAny;
|
|
935
|
+
bigint: () => JSONBigInt;
|
|
936
|
+
boolean: () => JSONBoolean;
|
|
937
|
+
date: () => JSONDate;
|
|
938
|
+
nan: () => JSONNaN;
|
|
939
|
+
never: () => JSONNever;
|
|
940
|
+
null: () => JSONNull;
|
|
941
|
+
number: () => JSONNumber;
|
|
942
|
+
string: () => JSONString;
|
|
943
|
+
undefined: () => JSONUndefined;
|
|
944
|
+
unknown: () => JSONUnknown;
|
|
945
|
+
void: () => JSONVoid;
|
|
946
|
+
array: <Type_1 extends JSONTypeAny>(element: Type_1) => JSONArray<Type_1, "many">;
|
|
947
|
+
discriminatedUnion: <Discriminator extends string, DiscriminatorValue extends Primitive, Types extends [JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, ...JSONDiscriminatedObject<Discriminator, DiscriminatorValue>[]]>(discriminator: Discriminator, options: Types) => JSONDiscriminatedUnion<Discriminator, DiscriminatorValue, Types[number]>;
|
|
948
|
+
enum: <U_1 extends string, T_3 extends [U_1, ...U_1[]]>(options: T_3) => JSONEnum<U_1, T_3>;
|
|
949
|
+
instanceOf: <T_4 extends new (...args: any[]) => any>(cls: T_4) => JSONInstanceOf<T_4>;
|
|
950
|
+
intersection: <Left extends JSONTypeAny, Right extends JSONTypeAny>(left: Left, right: Right) => JSONIntersection<Left, Right>;
|
|
951
|
+
lazy: <T_5 extends JSONTypeAny>(fn: () => T_5) => JSONLazy<T_5>;
|
|
952
|
+
literal: <T_6 extends Primitive>(value: T_6) => JSONLiteral<T_6>;
|
|
953
|
+
map: <Key extends JSONTypeAny, Value_1 extends JSONTypeAny>(keyType: Key, valueType: Value_1) => JSONMap<Key, Value_1>;
|
|
954
|
+
nativeEnum: <T_7 extends EnumLike>(givenEnum: T_7) => JSONNativeEnum<T_7>;
|
|
955
|
+
nullable: <T_8 extends JSONTypeAny>(type: T_8) => JSONNullable<T_8>;
|
|
956
|
+
nullish: <T_9 extends JSONTypeAny>(type: T_9) => JSONNullish<T_9>;
|
|
957
|
+
object: <T_10 extends JSONObjectShape, UnknownKeys extends UnknownKeysParam = "strip", Catchall extends JSONTypeAny = JSONTypeAny>(shape: T_10) => JSONObject<T_10, UnknownKeys, Catchall, JSONTypeAny extends Catchall ? addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never : (addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
|
|
958
|
+
[k: string]: Catchall["type"];
|
|
959
|
+
} extends infer T_12 ? { [k_2 in keyof T_12]: ((addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
|
|
960
|
+
[k: string]: Catchall["type"];
|
|
961
|
+
})[k_2]; } : never>;
|
|
962
|
+
optional: <T_13 extends JSONTypeAny>(type: T_13) => JSONOptional<T_13>;
|
|
963
|
+
record: typeof record;
|
|
964
|
+
}) => Type)) => JSONColumn<Type>;
|
|
965
|
+
jsonText: () => JSONTextColumn;
|
|
966
|
+
array: <Item extends ColumnType<unknown, Operators, unknown>>(item: Item) => ArrayColumn<Item>;
|
|
967
|
+
timestamps<T_14 extends ColumnType<unknown, Operators, unknown>>(this: {
|
|
968
|
+
timestamp(): T_14;
|
|
969
|
+
}): {
|
|
970
|
+
createdAt: T_14 & {
|
|
971
|
+
hasDefault: true;
|
|
972
|
+
};
|
|
973
|
+
updatedAt: T_14 & {
|
|
974
|
+
hasDefault: true;
|
|
975
|
+
};
|
|
976
|
+
};
|
|
977
|
+
primaryKey(columns: string[], options?: {
|
|
978
|
+
name?: string | undefined;
|
|
979
|
+
} | undefined): {};
|
|
980
|
+
index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
|
|
981
|
+
unique(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
|
|
982
|
+
foreignKey: {
|
|
983
|
+
<Model extends ForeignKeyModelWithColumns, Columns extends [Exclude<keyof InstanceType<Model>["columns"]["shape"], number | symbol>, ...Exclude<keyof InstanceType<Model>["columns"]["shape"], number | symbol>[]]>(columns: string[], fn: () => Model, foreignColumns: Columns, options?: ForeignKeyOptions | undefined): {};
|
|
984
|
+
<Table extends string, Columns_1 extends [string, ...string[]]>(columns: string[], table: Table, foreignColumns: Columns_1, options?: ForeignKeyOptions | undefined): {};
|
|
985
|
+
};
|
|
986
|
+
}>({ log, logger, columnTypes: ct, ...options }: DbOptions<CT>) => DbResult<CT>;
|
|
987
|
+
|
|
988
|
+
declare type WithArgsOptions = Omit<WithOptions, 'columns'> & {
|
|
989
|
+
columns?: boolean | string[];
|
|
990
|
+
};
|
|
991
|
+
declare type WithArgs = [string, ColumnsShape, RawExpression] | [string, WithArgsOptions, ColumnsShape, RawExpression] | [string, Query | ((qb: Db) => Query)] | [string, WithArgsOptions, Query | ((qb: Db) => Query)];
|
|
992
|
+
declare type WithShape<Args extends WithArgs> = Args[1] extends Query ? Args[1]['result'] : Args[1] extends (qb: Db) => Query ? ReturnType<Args[1]>['result'] : Args[2] extends Query ? Args[2]['result'] : Args[2] extends (qb: Db) => Query ? ReturnType<Args[2]>['result'] : Args[1] extends ColumnsShape ? Args[1] : Args[2] extends ColumnsShape ? Args[2] : Args[2] extends (t: ColumnTypes) => ColumnsShape ? ReturnType<Args[2]> : never;
|
|
993
|
+
declare type WithResult<T extends Query, Args extends WithArgs, Shape extends ColumnsShape> = AddQueryWith<T, {
|
|
994
|
+
table: Args[0];
|
|
995
|
+
shape: Shape;
|
|
996
|
+
type: ColumnShapeOutput<Shape>;
|
|
997
|
+
}>;
|
|
998
|
+
declare class With {
|
|
999
|
+
with<T extends Query, Args extends WithArgs, Shape extends ColumnsShape = WithShape<Args>>(this: T, ...args: Args): WithResult<T, Args, Shape>;
|
|
1000
|
+
_with<T extends Query, Args extends WithArgs, Shape extends ColumnsShape = WithShape<Args>>(this: T, ...args: Args): WithResult<T, Args, Shape>;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
declare type NestedInsertOneItem = {
|
|
1004
|
+
create?: Record<string, unknown>;
|
|
1005
|
+
connect?: WhereArg<QueryBase>;
|
|
1006
|
+
connectOrCreate?: {
|
|
1007
|
+
where: WhereArg<QueryBase>;
|
|
1008
|
+
create: Record<string, unknown>;
|
|
1009
|
+
};
|
|
1010
|
+
};
|
|
1011
|
+
declare type NestedInsertManyItems = {
|
|
1012
|
+
create?: Record<string, unknown>[];
|
|
1013
|
+
connect?: WhereArg<QueryBase>[];
|
|
1014
|
+
connectOrCreate?: {
|
|
1015
|
+
where: WhereArg<QueryBase>;
|
|
1016
|
+
create: Record<string, unknown>;
|
|
1017
|
+
}[];
|
|
1018
|
+
};
|
|
1019
|
+
declare type NestedInsertItem = NestedInsertOneItem | NestedInsertManyItems;
|
|
1020
|
+
declare type BelongsToNestedInsert = (query: Query, relationData: NestedInsertOneItem[]) => Promise<Record<string, unknown>[]>;
|
|
1021
|
+
declare type HasOneNestedInsert = (query: Query, data: [
|
|
1022
|
+
selfData: Record<string, unknown>,
|
|
1023
|
+
relationData: NestedInsertOneItem
|
|
1024
|
+
][]) => Promise<void>;
|
|
1025
|
+
declare type HasManyNestedInsert = (query: Query, data: [
|
|
1026
|
+
selfData: Record<string, unknown>,
|
|
1027
|
+
relationData: NestedInsertManyItems
|
|
1028
|
+
][]) => Promise<void>;
|
|
1029
|
+
declare type NestedUpdateOneItem = {
|
|
1030
|
+
disconnect?: boolean;
|
|
1031
|
+
set?: WhereArg<QueryBase>;
|
|
1032
|
+
delete?: boolean;
|
|
1033
|
+
update?: UpdateData<Query>;
|
|
1034
|
+
upsert?: {
|
|
1035
|
+
update: UpdateData<Query>;
|
|
1036
|
+
create: Record<string, unknown>;
|
|
1037
|
+
};
|
|
1038
|
+
create: Record<string, unknown>;
|
|
1039
|
+
};
|
|
1040
|
+
declare type NestedUpdateManyItems = {
|
|
1041
|
+
disconnect?: MaybeArray<WhereArg<QueryBase>>;
|
|
1042
|
+
set?: MaybeArray<WhereArg<QueryBase>>;
|
|
1043
|
+
delete?: MaybeArray<WhereArg<QueryBase>>;
|
|
1044
|
+
update?: {
|
|
1045
|
+
where: MaybeArray<WhereArg<QueryBase>>;
|
|
1046
|
+
data: UpdateData<Query>;
|
|
1047
|
+
};
|
|
1048
|
+
create: Record<string, unknown>[];
|
|
1049
|
+
};
|
|
1050
|
+
declare type NestedUpdateItem = NestedUpdateOneItem | NestedUpdateManyItems;
|
|
1051
|
+
declare type BelongsToNestedUpdate = (q: Query, update: Record<string, unknown>, params: NestedUpdateOneItem, state: {
|
|
1052
|
+
updateLater?: Record<string, unknown>;
|
|
1053
|
+
updateLaterPromises?: Promise<void>[];
|
|
1054
|
+
}) => boolean;
|
|
1055
|
+
declare type HasOneNestedUpdate = (query: Query, data: Record<string, unknown>[], relationData: NestedUpdateOneItem) => Promise<void>;
|
|
1056
|
+
declare type HasManyNestedUpdate = (query: Query, data: Record<string, unknown>[], relationData: NestedUpdateManyItems) => Promise<void>;
|
|
1057
|
+
declare type BaseRelation = {
|
|
1058
|
+
type: string;
|
|
1059
|
+
key: string;
|
|
1060
|
+
model: QueryWithTable;
|
|
1061
|
+
query: QueryWithTable;
|
|
1062
|
+
joinQuery(fromQuery: QueryBase, toQuery: Query): Query;
|
|
432
1063
|
nestedCreateQuery: Query;
|
|
433
1064
|
nestedInsert?: BelongsToNestedInsert | HasOneNestedInsert | HasManyNestedInsert;
|
|
434
1065
|
nestedUpdate?: BelongsToNestedUpdate | HasOneNestedUpdate | HasManyNestedUpdate;
|
|
@@ -497,95 +1128,9 @@ declare type RelationQuery<RelationName extends PropertyKey = string, Params ext
|
|
|
497
1128
|
[defaultsKey]: Record<Populate, true>;
|
|
498
1129
|
}) & Q;
|
|
499
1130
|
|
|
500
|
-
|
|
501
|
-
[column: string]: any;
|
|
502
|
-
}
|
|
503
|
-
declare type TypeParsers = Record<number, (input: string) => unknown>;
|
|
504
|
-
declare type QueryInput = string | {
|
|
1131
|
+
declare type Sql = {
|
|
505
1132
|
text: string;
|
|
506
|
-
values
|
|
507
|
-
};
|
|
508
|
-
declare type QueryResult<T extends QueryResultRow = any> = {
|
|
509
|
-
rowCount: number;
|
|
510
|
-
rows: T[];
|
|
511
|
-
};
|
|
512
|
-
declare type QueryArraysResult<R extends any[] = any[]> = {
|
|
513
|
-
rowCount: number;
|
|
514
|
-
rows: R[];
|
|
515
|
-
fields: {
|
|
516
|
-
name: string;
|
|
517
|
-
}[];
|
|
518
|
-
};
|
|
519
|
-
declare type AdapterOptions = Omit<PoolConfig, 'types'> & {
|
|
520
|
-
types?: TypeParsers;
|
|
521
|
-
};
|
|
522
|
-
declare class Adapter {
|
|
523
|
-
types: TypeParsers;
|
|
524
|
-
pool: Pool;
|
|
525
|
-
constructor({ types, ...config }: AdapterOptions);
|
|
526
|
-
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
527
|
-
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
528
|
-
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
529
|
-
destroy(): Promise<void>;
|
|
530
|
-
}
|
|
531
|
-
declare class TransactionAdapter implements Adapter {
|
|
532
|
-
pool: Pool;
|
|
533
|
-
client: PoolClient;
|
|
534
|
-
types: TypeParsers;
|
|
535
|
-
constructor(pool: Pool, client: PoolClient, types: TypeParsers);
|
|
536
|
-
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers): Promise<QueryResult<T>>;
|
|
537
|
-
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers): Promise<QueryArraysResult<R>>;
|
|
538
|
-
transaction<Result>(cb: (adapter: TransactionAdapter) => Promise<Result>): Promise<Result>;
|
|
539
|
-
destroy(): Promise<void>;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
declare type QueryLogObject = {
|
|
543
|
-
colors: boolean;
|
|
544
|
-
beforeQuery(sql: Sql): unknown;
|
|
545
|
-
afterQuery(sql: Sql, logData: unknown): void;
|
|
546
|
-
onError(error: Error, sql: Sql, logData: unknown): void;
|
|
547
|
-
};
|
|
548
|
-
declare type QueryLogger = {
|
|
549
|
-
log(message: string): void;
|
|
550
|
-
error(message: string): void;
|
|
551
|
-
};
|
|
552
|
-
declare type QueryLogOptions = {
|
|
553
|
-
log?: boolean | Partial<QueryLogObject>;
|
|
554
|
-
logger?: QueryLogger;
|
|
555
|
-
};
|
|
556
|
-
declare const logColors: {
|
|
557
|
-
boldCyanBright: (message: string) => string;
|
|
558
|
-
boldBlue: (message: string) => string;
|
|
559
|
-
boldYellow: (message: string) => string;
|
|
560
|
-
boldMagenta: (message: string) => string;
|
|
561
|
-
boldRed: (message: string) => string;
|
|
562
|
-
};
|
|
563
|
-
declare const logParamToLogObject: (logger: QueryLogger, log: QueryLogOptions['log']) => QueryLogObject | undefined;
|
|
564
|
-
declare class QueryLog {
|
|
565
|
-
log<T extends Query>(this: T, log?: boolean): T;
|
|
566
|
-
_log<T extends Query>(this: T, log?: boolean): T;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
declare type BeforeCallback<T extends Query> = (query: T) => void | Promise<void>;
|
|
570
|
-
declare type AfterCallback<T extends Query> = (query: T, data: unknown) => void | Promise<void>;
|
|
571
|
-
declare class QueryCallbacks {
|
|
572
|
-
beforeQuery<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
573
|
-
_beforeQuery<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
574
|
-
afterQuery<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
575
|
-
_afterQuery<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
576
|
-
beforeInsert<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
577
|
-
_beforeInsert<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
578
|
-
afterInsert<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
579
|
-
_afterInsert<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
580
|
-
beforeUpdate<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
581
|
-
_beforeUpdate<T extends Query>(this: T, cb: BeforeCallback<T>): T;
|
|
582
|
-
afterUpdate<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
583
|
-
_afterUpdate<T extends Query>(this: T, cb: AfterCallback<T>): T;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
declare type Sql = {
|
|
587
|
-
text: string;
|
|
588
|
-
values: unknown[];
|
|
1133
|
+
values: unknown[];
|
|
589
1134
|
};
|
|
590
1135
|
declare const queryKeysOfNotSimpleQuery: (keyof SelectQueryData)[];
|
|
591
1136
|
declare type CommonQueryData = {
|
|
@@ -821,523 +1366,6 @@ declare type UnionKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'INTERSECT ALL' |
|
|
|
821
1366
|
declare type OnConflictItem = string | string[] | RawExpression;
|
|
822
1367
|
declare type OnConflictMergeUpdate = string | string[] | Record<string, unknown> | RawExpression;
|
|
823
1368
|
|
|
824
|
-
declare type AggregateArg<T extends Query> = Expression<T> | Record<string, Expression<T>> | [Expression<T>, string];
|
|
825
|
-
declare type AggregateOptions<T extends Query = Query, As extends string | undefined = any> = {
|
|
826
|
-
as?: As;
|
|
827
|
-
distinct?: boolean;
|
|
828
|
-
order?: OrderArg<T> | OrderArg<T>[];
|
|
829
|
-
filter?: WhereArg<T>;
|
|
830
|
-
filterOr?: WhereArg<T>[];
|
|
831
|
-
withinGroup?: boolean;
|
|
832
|
-
over?: T['windows'][number] | WindowArgDeclaration<T>;
|
|
833
|
-
};
|
|
834
|
-
declare type Aggregate1ArgumentTypes<T extends Query = Query, C extends ColumnType = ColumnType> = {
|
|
835
|
-
count: Expression<T, C>;
|
|
836
|
-
avg: NumberExpression<T, C>;
|
|
837
|
-
min: Expression<T, C>;
|
|
838
|
-
max: Expression<T, C>;
|
|
839
|
-
sum: NumberExpression<T, C>;
|
|
840
|
-
bitAnd: NumberExpression<T, C>;
|
|
841
|
-
bitOr: NumberExpression<T, C>;
|
|
842
|
-
boolAnd: BooleanExpression<T, C>;
|
|
843
|
-
boolOr: BooleanExpression<T, C>;
|
|
844
|
-
every: BooleanExpression<T, C>;
|
|
845
|
-
jsonAgg: Expression<T, C>;
|
|
846
|
-
jsonbAgg: Expression<T, C>;
|
|
847
|
-
xmlAgg: Expression<T, C>;
|
|
848
|
-
};
|
|
849
|
-
declare const aggregate1FunctionNames: {
|
|
850
|
-
readonly count: "count";
|
|
851
|
-
readonly avg: "avg";
|
|
852
|
-
readonly min: "min";
|
|
853
|
-
readonly max: "max";
|
|
854
|
-
readonly sum: "sum";
|
|
855
|
-
readonly bitAnd: "bit_and";
|
|
856
|
-
readonly bitOr: "bit_or";
|
|
857
|
-
readonly boolAnd: "bool_and";
|
|
858
|
-
readonly boolOr: "bool_or";
|
|
859
|
-
readonly every: "every";
|
|
860
|
-
readonly jsonAgg: "json_agg";
|
|
861
|
-
readonly jsonbAgg: "jsonb_agg";
|
|
862
|
-
readonly xmlAgg: "xmlagg";
|
|
863
|
-
};
|
|
864
|
-
declare type SelectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType> = AddQuerySelect<T, Record<CoalesceString<As, Func>, Value>>;
|
|
865
|
-
declare type AT1<T extends Query> = Aggregate1ArgumentTypes<T>;
|
|
866
|
-
declare type WindowFunctionOptions<T extends Query = Query, As extends string | undefined = any> = {
|
|
867
|
-
as?: As;
|
|
868
|
-
} & WindowArgDeclaration<T>;
|
|
869
|
-
declare class Aggregate {
|
|
870
|
-
selectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType>(this: T, functionName: Func, arg: AggregateArg<T>, options?: AggregateOptions<T, As>): SelectAgg<T, Func, As, Value>;
|
|
871
|
-
_selectAgg<T extends Query, Func extends string, As extends string | undefined, Value extends ColumnType>(this: T, functionName: Func, arg: AggregateArg<T>, options?: AggregateOptions<T, As>, columnType?: ColumnType): SelectAgg<T, Func, As, Value>;
|
|
872
|
-
count<T extends Query>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T>): SetQueryReturnsValue<T, NumberColumn>;
|
|
873
|
-
_count<T extends Query>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T>): SetQueryReturnsValue<T, NumberColumn>;
|
|
874
|
-
selectCount<T extends Query, As extends string | undefined = undefined>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T, As>): SelectAgg<T, 'count', As, NumberColumn>;
|
|
875
|
-
_selectCount<T extends Query, As extends string | undefined = undefined>(this: T, arg?: AT1<T>['count'] | '*', options?: AggregateOptions<T, As>): SelectAgg<T, 'count', As, NumberColumn>;
|
|
876
|
-
avg<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['avg'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
877
|
-
_avg<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['avg'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
878
|
-
selectAvg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'avg', As, NullableColumn<NumberColumn>>;
|
|
879
|
-
_selectAvg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'avg', As, NullableColumn<NumberColumn>>;
|
|
880
|
-
min<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['min'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
881
|
-
_min<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['min'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
882
|
-
selectMin<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'min', As, NullableColumn<NumberColumn>>;
|
|
883
|
-
_selectMin<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'min', As, NullableColumn<NumberColumn>>;
|
|
884
|
-
max<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['max'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
885
|
-
_max<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['max'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
886
|
-
selectMax<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'max', As, NullableColumn<NumberColumn>>;
|
|
887
|
-
_selectMax<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'max', As, NullableColumn<NumberColumn>>;
|
|
888
|
-
sum<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['sum'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
889
|
-
_sum<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['sum'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
890
|
-
selectSum<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'sum', As, NullableColumn<NumberColumn>>;
|
|
891
|
-
_selectSum<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'sum', As, NullableColumn<NumberColumn>>;
|
|
892
|
-
bitAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
893
|
-
_bitAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
894
|
-
selectBitAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_and', As, NullableColumn<NumberColumn>>;
|
|
895
|
-
_selectBitAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_and', As, NullableColumn<NumberColumn>>;
|
|
896
|
-
bitOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
897
|
-
_bitOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['bitOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<NumberColumn>>;
|
|
898
|
-
selectBitOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_or', As, NullableColumn<NumberColumn>>;
|
|
899
|
-
_selectBitOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bit_or', As, NullableColumn<NumberColumn>>;
|
|
900
|
-
boolAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
901
|
-
_boolAnd<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolAnd'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
902
|
-
selectBoolAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_and', As, NullableColumn<BooleanColumn>>;
|
|
903
|
-
_selectBoolAnd<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_and', As, NullableColumn<BooleanColumn>>;
|
|
904
|
-
boolOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
905
|
-
_boolOr<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['boolOr'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
906
|
-
selectBoolOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_or', As, NullableColumn<BooleanColumn>>;
|
|
907
|
-
_selectBoolOr<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'bool_or', As, NullableColumn<BooleanColumn>>;
|
|
908
|
-
every<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['every'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
909
|
-
_every<T extends Query>(this: T, arg: Aggregate1ArgumentTypes<T>['every'], options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<BooleanColumn>>;
|
|
910
|
-
selectEvery<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'every', As, NullableColumn<BooleanColumn>>;
|
|
911
|
-
_selectEvery<T extends Query, As extends string | undefined = undefined>(this: T, arg: Expression<T>, options?: AggregateOptions<T, As>): SelectAgg<T, 'every', As, NullableColumn<BooleanColumn>>;
|
|
912
|
-
jsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
913
|
-
_jsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
914
|
-
selectJsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
915
|
-
_selectJsonAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
916
|
-
jsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
917
|
-
_jsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
918
|
-
selectJsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
919
|
-
_selectJsonbAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['jsonbAgg'], As extends string | undefined = undefined>(this: T, arg: Expr, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_agg', As, NullableColumn<ArrayColumn<ExpressionOutput<T, Expr>>>>;
|
|
920
|
-
xmlAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['xmlAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
921
|
-
_xmlAgg<T extends Query, Expr extends Aggregate1ArgumentTypes<T>['xmlAgg']>(this: T, arg: Expr, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
922
|
-
selectXmlAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Aggregate1ArgumentTypes<T>['xmlAgg'], options?: AggregateOptions<T, As>): SelectAgg<T, 'xmlagg', As, NullableColumn<StringColumn>>;
|
|
923
|
-
_selectXmlAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: Aggregate1ArgumentTypes<T>['xmlAgg'], options?: AggregateOptions<T, As>): SelectAgg<T, 'xmlagg', As, NullableColumn<StringColumn>>;
|
|
924
|
-
jsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
925
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
926
|
-
}>>>;
|
|
927
|
-
_jsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
928
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
929
|
-
}>>>;
|
|
930
|
-
selectJsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_object_agg', As, NullableColumn<ColumnType<{
|
|
931
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
932
|
-
}>>>;
|
|
933
|
-
_selectJsonObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'json_object_agg', As, NullableColumn<ColumnType<{
|
|
934
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
935
|
-
}>>>;
|
|
936
|
-
jsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
937
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
938
|
-
}>>>;
|
|
939
|
-
_jsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>>(this: T, obj: Obj, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<ColumnType<{
|
|
940
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
941
|
-
}>>>;
|
|
942
|
-
selectJsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_object_agg', As, NullableColumn<ColumnType<{
|
|
943
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
944
|
-
}>>>;
|
|
945
|
-
_selectJsonbObjectAgg<T extends Query, Obj extends Record<string, Expression<T>>, As extends string | undefined = undefined>(this: T, obj: Obj, options?: AggregateOptions<T, As>): SelectAgg<T, 'jsonb_object_agg', As, NullableColumn<ColumnType<{
|
|
946
|
-
[K in keyof Obj]: ExpressionOutput<T, Obj[K]>['type'];
|
|
947
|
-
}>>>;
|
|
948
|
-
stringAgg<T extends Query>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
949
|
-
_stringAgg<T extends Query>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T>): SetQueryReturnsValue<T, NullableColumn<StringColumn>>;
|
|
950
|
-
selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
951
|
-
_selectStringAgg<T extends Query, As extends string | undefined = undefined>(this: T, arg: StringExpression<T>, delimiter: string, options?: AggregateOptions<T, As>): SelectAgg<T, 'string_agg', As, NullableColumn<StringColumn>>;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
declare type ClearStatement = 'with' | 'select' | 'where' | 'union' | 'using' | 'join' | 'group' | 'order' | 'having' | 'limit' | 'offset' | 'counters';
|
|
955
|
-
declare class Clear {
|
|
956
|
-
clear<T extends Query>(this: T, ...clears: ClearStatement[]): T;
|
|
957
|
-
_clear<T extends Query>(this: T, ...clears: ClearStatement[]): T;
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
declare type ColumnInfo = {
|
|
961
|
-
defaultValue: unknown;
|
|
962
|
-
type: string;
|
|
963
|
-
maxLength: number | null;
|
|
964
|
-
nullable: boolean;
|
|
965
|
-
};
|
|
966
|
-
declare class ColumnInfoMethods {
|
|
967
|
-
columnInfo<T extends Query, Column extends keyof T['shape'] | undefined = undefined>(this: T, column?: Column): SetQueryReturnsColumnInfo<T, Column>;
|
|
968
|
-
_columnInfo<T extends Query, Column extends keyof T['shape'] | undefined = undefined>(this: T, column?: Column): SetQueryReturnsColumnInfo<T, Column>;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
declare type DeleteArgs<T extends Query> = T['hasWhere'] extends true ? [forceAll?: boolean] : [true];
|
|
972
|
-
declare type DeleteResult<T extends Query> = T['hasSelect'] extends false ? SetQueryReturnsRowCount<T> : T;
|
|
973
|
-
declare class Delete {
|
|
974
|
-
del<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
975
|
-
_del<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
976
|
-
delete<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
977
|
-
_delete<T extends Query>(this: T, ...args: DeleteArgs<T>): DeleteResult<T>;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
declare type ForQueryBuilder<Q extends Query> = Q & {
|
|
981
|
-
noWait<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
982
|
-
_noWait<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
983
|
-
skipLocked<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
984
|
-
_skipLocked<T extends ForQueryBuilder<Q>>(this: T): T;
|
|
985
|
-
};
|
|
986
|
-
declare class For {
|
|
987
|
-
forUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
988
|
-
_forUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
989
|
-
forNoKeyUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
990
|
-
_forNoKeyUpdate<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
991
|
-
forShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
992
|
-
_forShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
993
|
-
forKeyShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
994
|
-
_forKeyShare<T extends Query>(this: T, tableNames?: string[] | RawExpression): ForQueryBuilder<T>;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
declare type FromArgs<T extends Query> = [
|
|
998
|
-
first: string | Query | RawExpression | Exclude<keyof T['withData'], symbol | number>,
|
|
999
|
-
second?: string | {
|
|
1000
|
-
as?: string;
|
|
1001
|
-
only?: boolean;
|
|
1002
|
-
}
|
|
1003
|
-
];
|
|
1004
|
-
declare type FromResult<T extends Query, Args extends FromArgs<T>> = Args[1] extends string ? SetQueryTableAlias<T, Args[1]> : Args[1] extends {
|
|
1005
|
-
as: string;
|
|
1006
|
-
} ? SetQueryTableAlias<T, Args[1]['as']> : Args[0] extends string ? SetQueryTableAlias<T, Args[0]> : Args[0] extends Query ? SetQueryTableAlias<T, AliasOrTable<Args[0]>> : T;
|
|
1007
|
-
declare class From {
|
|
1008
|
-
from<T extends Query, Args extends FromArgs<T>>(this: T, ...args: Args): FromResult<T, Args>;
|
|
1009
|
-
_from<T extends Query, Args extends FromArgs<T>>(this: T, ...args: Args): FromResult<T, Args>;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
declare type GetArg<T extends QueryBase> = StringKey<keyof T['selectable']> | RawExpression;
|
|
1013
|
-
declare type UnwrapRaw<T extends Query, Arg extends GetArg<T>> = Arg extends RawExpression ? Arg['__column'] : Exclude<Arg, RawExpression>;
|
|
1014
|
-
declare type GetResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValue<T, UnwrapRaw<T, Arg>>;
|
|
1015
|
-
declare type GetOptionalResult<T extends Query, Arg extends GetArg<T>> = SetQueryReturnsValueOptional<T, UnwrapRaw<T, Arg>>;
|
|
1016
|
-
declare type getValueKey = typeof getValueKey;
|
|
1017
|
-
declare const getValueKey: unique symbol;
|
|
1018
|
-
declare class QueryGet {
|
|
1019
|
-
get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
1020
|
-
_get<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetResult<T, Arg>;
|
|
1021
|
-
getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
1022
|
-
_getOptional<T extends Query, Arg extends GetArg<T>>(this: T, arg: Arg): GetOptionalResult<T, Arg>;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
declare type HavingArgObject<T extends Query, Agg extends keyof Aggregate1ArgumentTypes<T>> = {
|
|
1026
|
-
[Column in Exclude<Aggregate1ArgumentTypes<T>[Agg], RawExpression>]?: T['selectable'][Column]['column']['type'] | (ColumnOperators<T['selectable'], Column> & AggregateOptions<T>);
|
|
1027
|
-
};
|
|
1028
|
-
declare type HavingArg<T extends Query = Query> = ({
|
|
1029
|
-
[Agg in keyof Aggregate1ArgumentTypes<T>]?: HavingArgObject<T, Agg>;
|
|
1030
|
-
} & {
|
|
1031
|
-
count?: number | HavingArgObject<T, 'count'>;
|
|
1032
|
-
}) | Query | RawExpression;
|
|
1033
|
-
declare class Having {
|
|
1034
|
-
having<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
1035
|
-
_having<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
1036
|
-
havingOr<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
1037
|
-
_havingOr<T extends Query>(this: T, ...args: HavingArg<T>[]): T;
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
declare type JsonColumnName<T extends Pick<Query, 'selectable'>> = StringKey<{
|
|
1041
|
-
[K in keyof T['selectable']]: T['selectable'][K]['column']['dataType'] extends 'jsonb' ? K : never;
|
|
1042
|
-
}[keyof T['selectable']]>;
|
|
1043
|
-
declare type ColumnOrJsonMethod<T extends Query> = JsonColumnName<T> | JsonItem;
|
|
1044
|
-
declare type JsonSetResult<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string, Type extends ColumnType = Column extends keyof T['shape'] ? T['shape'][Column] : Column extends JsonItem ? Column['__json'][2] : ColumnType> = JsonItem<As, Type> & (Type extends ColumnType ? AddQuerySelect<T, Record<As, Type>> : T);
|
|
1045
|
-
declare type JsonPathQueryResult<T extends Query, As extends string, Type extends ColumnType> = JsonItem & AddQuerySelect<T, {
|
|
1046
|
-
[K in As]: Type;
|
|
1047
|
-
}>;
|
|
1048
|
-
declare class Json {
|
|
1049
|
-
json<T extends Query>(this: T): SetQueryReturnsValueOptional<T, StringColumn>;
|
|
1050
|
-
_json<T extends Query>(this: T): SetQueryReturnsValueOptional<T, StringColumn>;
|
|
1051
|
-
jsonSet<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
1052
|
-
as?: As;
|
|
1053
|
-
createIfMissing?: boolean;
|
|
1054
|
-
}): JsonSetResult<T, Column, As>;
|
|
1055
|
-
_jsonSet<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
1056
|
-
as?: As;
|
|
1057
|
-
createIfMissing?: boolean;
|
|
1058
|
-
}): JsonSetResult<T, Column, As>;
|
|
1059
|
-
jsonInsert<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, ...args: [
|
|
1060
|
-
column: Column,
|
|
1061
|
-
path: Array<string | number>,
|
|
1062
|
-
value: unknown,
|
|
1063
|
-
options?: {
|
|
1064
|
-
as?: As;
|
|
1065
|
-
insertAfter?: boolean;
|
|
1066
|
-
}
|
|
1067
|
-
]): JsonSetResult<T, Column, As>;
|
|
1068
|
-
_jsonInsert<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, value: unknown, options?: {
|
|
1069
|
-
as?: As;
|
|
1070
|
-
insertAfter?: boolean;
|
|
1071
|
-
}): JsonSetResult<T, Column, As>;
|
|
1072
|
-
jsonRemove<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, ...args: [
|
|
1073
|
-
column: Column,
|
|
1074
|
-
path: Array<string | number>,
|
|
1075
|
-
options?: {
|
|
1076
|
-
as?: As;
|
|
1077
|
-
}
|
|
1078
|
-
]): JsonSetResult<T, Column, As>;
|
|
1079
|
-
_jsonRemove<T extends Query, Column extends ColumnOrJsonMethod<T>, As extends string = Column extends JsonItem ? Column['__json'][1] : Column>(this: T, column: Column, path: Array<string | number>, options?: {
|
|
1080
|
-
as?: As;
|
|
1081
|
-
}): JsonSetResult<T, Column, As>;
|
|
1082
|
-
jsonPathQuery<T extends Query, As extends string, Type extends ColumnType>(this: T, ...args: [
|
|
1083
|
-
type: Type,
|
|
1084
|
-
column: ColumnOrJsonMethod<T>,
|
|
1085
|
-
path: string,
|
|
1086
|
-
as: As,
|
|
1087
|
-
options?: {
|
|
1088
|
-
vars?: string;
|
|
1089
|
-
silent?: boolean;
|
|
1090
|
-
}
|
|
1091
|
-
]): JsonPathQueryResult<T, As, Type>;
|
|
1092
|
-
_jsonPathQuery<T extends Query, As extends string, Type extends ColumnType>(this: T, type: Type, column: ColumnOrJsonMethod<T>, path: string, as: As, options?: {
|
|
1093
|
-
vars?: string;
|
|
1094
|
-
silent?: boolean;
|
|
1095
|
-
}): JsonPathQueryResult<T, As, Type>;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
declare type SelectArg<T extends QueryBase> = StringKey<keyof T['selectable']> | (T['relations'] extends Record<string, Relation> ? StringKey<keyof T['relations']> : never) | SelectAsArg<T>;
|
|
1099
|
-
declare type SelectAsArg<T extends QueryBase> = Record<string, StringKey<keyof T['selectable']> | RawExpression | ((q: T) => Query)>;
|
|
1100
|
-
declare type SelectResult<T extends Query, Args extends SelectArg<T>[], SelectAsArgs = SimpleSpread<FilterTuple<Args, SelectAsArg<T>>>> = AddQuerySelect<T, {
|
|
1101
|
-
[Arg in Args[number] as Arg extends keyof T['selectable'] ? T['selectable'][Arg]['as'] : Arg extends keyof T['relations'] ? Arg : never]: Arg extends keyof T['selectable'] ? T['selectable'][Arg]['column'] : T['relations'] extends Record<string, Relation> ? Arg extends keyof T['relations'] ? T['relations'][Arg]['returns'] extends 'many' ? ArrayOfColumnsObjects<T['relations'][Arg]['model']['result']> : T['relations'][Arg]['options']['required'] extends true ? ColumnsObject<T['relations'][Arg]['model']['result']> : NullableColumn<ColumnsObject<T['relations'][Arg]['model']['result']>> : never : never;
|
|
1102
|
-
} & {
|
|
1103
|
-
[K in keyof SelectAsArgs]: SelectAsArgs[K] extends keyof T['selectable'] ? T['selectable'][SelectAsArgs[K]]['column'] : SelectAsArgs[K] extends RawExpression ? SelectAsArgs[K]['__column'] : SelectAsArgs[K] extends (q: T) => Query ? SelectSubQueryResult<ReturnType<SelectAsArgs[K]>> : never;
|
|
1104
|
-
}>;
|
|
1105
|
-
declare type SelectSubQueryResult<Arg extends Query & {
|
|
1106
|
-
[isRequiredRelationKey]?: boolean;
|
|
1107
|
-
}> = Arg['returnType'] extends 'all' ? ArrayOfColumnsObjects<Arg['result']> : Arg['returnType'] extends 'valueOrThrow' ? Arg['result']['value'] : Arg['returnType'] extends 'pluck' ? PluckResultColumnType<Arg['result']['pluck']> : Arg[isRequiredRelationKey] extends true ? ColumnsObject<Arg['result']> : NullableColumn<ColumnsObject<Arg['result']>>;
|
|
1108
|
-
declare const addParserForRawExpression: (q: Query, key: string | getValueKey, raw: RawExpression) => void;
|
|
1109
|
-
declare const addParserForSelectItem: <T extends Query>(q: T, as: string | getValueKey | undefined, key: string, arg: RawExpression<ColumnType<unknown, Operators, unknown>> | Exclude<keyof T["selectable"], number | symbol> | ((q: T) => Query)) => string | RawExpression | Query;
|
|
1110
|
-
declare const addParserToQuery: (query: QueryData, key: string | getValueKey, parser: ColumnParser) => void;
|
|
1111
|
-
declare const processSelectArg: <T extends Query>(q: T, as: string | undefined, arg: SelectArg<T>, columnAs?: string | getValueKey) => SelectItem;
|
|
1112
|
-
declare class Select {
|
|
1113
|
-
select<T extends Query, K extends SelectArg<T>[]>(this: T, ...args: K): SelectResult<T, K>;
|
|
1114
|
-
_select<T extends Query, K extends SelectArg<T>[]>(this: T, ...args: K): SelectResult<T, K>;
|
|
1115
|
-
selectAll<T extends Query>(this: T): QuerySelectAll<T>;
|
|
1116
|
-
_selectAll<T extends Query>(this: T): QuerySelectAll<T>;
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
declare type ThenResult<Res> = (resolve?: (value: Res) => any, reject?: (error: any) => any) => Promise<Res | never>;
|
|
1120
|
-
declare const queryMethodByReturnType: Record<QueryReturnType, 'query' | 'arrays'>;
|
|
1121
|
-
declare class Then {
|
|
1122
|
-
then(this: Query, resolve?: (result: any) => any, reject?: (error: any) => any): Promise<any>;
|
|
1123
|
-
}
|
|
1124
|
-
declare const handleResult: CommonQueryData['handleResult'];
|
|
1125
|
-
declare const parseResult: (q: Query, returnType: QueryReturnType, result: QueryResult) => unknown;
|
|
1126
|
-
declare const parseRecord: (parsers: ColumnsParsers, row: any) => any;
|
|
1127
|
-
|
|
1128
|
-
declare class Transaction {
|
|
1129
|
-
transaction<T extends Query, Result>(this: T, cb: (query: T) => Promise<Result>): Promise<Result>;
|
|
1130
|
-
transacting<T extends Query>(this: T, query: Query): T;
|
|
1131
|
-
_transacting<T extends Query>(this: T, query: Query): T;
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
declare type UnionArg<T extends Query> = (Omit<Query, 'result'> & {
|
|
1135
|
-
result: T['result'];
|
|
1136
|
-
}) | RawExpression;
|
|
1137
|
-
declare class Union {
|
|
1138
|
-
union<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1139
|
-
_union<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1140
|
-
unionAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1141
|
-
_unionAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1142
|
-
intersect<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1143
|
-
_intersect<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1144
|
-
intersectAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1145
|
-
_intersectAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1146
|
-
except<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1147
|
-
_except<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1148
|
-
exceptAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1149
|
-
_exceptAll<T extends Query>(this: T, args: UnionArg<T>[], wrap?: boolean): T;
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
declare type UpsertData<T extends Query> = {
|
|
1153
|
-
update: UpdateData<T>;
|
|
1154
|
-
create: InsertData<T>;
|
|
1155
|
-
};
|
|
1156
|
-
declare type UpsertResult<T extends Query> = T['hasSelect'] extends true ? SetQueryReturnsOne<T> : SetQueryReturnsVoid<T>;
|
|
1157
|
-
declare type UpsertThis = WhereResult<Query> & {
|
|
1158
|
-
returnType: 'one' | 'oneOrThrow';
|
|
1159
|
-
};
|
|
1160
|
-
declare class QueryUpsert {
|
|
1161
|
-
upsert<T extends UpsertThis>(this: T, data: UpsertData<T>): UpsertResult<T>;
|
|
1162
|
-
_upsert<T extends UpsertThis>(this: T, data: UpsertData<T>): UpsertResult<T>;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
declare type DbTableOptions = {
|
|
1166
|
-
schema?: string;
|
|
1167
|
-
} & QueryLogOptions;
|
|
1168
|
-
interface Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> extends QueryMethods {
|
|
1169
|
-
new (adapter: Adapter, queryBuilder: Db, table?: Table, shape?: Shape, options?: DbTableOptions): this;
|
|
1170
|
-
adapter: Adapter;
|
|
1171
|
-
queryBuilder: Db;
|
|
1172
|
-
whereQueryBuilder: Query['whereQueryBuilder'];
|
|
1173
|
-
table: Table;
|
|
1174
|
-
shape: Shape;
|
|
1175
|
-
schema: TableSchema<Shape>;
|
|
1176
|
-
type: ColumnShapeOutput<Shape>;
|
|
1177
|
-
inputType: ColumnShapeInput<Shape>;
|
|
1178
|
-
returnType: 'all';
|
|
1179
|
-
then: ThenResult<Pick<ColumnShapeOutput<Shape>, DefaultSelectColumns<Shape>[number]>[]>;
|
|
1180
|
-
query: QueryData;
|
|
1181
|
-
columns: (keyof ColumnShapeOutput<Shape>)[];
|
|
1182
|
-
defaultSelectColumns: DefaultSelectColumns<Shape>;
|
|
1183
|
-
columnsParsers?: ColumnsParsers;
|
|
1184
|
-
result: Pick<Shape, DefaultSelectColumns<Shape>[number]>;
|
|
1185
|
-
hasSelect: false;
|
|
1186
|
-
hasWhere: boolean;
|
|
1187
|
-
selectable: {
|
|
1188
|
-
[K in keyof Shape]: {
|
|
1189
|
-
as: K;
|
|
1190
|
-
column: Shape[K];
|
|
1191
|
-
};
|
|
1192
|
-
} & {
|
|
1193
|
-
[K in keyof Shape as `${Table}.${StringKey<K>}`]: {
|
|
1194
|
-
as: K;
|
|
1195
|
-
column: Shape[K];
|
|
1196
|
-
};
|
|
1197
|
-
};
|
|
1198
|
-
tableAlias: undefined;
|
|
1199
|
-
windows: PropertyKey[];
|
|
1200
|
-
withData: Query['withData'];
|
|
1201
|
-
joinedTables: Query['joinedTables'];
|
|
1202
|
-
relations: Relations;
|
|
1203
|
-
[defaultsKey]: Record<{
|
|
1204
|
-
[K in keyof Shape]: Shape[K]['hasDefault'] extends true ? K : never;
|
|
1205
|
-
}[keyof Shape], true>;
|
|
1206
|
-
}
|
|
1207
|
-
declare class Db<Table extends string | undefined = undefined, Shape extends ColumnsShape = Record<string, never>, Relations extends Query['relations'] = Query['relations']> implements Query {
|
|
1208
|
-
adapter: Adapter;
|
|
1209
|
-
queryBuilder: Db;
|
|
1210
|
-
table: Table;
|
|
1211
|
-
shape: Shape;
|
|
1212
|
-
whereQueryBuilder: typeof WhereQueryBuilder;
|
|
1213
|
-
onQueryBuilder: typeof OnQueryBuilder;
|
|
1214
|
-
constructor(adapter: Adapter, queryBuilder: Db, table: Table, shape: Shape, options: DbTableOptions);
|
|
1215
|
-
}
|
|
1216
|
-
declare type DbResult<CT extends ColumnTypesBase> = Db & {
|
|
1217
|
-
<Table extends string, Shape extends ColumnsShape = ColumnsShape>(table: Table, shape?: ((t: CT) => Shape) | Shape, options?: DbTableOptions): Db<Table, Shape>;
|
|
1218
|
-
adapter: Adapter;
|
|
1219
|
-
destroy: Adapter['destroy'];
|
|
1220
|
-
};
|
|
1221
|
-
declare type DbOptions<CT extends ColumnTypesBase = ColumnTypes> = ({
|
|
1222
|
-
adapter: Adapter;
|
|
1223
|
-
} | Omit<AdapterOptions, 'log'>) & QueryLogOptions & {
|
|
1224
|
-
columnTypes?: CT;
|
|
1225
|
-
};
|
|
1226
|
-
declare const createDb: <CT extends ColumnTypesBase = {
|
|
1227
|
-
smallint: () => SmallIntColumn;
|
|
1228
|
-
integer: () => IntegerColumn;
|
|
1229
|
-
bigint: () => BigIntColumn;
|
|
1230
|
-
numeric: <Precision extends number | undefined = undefined, Scale extends number | undefined = undefined>(precision?: Precision | undefined, scale?: Scale | undefined) => DecimalColumn<Precision, Scale>;
|
|
1231
|
-
decimal: <Precision_1 extends number | undefined = undefined, Scale_1 extends number | undefined = undefined>(precision?: Precision_1 | undefined, scale?: Scale_1 | undefined) => DecimalColumn<Precision_1, Scale_1>;
|
|
1232
|
-
real: () => RealColumn;
|
|
1233
|
-
doublePrecision: () => DoublePrecisionColumn;
|
|
1234
|
-
smallSerial: () => SmallSerialColumn;
|
|
1235
|
-
serial: () => SerialColumn;
|
|
1236
|
-
bigSerial: () => BigSerialColumn;
|
|
1237
|
-
money: () => MoneyColumn;
|
|
1238
|
-
varchar: <Limit extends number | undefined = undefined>(limit?: Limit | undefined) => VarCharColumn<Limit>;
|
|
1239
|
-
char: <Limit_1 extends number | undefined = undefined>(limit?: Limit_1 | undefined) => CharColumn<Limit_1>;
|
|
1240
|
-
text: () => TextColumn;
|
|
1241
|
-
string: () => TextColumn;
|
|
1242
|
-
bytea: () => ByteaColumn;
|
|
1243
|
-
date: () => DateColumn;
|
|
1244
|
-
timestamp: <Precision_2 extends number | undefined = undefined>(precision?: Precision_2 | undefined) => TimestampColumn<Precision_2>;
|
|
1245
|
-
timestampWithTimeZone: <Precision_3 extends number | undefined = undefined>(precision?: Precision_3 | undefined) => TimestampWithTimeZoneColumn<Precision_3>;
|
|
1246
|
-
time: <Precision_4 extends number | undefined = undefined>(precision?: Precision_4 | undefined) => TimeColumn<Precision_4>;
|
|
1247
|
-
timeWithTimeZone: <Precision_5 extends number | undefined = undefined>(precision?: Precision_5 | undefined) => TimeWithTimeZoneColumn<Precision_5>;
|
|
1248
|
-
interval: <Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(fields?: Fields | undefined, precision?: Precision_6 | undefined) => IntervalColumn<Fields, Precision_6>;
|
|
1249
|
-
boolean: () => BooleanColumn;
|
|
1250
|
-
enum: <U extends string, T extends [U, ...U[]]>(dataType: string, type: T) => EnumColumn<U, T>;
|
|
1251
|
-
point: () => PointColumn;
|
|
1252
|
-
line: () => LineColumn;
|
|
1253
|
-
lseg: () => LsegColumn;
|
|
1254
|
-
box: () => BoxColumn;
|
|
1255
|
-
path: () => PathColumn;
|
|
1256
|
-
polygon: () => PolygonColumn;
|
|
1257
|
-
circle: () => CircleColumn;
|
|
1258
|
-
cidr: () => CidrColumn;
|
|
1259
|
-
inet: () => InetColumn;
|
|
1260
|
-
macaddr: () => MacAddrColumn;
|
|
1261
|
-
macaddr8: () => MacAddr8Column;
|
|
1262
|
-
bit: <Length extends number>(length: Length) => BitColumn<Length>;
|
|
1263
|
-
bitVarying: <Length_1 extends number | undefined = undefined>(length?: Length_1 | undefined) => BitVaryingColumn<Length_1 | undefined>;
|
|
1264
|
-
tsvector: () => TsVectorColumn;
|
|
1265
|
-
tsquery: () => TsQueryColumn;
|
|
1266
|
-
uuid: () => UUIDColumn;
|
|
1267
|
-
xml: () => XMLColumn;
|
|
1268
|
-
json: <Type extends JSONTypeAny>(schemaOrFn: Type | ((j: {
|
|
1269
|
-
set: <Value extends JSONTypeAny>(valueType: Value) => JSONSet<Value>;
|
|
1270
|
-
tuple: <T_1 extends [] | JSONTupleItems, Rest extends JSONTypeAny | null = null>(items: T_1, rest?: Rest) => JSONTuple<T_1, Rest>;
|
|
1271
|
-
union: <T_2 extends [JSONTypeAny, JSONTypeAny, ...JSONTypeAny[]]>(types: T_2) => JSONUnion<T_2>;
|
|
1272
|
-
any: () => JSONAny;
|
|
1273
|
-
bigint: () => JSONBigInt;
|
|
1274
|
-
boolean: () => JSONBoolean;
|
|
1275
|
-
date: () => JSONDate;
|
|
1276
|
-
nan: () => JSONNaN;
|
|
1277
|
-
never: () => JSONNever;
|
|
1278
|
-
null: () => JSONNull;
|
|
1279
|
-
number: () => JSONNumber;
|
|
1280
|
-
string: () => JSONString;
|
|
1281
|
-
undefined: () => JSONUndefined;
|
|
1282
|
-
unknown: () => JSONUnknown;
|
|
1283
|
-
void: () => JSONVoid;
|
|
1284
|
-
array: <Type_1 extends JSONTypeAny>(element: Type_1) => JSONArray<Type_1, "many">;
|
|
1285
|
-
discriminatedUnion: <Discriminator extends string, DiscriminatorValue extends Primitive, Types extends [JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, ...JSONDiscriminatedObject<Discriminator, DiscriminatorValue>[]]>(discriminator: Discriminator, options: Types) => JSONDiscriminatedUnion<Discriminator, DiscriminatorValue, Types[number]>;
|
|
1286
|
-
enum: <U_1 extends string, T_3 extends [U_1, ...U_1[]]>(options: T_3) => JSONEnum<U_1, T_3>;
|
|
1287
|
-
instanceOf: <T_4 extends new (...args: any[]) => any>(cls: T_4) => JSONInstanceOf<T_4>;
|
|
1288
|
-
intersection: <Left extends JSONTypeAny, Right extends JSONTypeAny>(left: Left, right: Right) => JSONIntersection<Left, Right>;
|
|
1289
|
-
lazy: <T_5 extends JSONTypeAny>(fn: () => T_5) => JSONLazy<T_5>;
|
|
1290
|
-
literal: <T_6 extends Primitive>(value: T_6) => JSONLiteral<T_6>;
|
|
1291
|
-
map: <Key extends JSONTypeAny, Value_1 extends JSONTypeAny>(keyType: Key, valueType: Value_1) => JSONMap<Key, Value_1>;
|
|
1292
|
-
nativeEnum: <T_7 extends EnumLike>(givenEnum: T_7) => JSONNativeEnum<T_7>;
|
|
1293
|
-
nullable: <T_8 extends JSONTypeAny>(type: T_8) => JSONNullable<T_8>;
|
|
1294
|
-
nullish: <T_9 extends JSONTypeAny>(type: T_9) => JSONNullish<T_9>;
|
|
1295
|
-
object: <T_10 extends JSONObjectShape, UnknownKeys extends UnknownKeysParam = "strip", Catchall extends JSONTypeAny = JSONTypeAny>(shape: T_10) => JSONObject<T_10, UnknownKeys, Catchall, JSONTypeAny extends Catchall ? addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never : (addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
|
|
1296
|
-
[k: string]: Catchall["type"];
|
|
1297
|
-
} extends infer T_12 ? { [k_2 in keyof T_12]: ((addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 ? { [k in keyof T_11]: addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
|
|
1298
|
-
[k: string]: Catchall["type"];
|
|
1299
|
-
})[k_2]; } : never>;
|
|
1300
|
-
optional: <T_13 extends JSONTypeAny>(type: T_13) => JSONOptional<T_13>;
|
|
1301
|
-
record: typeof record;
|
|
1302
|
-
}) => Type)) => JSONColumn<Type>;
|
|
1303
|
-
jsonText: () => JSONTextColumn;
|
|
1304
|
-
array: <Item extends ColumnType<unknown, Operators, unknown>>(item: Item) => ArrayColumn<Item>;
|
|
1305
|
-
timestamps<T_14 extends ColumnType<unknown, Operators, unknown>>(this: {
|
|
1306
|
-
timestamp(): T_14;
|
|
1307
|
-
}): {
|
|
1308
|
-
createdAt: T_14 & {
|
|
1309
|
-
hasDefault: true;
|
|
1310
|
-
};
|
|
1311
|
-
updatedAt: T_14 & {
|
|
1312
|
-
hasDefault: true;
|
|
1313
|
-
};
|
|
1314
|
-
};
|
|
1315
|
-
primaryKey(columns: string[], options?: {
|
|
1316
|
-
name?: string | undefined;
|
|
1317
|
-
} | undefined): {};
|
|
1318
|
-
index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
|
|
1319
|
-
unique(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
|
|
1320
|
-
foreignKey: {
|
|
1321
|
-
<Model extends ForeignKeyModelWithColumns, Columns extends [Exclude<keyof InstanceType<Model>["columns"]["shape"], number | symbol>, ...Exclude<keyof InstanceType<Model>["columns"]["shape"], number | symbol>[]]>(columns: string[], fn: () => Model, foreignColumns: Columns, options?: ForeignKeyOptions | undefined): {};
|
|
1322
|
-
<Table extends string, Columns_1 extends [string, ...string[]]>(columns: string[], table: Table, foreignColumns: Columns_1, options?: ForeignKeyOptions | undefined): {};
|
|
1323
|
-
};
|
|
1324
|
-
}>({ log, logger, columnTypes: ct, ...options }: DbOptions<CT>) => DbResult<CT>;
|
|
1325
|
-
|
|
1326
|
-
declare type WithArgsOptions = Omit<WithOptions, 'columns'> & {
|
|
1327
|
-
columns?: boolean | string[];
|
|
1328
|
-
};
|
|
1329
|
-
declare type WithArgs = [string, ColumnsShape, RawExpression] | [string, WithArgsOptions, ColumnsShape, RawExpression] | [string, Query | ((qb: Db) => Query)] | [string, WithArgsOptions, Query | ((qb: Db) => Query)];
|
|
1330
|
-
declare type WithShape<Args extends WithArgs> = Args[1] extends Query ? Args[1]['result'] : Args[1] extends (qb: Db) => Query ? ReturnType<Args[1]>['result'] : Args[2] extends Query ? Args[2]['result'] : Args[2] extends (qb: Db) => Query ? ReturnType<Args[2]>['result'] : Args[1] extends ColumnsShape ? Args[1] : Args[2] extends ColumnsShape ? Args[2] : Args[2] extends (t: ColumnTypes) => ColumnsShape ? ReturnType<Args[2]> : never;
|
|
1331
|
-
declare type WithResult<T extends Query, Args extends WithArgs, Shape extends ColumnsShape> = AddQueryWith<T, {
|
|
1332
|
-
table: Args[0];
|
|
1333
|
-
shape: Shape;
|
|
1334
|
-
type: ColumnShapeOutput<Shape>;
|
|
1335
|
-
}>;
|
|
1336
|
-
declare class With {
|
|
1337
|
-
with<T extends Query, Args extends WithArgs, Shape extends ColumnsShape = WithShape<Args>>(this: T, ...args: Args): WithResult<T, Args, Shape>;
|
|
1338
|
-
_with<T extends Query, Args extends WithArgs, Shape extends ColumnsShape = WithShape<Args>>(this: T, ...args: Args): WithResult<T, Args, Shape>;
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
1369
|
declare type ToSqlCtx = {
|
|
1342
1370
|
whereQueryBuilder: typeof WhereQueryBuilder;
|
|
1343
1371
|
onQueryBuilder: typeof OnQueryBuilder;
|