pqb 0.65.1 → 0.65.3
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 +189 -129
- package/dist/index.js +215 -218
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -218
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/node-postgres.js +31 -30
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +31 -30
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.js +2 -2
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +2 -2
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { inspect } from "node:util";
|
|
2
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { inspect } from "node:util";
|
|
3
3
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
4
4
|
type MaybeArray<T> = T | T[];
|
|
5
5
|
type MaybePromise<T> = T | Promise<T>;
|
|
@@ -242,10 +242,114 @@ declare abstract class QueryError<T extends PickQueryShape = PickQueryShape> ext
|
|
|
242
242
|
get isUnique(): boolean;
|
|
243
243
|
get columns(): { [K in keyof T["shape"]]?: true | undefined };
|
|
244
244
|
}
|
|
245
|
+
interface QueryLogObject {
|
|
246
|
+
colors: boolean;
|
|
247
|
+
beforeQuery(sql: SingleSql): unknown;
|
|
248
|
+
afterQuery(sql: SingleSql, logData: unknown): void;
|
|
249
|
+
onError(error: Error, sql: SingleSql, logData: unknown): void;
|
|
250
|
+
}
|
|
251
|
+
interface QueryLogger {
|
|
252
|
+
log(message: string): void;
|
|
253
|
+
warn(message: string): void;
|
|
254
|
+
error(message: string): void;
|
|
255
|
+
}
|
|
256
|
+
interface QueryLogOptions {
|
|
257
|
+
log?: boolean | Partial<QueryLogObject>;
|
|
258
|
+
logger?: QueryLogger;
|
|
259
|
+
}
|
|
260
|
+
declare const logColors: {
|
|
261
|
+
boldCyanBright: (message: string) => string;
|
|
262
|
+
boldBlue: (message: string) => string;
|
|
263
|
+
boldYellow: (message: string) => string;
|
|
264
|
+
boldMagenta: (message: string) => string;
|
|
265
|
+
boldRed: (message: string) => string;
|
|
266
|
+
};
|
|
267
|
+
declare const logParamToLogObject: (logger: QueryLogger, log: QueryLogOptions["log"]) => QueryLogObject | undefined;
|
|
268
|
+
declare class QueryLog {
|
|
269
|
+
/**
|
|
270
|
+
* Override the `log` option, which can also be set in `createDb` or when creating a table instance:
|
|
271
|
+
*
|
|
272
|
+
* ```ts
|
|
273
|
+
* // turn log on for this query:
|
|
274
|
+
* await db.table.all().log(true);
|
|
275
|
+
* await db.table.all().log(); // no argument for true
|
|
276
|
+
*
|
|
277
|
+
* // turn log off for this query:
|
|
278
|
+
* await db.table.all().log(false);
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* Use {@link $withOptions} to override `log` for a scope of a callback.
|
|
282
|
+
*/
|
|
283
|
+
log<T>(this: T, log?: boolean): T;
|
|
284
|
+
}
|
|
245
285
|
interface SqlSessionState {
|
|
286
|
+
/**
|
|
287
|
+
* Postgres role for SQL session context.
|
|
288
|
+
*
|
|
289
|
+
* `$withOptions` applies it around query execution; transaction options apply
|
|
290
|
+
* it with transaction-local semantics.
|
|
291
|
+
*/
|
|
246
292
|
role?: string;
|
|
293
|
+
/**
|
|
294
|
+
* Postgres custom settings for SQL session context.
|
|
295
|
+
*
|
|
296
|
+
* `$withOptions` applies them around query execution; transaction options
|
|
297
|
+
* apply them with transaction-local semantics.
|
|
298
|
+
*/
|
|
247
299
|
setConfig?: Record<string, string | number | boolean>;
|
|
248
300
|
}
|
|
301
|
+
type QuerySchema = (() => string) | string;
|
|
302
|
+
interface HasQuerySchema {
|
|
303
|
+
q: {
|
|
304
|
+
schema?: QuerySchema;
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
declare const getQuerySchema: (query: HasQuerySchema) => string | undefined;
|
|
308
|
+
declare class QueryWithSchema {
|
|
309
|
+
/**
|
|
310
|
+
* Specifies the schema to be used as a prefix of a table name.
|
|
311
|
+
*
|
|
312
|
+
* Though this method can be used to set the schema right when building the query,
|
|
313
|
+
* it's better to specify schema when calling `db(table, () => columns, { schema: string })`
|
|
314
|
+
*
|
|
315
|
+
* ```ts
|
|
316
|
+
* db.table.withSchema('customSchema').select('id');
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* Resulting SQL:
|
|
320
|
+
*
|
|
321
|
+
* ```sql
|
|
322
|
+
* SELECT "user"."id" FROM "customSchema"."user"
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* You can set a **default** schema for all tables in a callback by using {@link $withOptions}.
|
|
326
|
+
*
|
|
327
|
+
* @param schema - a name of the database schema to use
|
|
328
|
+
*/
|
|
329
|
+
withSchema<T>(this: T, schema: QuerySchema | undefined): T;
|
|
330
|
+
}
|
|
331
|
+
interface AsyncState extends SqlSessionState {
|
|
332
|
+
transactionAdapter?: Adapter;
|
|
333
|
+
transactionId?: number;
|
|
334
|
+
afterCommit?: TransactionAfterCommitHook[];
|
|
335
|
+
log?: QueryLogObject;
|
|
336
|
+
testTransactionCount?: number;
|
|
337
|
+
catchI?: number;
|
|
338
|
+
schema?: QuerySchema;
|
|
339
|
+
transactionRole?: SqlSessionState['role'];
|
|
340
|
+
transactionSetConfig?: SqlSessionState['setConfig'];
|
|
341
|
+
}
|
|
342
|
+
interface StorageOptions extends SqlSessionState {
|
|
343
|
+
log?: boolean;
|
|
344
|
+
schema?: QuerySchema;
|
|
345
|
+
}
|
|
346
|
+
interface ProcessedStorageOptions extends SqlSessionState {
|
|
347
|
+
log?: QueryLogObject;
|
|
348
|
+
schema?: QuerySchema;
|
|
349
|
+
}
|
|
350
|
+
declare class QueryStorage {
|
|
351
|
+
withOptions<Result>(this: PickQueryQAndInternal, options: StorageOptions, cb: () => Promise<Result>): Promise<Result>;
|
|
352
|
+
}
|
|
249
353
|
/**
|
|
250
354
|
* Generic result returning from query methods.
|
|
251
355
|
*/
|
|
@@ -273,7 +377,12 @@ interface AdapterConfigBase {
|
|
|
273
377
|
password?: string | (() => string | Promise<string>);
|
|
274
378
|
searchPath?: string;
|
|
275
379
|
ssl?: any;
|
|
276
|
-
|
|
380
|
+
/**
|
|
381
|
+
* Postgres settings to apply when driver connections are configured.
|
|
382
|
+
*
|
|
383
|
+
* `searchPath` is normalized to `search_path` in this map.
|
|
384
|
+
*/
|
|
385
|
+
setConfig?: RecordString;
|
|
277
386
|
schema?: QuerySchema;
|
|
278
387
|
host?: string;
|
|
279
388
|
/**
|
|
@@ -339,14 +448,11 @@ interface AdapterConfigConnectRetry {
|
|
|
339
448
|
interface AdapterConfigConnectRetryStrategy {
|
|
340
449
|
(attempt: number, attempts: number): Promise<void> | void;
|
|
341
450
|
}
|
|
342
|
-
interface AdapterTransactionOptions {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
};
|
|
347
|
-
sqlSessionState?: SqlSessionState;
|
|
451
|
+
interface AdapterTransactionOptions extends ProcessedStorageOptions {
|
|
452
|
+
level?: IsolationLevel;
|
|
453
|
+
readOnly?: boolean;
|
|
454
|
+
deferrable?: boolean;
|
|
348
455
|
}
|
|
349
|
-
type TransactionArgs<Result> = [cbOrOptions: undefined | AdapterTransactionOptions | ((adapter: TransactionAdapter) => Promise<Result>), optionalCb?: (adapter: TransactionAdapter) => Promise<Result>];
|
|
350
456
|
interface Adapter {
|
|
351
457
|
errorClass: new (...args: any[]) => Error;
|
|
352
458
|
searchPath?: string;
|
|
@@ -358,16 +464,9 @@ interface Adapter {
|
|
|
358
464
|
/**
|
|
359
465
|
* Run a transaction
|
|
360
466
|
*
|
|
361
|
-
*
|
|
362
|
-
* @param options - optional transaction parameters
|
|
363
|
-
*/
|
|
364
|
-
transaction<T>(options: AdapterTransactionOptions | undefined, cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
365
|
-
/**
|
|
366
|
-
* Run a transaction
|
|
367
|
-
*
|
|
368
|
-
* @param cb - callback will be called with a db client with a dedicated connection.
|
|
467
|
+
* `options` can be `undefined`.
|
|
369
468
|
*/
|
|
370
|
-
transaction<T>(cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
469
|
+
transaction<T>(asyncStorage: AsyncLocalStorage<AsyncState> | undefined, options: AdapterTransactionOptions | undefined, cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
371
470
|
close(): Promise<void>;
|
|
372
471
|
getDatabase(): string;
|
|
373
472
|
getUser(): string;
|
|
@@ -421,7 +520,6 @@ declare class AdapterClass implements Adapter {
|
|
|
421
520
|
private pool;
|
|
422
521
|
private readonly config;
|
|
423
522
|
private readonly connectionState;
|
|
424
|
-
private readonly locals;
|
|
425
523
|
constructor(params: AdapterParams);
|
|
426
524
|
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[], startingSavepoint?: string, releasingSavepoint?: string, sqlSessionState?: SqlSessionState): Promise<QueryResult<T>>;
|
|
427
525
|
arrays<R extends any[] = any[]>(text: string, values?: unknown[], startingSavepoint?: string, releasingSavepoint?: string, sqlSessionState?: SqlSessionState): Promise<QueryArraysResult<R>>;
|
|
@@ -432,9 +530,8 @@ declare class AdapterClass implements Adapter {
|
|
|
432
530
|
getSearchPath(): string | undefined;
|
|
433
531
|
getHost(): string;
|
|
434
532
|
getSchema(): QuerySchema | undefined;
|
|
435
|
-
transaction<T>(options: AdapterTransactionOptions | undefined, cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
436
|
-
|
|
437
|
-
close(): Promise<void>;
|
|
533
|
+
transaction<T>(asyncStorage: AsyncLocalStorage<AsyncState> | undefined, options: AdapterTransactionOptions | undefined, cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
534
|
+
close: () => Promise<void>;
|
|
438
535
|
assignError(to: QueryError, from: Error): void;
|
|
439
536
|
}
|
|
440
537
|
/**
|
|
@@ -442,11 +539,10 @@ declare class AdapterClass implements Adapter {
|
|
|
442
539
|
*/
|
|
443
540
|
declare class TransactionAdapterClass implements TransactionAdapter {
|
|
444
541
|
private adapter;
|
|
445
|
-
private locals;
|
|
446
542
|
private client;
|
|
447
543
|
errorClass: new (...args: any[]) => Error;
|
|
448
544
|
driverAdapter: DriverAdapter;
|
|
449
|
-
constructor(adapter: Adapter,
|
|
545
|
+
constructor(adapter: Adapter, client: Client);
|
|
450
546
|
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[], startingSavepoint?: string, releasingSavepoint?: string, sqlSessionState?: SqlSessionState): Promise<QueryResult<T>>;
|
|
451
547
|
arrays<R extends any[] = any[]>(text: string, values?: unknown[], startingSavepoint?: string, releasingSavepoint?: string, sqlSessionState?: SqlSessionState): Promise<QueryArraysResult<R>>;
|
|
452
548
|
clone(params?: AdapterConfigBase): Adapter;
|
|
@@ -456,8 +552,7 @@ declare class TransactionAdapterClass implements TransactionAdapter {
|
|
|
456
552
|
getSearchPath(): string | undefined;
|
|
457
553
|
getHost(): string;
|
|
458
554
|
getSchema(): QuerySchema | undefined;
|
|
459
|
-
transaction<T>(options: AdapterTransactionOptions | undefined, cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
460
|
-
transaction<T>(cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
555
|
+
transaction<T>(asyncStorage: AsyncLocalStorage<AsyncState> | undefined, options: AdapterTransactionOptions | undefined, cb: (adapter: TransactionAdapter) => Promise<T>): Promise<T>;
|
|
461
556
|
close(): Promise<void>;
|
|
462
557
|
assignError(to: QueryError, from: Error): void;
|
|
463
558
|
}
|
|
@@ -4282,95 +4377,9 @@ declare class SoftDeleteMethods {
|
|
|
4282
4377
|
*/
|
|
4283
4378
|
hardDelete<T extends QueryWithSoftDelete>(this: T, ..._args: DeleteArgs<T>): DeleteResult<T>;
|
|
4284
4379
|
}
|
|
4285
|
-
interface QueryLogObject {
|
|
4286
|
-
colors: boolean;
|
|
4287
|
-
beforeQuery(sql: SingleSql): unknown;
|
|
4288
|
-
afterQuery(sql: SingleSql, logData: unknown): void;
|
|
4289
|
-
onError(error: Error, sql: SingleSql, logData: unknown): void;
|
|
4290
|
-
}
|
|
4291
|
-
interface QueryLogger {
|
|
4292
|
-
log(message: string): void;
|
|
4293
|
-
warn(message: string): void;
|
|
4294
|
-
error(message: string): void;
|
|
4295
|
-
}
|
|
4296
|
-
interface QueryLogOptions {
|
|
4297
|
-
log?: boolean | Partial<QueryLogObject>;
|
|
4298
|
-
logger?: QueryLogger;
|
|
4299
|
-
}
|
|
4300
|
-
declare const logColors: {
|
|
4301
|
-
boldCyanBright: (message: string) => string;
|
|
4302
|
-
boldBlue: (message: string) => string;
|
|
4303
|
-
boldYellow: (message: string) => string;
|
|
4304
|
-
boldMagenta: (message: string) => string;
|
|
4305
|
-
boldRed: (message: string) => string;
|
|
4306
|
-
};
|
|
4307
|
-
declare const logParamToLogObject: (logger: QueryLogger, log: QueryLogOptions["log"]) => QueryLogObject | undefined;
|
|
4308
|
-
declare class QueryLog {
|
|
4309
|
-
/**
|
|
4310
|
-
* Override the `log` option, which can also be set in `createDb` or when creating a table instance:
|
|
4311
|
-
*
|
|
4312
|
-
* ```ts
|
|
4313
|
-
* // turn log on for this query:
|
|
4314
|
-
* await db.table.all().log(true);
|
|
4315
|
-
* await db.table.all().log(); // no argument for true
|
|
4316
|
-
*
|
|
4317
|
-
* // turn log off for this query:
|
|
4318
|
-
* await db.table.all().log(false);
|
|
4319
|
-
* ```
|
|
4320
|
-
*
|
|
4321
|
-
* Use {@link $withOptions} to override `log` for a scope of a callback.
|
|
4322
|
-
*/
|
|
4323
|
-
log<T>(this: T, log?: boolean): T;
|
|
4324
|
-
}
|
|
4325
4380
|
interface QueryInternalColumnNameToKey {
|
|
4326
4381
|
columnNameToKeyMap?: Map<string, string>;
|
|
4327
4382
|
}
|
|
4328
|
-
type QuerySchema = (() => string) | string;
|
|
4329
|
-
interface HasQuerySchema {
|
|
4330
|
-
q: {
|
|
4331
|
-
schema?: QuerySchema;
|
|
4332
|
-
};
|
|
4333
|
-
}
|
|
4334
|
-
declare const getQuerySchema: (query: HasQuerySchema) => string | undefined;
|
|
4335
|
-
declare class QueryWithSchema {
|
|
4336
|
-
/**
|
|
4337
|
-
* Specifies the schema to be used as a prefix of a table name.
|
|
4338
|
-
*
|
|
4339
|
-
* Though this method can be used to set the schema right when building the query,
|
|
4340
|
-
* it's better to specify schema when calling `db(table, () => columns, { schema: string })`
|
|
4341
|
-
*
|
|
4342
|
-
* ```ts
|
|
4343
|
-
* db.table.withSchema('customSchema').select('id');
|
|
4344
|
-
* ```
|
|
4345
|
-
*
|
|
4346
|
-
* Resulting SQL:
|
|
4347
|
-
*
|
|
4348
|
-
* ```sql
|
|
4349
|
-
* SELECT "user"."id" FROM "customSchema"."user"
|
|
4350
|
-
* ```
|
|
4351
|
-
*
|
|
4352
|
-
* You can set a **default** schema for all tables in a callback by using {@link $withOptions}.
|
|
4353
|
-
*
|
|
4354
|
-
* @param schema - a name of the database schema to use
|
|
4355
|
-
*/
|
|
4356
|
-
withSchema<T>(this: T, schema: QuerySchema | undefined): T;
|
|
4357
|
-
}
|
|
4358
|
-
interface AsyncState extends SqlSessionState {
|
|
4359
|
-
transactionAdapter?: Adapter;
|
|
4360
|
-
transactionId?: number;
|
|
4361
|
-
afterCommit?: TransactionAfterCommitHook[];
|
|
4362
|
-
log?: QueryLogObject;
|
|
4363
|
-
testTransactionCount?: number;
|
|
4364
|
-
catchI?: number;
|
|
4365
|
-
schema?: QuerySchema;
|
|
4366
|
-
}
|
|
4367
|
-
interface StorageOptions extends SqlSessionState {
|
|
4368
|
-
log?: boolean;
|
|
4369
|
-
schema?: QuerySchema;
|
|
4370
|
-
}
|
|
4371
|
-
declare class QueryStorage {
|
|
4372
|
-
withOptions<Result>(this: PickQueryQAndInternal, options: StorageOptions, cb: () => Promise<Result>): Promise<Result>;
|
|
4373
|
-
}
|
|
4374
4383
|
declare namespace DefaultPrivileges {
|
|
4375
4384
|
export type ObjectType = (typeof DEFAULT_PRIVILEGE.OBJECT_TYPES)[number];
|
|
4376
4385
|
export interface Privilege {
|
|
@@ -5388,12 +5397,40 @@ declare abstract class ExpressionTypeMethod {
|
|
|
5388
5397
|
};
|
|
5389
5398
|
}
|
|
5390
5399
|
type IsolationLevel = 'SERIALIZABLE' | 'REPEATABLE READ' | 'READ COMMITTED' | 'READ UNCOMMITTED';
|
|
5391
|
-
interface TransactionOptions {
|
|
5400
|
+
interface TransactionOptions extends SqlSessionState {
|
|
5401
|
+
/**
|
|
5402
|
+
* Enable or disable logging for all queries in the transaction.
|
|
5403
|
+
*/
|
|
5392
5404
|
log?: boolean;
|
|
5405
|
+
/**
|
|
5406
|
+
* Default schema to use for queries in the transaction.
|
|
5407
|
+
*/
|
|
5393
5408
|
schema?: QuerySchema;
|
|
5409
|
+
/**
|
|
5410
|
+
* Postgres isolation level for the top-level transaction.
|
|
5411
|
+
*/
|
|
5394
5412
|
level?: IsolationLevel;
|
|
5413
|
+
/**
|
|
5414
|
+
* Whether the top-level transaction should be read-only.
|
|
5415
|
+
*/
|
|
5395
5416
|
readOnly?: boolean;
|
|
5417
|
+
/**
|
|
5418
|
+
* Whether the top-level transaction should be deferrable.
|
|
5419
|
+
*/
|
|
5396
5420
|
deferrable?: boolean;
|
|
5421
|
+
/**
|
|
5422
|
+
* Postgres role to apply for the transaction callback.
|
|
5423
|
+
*
|
|
5424
|
+
* Nested transactions can temporarily replace the parent transaction role.
|
|
5425
|
+
*/
|
|
5426
|
+
role?: SqlSessionState['role'];
|
|
5427
|
+
/**
|
|
5428
|
+
* Postgres custom settings to apply for the transaction callback.
|
|
5429
|
+
*
|
|
5430
|
+
* Nested transaction settings are shallow-merged over the parent transaction
|
|
5431
|
+
* settings while the nested callback runs.
|
|
5432
|
+
*/
|
|
5433
|
+
setConfig?: SqlSessionState['setConfig'];
|
|
5397
5434
|
}
|
|
5398
5435
|
interface AfterCommitErrorFulfilledResult extends PromiseFulfilledResult<unknown> {
|
|
5399
5436
|
name?: string;
|
|
@@ -5556,6 +5593,36 @@ declare class QueryTransaction {
|
|
|
5556
5593
|
* ```
|
|
5557
5594
|
*
|
|
5558
5595
|
* If the error in the inner transaction is not caught, all nested transactions are rolled back and aborted.
|
|
5596
|
+
*
|
|
5597
|
+
* ## SQL session context in transactions
|
|
5598
|
+
*
|
|
5599
|
+
* Pass `role` and `setConfig` in transaction options to apply Postgres SQL session context for the whole transaction:
|
|
5600
|
+
*
|
|
5601
|
+
* ```ts
|
|
5602
|
+
* await db.$transaction(
|
|
5603
|
+
* {
|
|
5604
|
+
* role: 'app_user',
|
|
5605
|
+
* setConfig: {
|
|
5606
|
+
* 'app.tenant_id': tenantId,
|
|
5607
|
+
* 'app.user_id': userId,
|
|
5608
|
+
* },
|
|
5609
|
+
* },
|
|
5610
|
+
* async () => {
|
|
5611
|
+
* const project = await db.project.find(projectId);
|
|
5612
|
+
*
|
|
5613
|
+
* await db.project.find(projectId).update({ lastViewedAt: new Date() });
|
|
5614
|
+
*
|
|
5615
|
+
* return project;
|
|
5616
|
+
* },
|
|
5617
|
+
* );
|
|
5618
|
+
* ```
|
|
5619
|
+
*
|
|
5620
|
+
* This is different from `$withOptions({ role, setConfig }, cb)`.
|
|
5621
|
+
* `$withOptions` is query-scoped and reconciles SQL session state around each query.
|
|
5622
|
+
* Transaction options are applied once for the transaction and are useful for request-scoped RLS work that is already transaction-bound.
|
|
5623
|
+
*
|
|
5624
|
+
* Nested transactions can temporarily override the parent transaction role and config.
|
|
5625
|
+
* When the nested transaction finishes, Orchid restores the parent transaction context before the outer callback continues.
|
|
5559
5626
|
*/
|
|
5560
5627
|
transaction<Result>(this: PickQueryQAndInternal, cb: () => Promise<Result>): Promise<Result>;
|
|
5561
5628
|
transaction<Result>(this: PickQueryQAndInternal, options: IsolationLevel | TransactionOptions, cb: () => Promise<Result>): Promise<Result>;
|
|
@@ -7217,11 +7284,10 @@ declare class QueryCreateFrom {
|
|
|
7217
7284
|
interface CreateSelf extends IsQuery, PickQueryHasSelect, PickQueryDefaults, PickQueryResult, PickQueryRelations, PickQueryWithData, PickQueryReturnType, PickQueryShape, PickQueryUniqueProperties, PickQueryInputType {}
|
|
7218
7285
|
type CreateData<T extends CreateSelf> = EmptyObject extends T['relations'] ? CreateDataWithDefaults<T, keyof T['__defaults']> : CreateRelationsData<T>;
|
|
7219
7286
|
type CreateDataWithDefaults<T extends CreateSelf, Defaults extends PropertyKey> = { [K in keyof T['inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T, K> } & { [K in Defaults]?: K extends keyof T['inputType'] ? CreateColumn<T, K> : never };
|
|
7220
|
-
type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends keyof T['inputType'], OmitFKeys extends PropertyKey> = { [K in keyof T['inputType'] as K extends Defaults | OmitFKeys ? never : K]: K extends Defaults | OmitFKeys ? never : CreateColumn<T, K> } & { [K in
|
|
7287
|
+
type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends keyof T['inputType'], OmitFKeys extends PropertyKey> = { [K in keyof T['inputType'] as K extends Defaults | OmitFKeys ? never : K]: K extends Defaults | OmitFKeys ? never : CreateColumn<T, K> } & { [K in keyof T['inputType'] & (Defaults | OmitFKeys)]?: CreateColumn<T, K> };
|
|
7221
7288
|
type CreateColumn<T extends CreateSelf, K extends keyof T['inputType']> = T['inputType'][K] | ((q: T) => QueryOrExpression<T['inputType'][K]>);
|
|
7222
|
-
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['
|
|
7223
|
-
type CreateBelongsToData<T extends CreateSelf> = [T['relations'][keyof T['relations']]['dataForCreate']] extends [never] ? EmptyObject :
|
|
7224
|
-
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union extends RelationConfigDataForCreate ? (u: Union['columns'] extends keyof T['__defaults'] ? { [P in Exclude<Union['columns'] & keyof T['inputType'], keyof T['__defaults']>]: CreateColumn<T, P> } & { [P in keyof T['__defaults'] & Union['columns']]?: CreateColumn<T, P> } & Partial<Union['nested']> : { [P in Union['columns'] & keyof T['inputType']]: CreateColumn<T, P> } | Union['nested']) => void : never) extends ((u: infer Obj) => void) ? Obj : never;
|
|
7289
|
+
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['columnsForCreate']> & CreateBelongsToData<T> & T['relations'][keyof T['relations']]['optionalDataForCreate'];
|
|
7290
|
+
type CreateBelongsToData<T extends CreateSelf> = [T['relations'][keyof T['relations']]['dataForCreate']] extends [never] ? EmptyObject : T['relations'][keyof T['relations']]['dataForCreate'];
|
|
7225
7291
|
type CreateResult<T extends CreateSelf, Data> = T extends {
|
|
7226
7292
|
isCount: true;
|
|
7227
7293
|
} ? T : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneResult<T, NarrowCreateResult<T, Data>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnResult<T, NarrowCreateResult<T, Data>> : SetQueryResult<T, NarrowCreateResult<T, Data>>;
|
|
@@ -7236,10 +7302,7 @@ type InsertManyResult<T extends CreateSelf> = T['__hasSelect'] extends true ? T[
|
|
|
7236
7302
|
*
|
|
7237
7303
|
* The same should work as well with any non-null columns passed to `create`, but it's to be implemented later.
|
|
7238
7304
|
*/
|
|
7239
|
-
type NarrowCreateResult<T extends CreateSelf, Data> = EmptyObject extends T['relations'] ? T['result'] : { [K in keyof T['result']]: true extends { [R in keyof T['relations']]: K extends T['relations'][R]['
|
|
7240
|
-
columns: unknown;
|
|
7241
|
-
nested: unknown;
|
|
7242
|
-
} ? keyof T['relations'][R]['dataForCreate']['nested'] extends keyof Data ? true : T['relations'][R]['dataForCreate']['columns'] extends keyof Data ? null | undefined extends Data[T['relations'][R]['dataForCreate']['columns']] ? never : true : never : never : never }[keyof T['relations']] ? Column.Pick.QueryColumnOfTypeAndOps<string, Exclude<T['result'][K]['outputType'], null>, T['result'][K]['operators']> : T['result'][K] };
|
|
7305
|
+
type NarrowCreateResult<T extends CreateSelf, Data> = EmptyObject extends T['relations'] ? T['result'] : { [K in keyof T['result']]: true extends { [R in keyof T['relations']]: K extends T['relations'][R]['columnsForCreate'] ? R extends keyof Data ? true : T['relations'][R]['columnsForCreate'] extends keyof Data ? null | undefined extends Data[T['relations'][R]['columnsForCreate']] ? never : true : never : never }[keyof T['relations']] ? Column.Pick.QueryColumnOfTypeAndOps<string, Exclude<T['result'][K]['outputType'], null>, T['result'][K]['operators']> : T['result'][K] };
|
|
7243
7306
|
type IgnoreResult<T extends CreateSelf> = T['returnType'] extends 'oneOrThrow' ? QueryTakeOptional<T> : T['returnType'] extends 'valueOrThrow' ? SetQueryReturnsColumnOptional<T, T['result']['value']> : T;
|
|
7244
7307
|
type OnConflictArg<T extends PickQueryUniqueProperties> = T['internal']['uniqueColumnNames'] | T['internal']['uniqueColumnTuples'] | Expression | {
|
|
7245
7308
|
constraint: T['internal']['uniqueConstraints'];
|
|
@@ -7266,7 +7329,8 @@ declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<Create
|
|
|
7266
7329
|
*/
|
|
7267
7330
|
type CreateMethodsNames = 'create' | 'insert' | 'createMany' | 'insertMany' | CreateFromMethodNames;
|
|
7268
7331
|
type CreateManyMethodsNames = 'createMany' | 'insertMany' | CreateManyFromMethodNames;
|
|
7269
|
-
type
|
|
7332
|
+
type CollectMissingColumns<T extends CreateSelf, Data> = { [K in T['relations'][keyof T['relations']]['columnsForCreate']]: null | undefined extends T['inputType'][K & keyof T['inputType']] ? false : K extends keyof T['__defaults'] ? false : true extends { [Rel in keyof T['relations']]: K extends T['relations'][Rel]['columnsForCreate'] ? Rel extends keyof Data ? undefined extends Data[Rel] ? false : true : false : false }[keyof T['relations']] ? false : K extends keyof Data ? undefined extends Data[K] ? K : false : K }[T['relations'][keyof T['relations']]['columnsForCreate']];
|
|
7333
|
+
type ExtraPropertiesAreNotAllowed<T extends CreateSelf, Data> = keyof Data extends keyof T['inputType'] | keyof T['relations'] ? CollectMissingColumns<T, Data> extends false ? Data : `Missing ${CollectMissingColumns<T, Data> & string}` : `Extra properties are not allowed: ${Exclude<keyof Data, keyof T['inputType'] | keyof T['relations']> & string}`;
|
|
7270
7334
|
declare class QueryCreate {
|
|
7271
7335
|
/**
|
|
7272
7336
|
* `create` and `insert` create a single record.
|
|
@@ -10078,17 +10142,13 @@ interface RelationConfigBase extends IsQuery {
|
|
|
10078
10142
|
queryRelated(params: unknown): unknown;
|
|
10079
10143
|
modifyRelatedQuery?(relatedQuery: IsQuery): (query: IsQuery) => void;
|
|
10080
10144
|
maybeSingle: PickQuerySelectableReturnType;
|
|
10081
|
-
|
|
10082
|
-
dataForCreate
|
|
10145
|
+
columnsForCreate: PropertyKey;
|
|
10146
|
+
dataForCreate: RecordUnknown;
|
|
10083
10147
|
optionalDataForCreate: unknown;
|
|
10084
10148
|
dataForUpdate: unknown;
|
|
10085
10149
|
dataForUpdateOne: unknown;
|
|
10086
10150
|
primaryKeys: string[];
|
|
10087
10151
|
}
|
|
10088
|
-
interface RelationConfigDataForCreate {
|
|
10089
|
-
columns: PropertyKey;
|
|
10090
|
-
nested: RecordUnknown;
|
|
10091
|
-
}
|
|
10092
10152
|
interface RelationsBase {
|
|
10093
10153
|
[K: string]: RelationConfigBase;
|
|
10094
10154
|
}
|
|
@@ -10397,4 +10457,4 @@ declare const testTransaction: {
|
|
|
10397
10457
|
*/
|
|
10398
10458
|
close(arg: Arg$1): Promise<void>;
|
|
10399
10459
|
};
|
|
10400
|
-
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type FromArg, type FromResult, type GeneratorIgnore, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, TransactionAdapterClass, type
|
|
10460
|
+
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type FromArg, type FromResult, type GeneratorIgnore, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, snakeCaseKey, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|