pqb 0.56.4 → 0.56.5
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 +185 -99
- package/dist/index.js +411 -232
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +408 -230
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -403,7 +403,10 @@ interface QueryData extends QueryDataBase {
|
|
|
403
403
|
};
|
|
404
404
|
/** insert **/
|
|
405
405
|
columns: string[];
|
|
406
|
-
|
|
406
|
+
insertFrom?: Query;
|
|
407
|
+
insertValuesAs?: string;
|
|
408
|
+
queryColumnsCount?: number;
|
|
409
|
+
values: InsertQueryDataObjectValues;
|
|
407
410
|
onConflict?: {
|
|
408
411
|
target?: OnConflictTarget;
|
|
409
412
|
set?: OnConflictSet$1;
|
|
@@ -420,10 +423,6 @@ interface QueryData extends QueryDataBase {
|
|
|
420
423
|
copy: CopyOptions;
|
|
421
424
|
}
|
|
422
425
|
type InsertQueryDataObjectValues = unknown[][];
|
|
423
|
-
type InsertQueryDataFromValues = {
|
|
424
|
-
from: Query;
|
|
425
|
-
values?: unknown[];
|
|
426
|
-
};
|
|
427
426
|
interface UpdateQueryDataObject {
|
|
428
427
|
[K: string]: Expression | {
|
|
429
428
|
op: string;
|
|
@@ -1238,9 +1237,9 @@ declare class Join {
|
|
|
1238
1237
|
}): JoinLateralResult<T, Table, Meta, Result, false>;
|
|
1239
1238
|
/**
|
|
1240
1239
|
* This method may be useful
|
|
1241
|
-
* for combining with [
|
|
1240
|
+
* for combining with [createForEachFrom](/guide/create-update-delete.html#createForEachFrom-insertForEachFrom).
|
|
1242
1241
|
*
|
|
1243
|
-
* `
|
|
1242
|
+
* `createForEachFrom` creates multiple record based on a selecting query:
|
|
1244
1243
|
*
|
|
1245
1244
|
* ```sql
|
|
1246
1245
|
* INSERT INTO t1(c1, c2)
|
|
@@ -1254,7 +1253,7 @@ declare class Join {
|
|
|
1254
1253
|
* ```ts
|
|
1255
1254
|
* const data = [{ column2: 'one' }, { column2: 'two' }, { column2: 'three' }];
|
|
1256
1255
|
*
|
|
1257
|
-
* await db.table.
|
|
1256
|
+
* await db.table.createForEachFrom(
|
|
1258
1257
|
* db.otherTable
|
|
1259
1258
|
* .joinData('data', (t) => ({ column2: t.text() }), data)
|
|
1260
1259
|
* .select('otherTable.column1', 'data.column2'),
|
|
@@ -4223,6 +4222,179 @@ declare class Clear {
|
|
|
4223
4222
|
clear<T>(this: T, ...clears: ClearStatement[]): T;
|
|
4224
4223
|
}
|
|
4225
4224
|
|
|
4225
|
+
type CreateFromMethodNames = 'createOneFrom' | 'insertOneFrom' | CreateManyFromMethodNames;
|
|
4226
|
+
type CreateManyFromMethodNames = 'createManyFrom' | 'insertManyFrom' | 'createForEachFrom' | 'insertForEachFrom';
|
|
4227
|
+
interface QueryReturningOne extends IsQuery {
|
|
4228
|
+
result: QueryColumns;
|
|
4229
|
+
returnType: 'one' | 'oneOrThrow';
|
|
4230
|
+
}
|
|
4231
|
+
type CreateRawOrFromResult<T extends CreateSelf> = T extends {
|
|
4232
|
+
isCount: true;
|
|
4233
|
+
} ? SetQueryKind<T, 'create'> : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKind<T, 'create'> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKind<T, 'create'> : SetQueryKind<T, 'create'>;
|
|
4234
|
+
type InsertRawOrFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKind<T, 'create'> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKind<T, 'create'> : SetQueryKind<T, 'create'> : SetQueryReturnsRowCount<T, 'create'>;
|
|
4235
|
+
type CreateManyFromResult<T extends CreateSelf> = T extends {
|
|
4236
|
+
isCount: true;
|
|
4237
|
+
} ? SetQueryKind<T, 'create'> : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKind<T, 'create'> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKind<T, 'create'> : SetQueryKind<T, 'create'>;
|
|
4238
|
+
type InsertManyFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKind<T, 'create'> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKind<T, 'create'> : SetQueryKind<T, 'create'> : SetQueryReturnsRowCountMany<T, 'create'>;
|
|
4239
|
+
declare const _queryCreateOneFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>) => CreateRawOrFromResult<T>;
|
|
4240
|
+
declare const _queryInsertOneFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>) => InsertRawOrFromResult<T>;
|
|
4241
|
+
declare const _queryCreateManyFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>[]) => CreateManyFromResult<T>;
|
|
4242
|
+
declare const _queryInsertManyFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>[]) => InsertManyFromResult<T>;
|
|
4243
|
+
declare const _queryCreateForEachFrom: <T extends CreateSelf>(q: T, query: IsQuery) => CreateManyFromResult<T>;
|
|
4244
|
+
declare const _queryInsertForEachFrom: <T extends CreateSelf>(q: T, query: IsQuery) => InsertManyFromResult<T>;
|
|
4245
|
+
declare class QueryCreateFrom {
|
|
4246
|
+
/**
|
|
4247
|
+
* Inserts a single record based on a query that selects a single record.
|
|
4248
|
+
*
|
|
4249
|
+
* Performs a single SQL query based on `INSERT ... SELECT ... FROM`.
|
|
4250
|
+
*
|
|
4251
|
+
* See {@link createManyFrom} to insert multiple records based on a single record query,
|
|
4252
|
+
* and {@link createForEachFrom} to insert a record per every one found by the query.
|
|
4253
|
+
*
|
|
4254
|
+
* The first argument is a query of a **single** record, it should have `find`, `take`, or similar.
|
|
4255
|
+
*
|
|
4256
|
+
* The second optional argument is a data which will be merged with columns returned by the query.
|
|
4257
|
+
*
|
|
4258
|
+
* The data for the second argument is the same as in {@link create}.
|
|
4259
|
+
*
|
|
4260
|
+
* Columns with runtime defaults (defined with a callback) are supported here.
|
|
4261
|
+
* The value for such a column will be injected unless selected from a related table or provided in a data object.
|
|
4262
|
+
*
|
|
4263
|
+
* ```ts
|
|
4264
|
+
* const oneRecord = await db.table.createOneFrom(
|
|
4265
|
+
* db.relatedTable
|
|
4266
|
+
* // use select to map columns from one table to another
|
|
4267
|
+
* .select({
|
|
4268
|
+
* // relatedTable's id will be inserted as "relatedId"
|
|
4269
|
+
* relatedId: 'id',
|
|
4270
|
+
* })
|
|
4271
|
+
* .findBy({ key: 'value' }),
|
|
4272
|
+
* // optional argument:
|
|
4273
|
+
* {
|
|
4274
|
+
* key: 'value',
|
|
4275
|
+
* // supports sql, nested select, create, update, delete queries
|
|
4276
|
+
* fromSql: () => sql`custom sql`,
|
|
4277
|
+
* fromQuery: () => db.otherTable.find(id).update(data).get('column'),
|
|
4278
|
+
* fromRelated: (q) => q.relatedTable.create(data).get('column'),
|
|
4279
|
+
* },
|
|
4280
|
+
* );
|
|
4281
|
+
* ```
|
|
4282
|
+
*
|
|
4283
|
+
* The query above will produce such a SQL (omitting `from*` values):
|
|
4284
|
+
*
|
|
4285
|
+
* ```sql
|
|
4286
|
+
* INSERT INTO "table"("relatedId", "key")
|
|
4287
|
+
* SELECT "relatedTable"."id" AS "relatedId", 'value'
|
|
4288
|
+
* FROM "relatedTable"
|
|
4289
|
+
* WHERE "relatedTable"."key" = 'value'
|
|
4290
|
+
* LIMIT 1
|
|
4291
|
+
* RETURNING *
|
|
4292
|
+
* ```
|
|
4293
|
+
*
|
|
4294
|
+
* @param query - query to create new records from
|
|
4295
|
+
* @param data - additionally you can set some columns
|
|
4296
|
+
*/
|
|
4297
|
+
createOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>): CreateRawOrFromResult<T>;
|
|
4298
|
+
/**
|
|
4299
|
+
* Works exactly as {@link createOneFrom}, except that it returns inserted row count by default.
|
|
4300
|
+
*
|
|
4301
|
+
* @param query - query to create new records from
|
|
4302
|
+
* @param data - additionally you can set some columns
|
|
4303
|
+
*/
|
|
4304
|
+
insertOneFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>): InsertRawOrFromResult<T>;
|
|
4305
|
+
/**
|
|
4306
|
+
* Inserts multiple records based on a query that selects a single record.
|
|
4307
|
+
*
|
|
4308
|
+
* Performs a single SQL query based on `INSERT ... SELECT ... FROM`.
|
|
4309
|
+
*
|
|
4310
|
+
* See {@link createOneFrom} to insert a single record based on a single record query,
|
|
4311
|
+
* and {@link createForEachFrom} to insert a record per every one found by the query.
|
|
4312
|
+
*
|
|
4313
|
+
* The first argument is a query of a **single** record, it should have `find`, `take`, or similar.
|
|
4314
|
+
*
|
|
4315
|
+
* The second argument is array of objects to be merged with columns returned by the query.
|
|
4316
|
+
*
|
|
4317
|
+
* The data for the second argument is the same as in {@link createMany}.
|
|
4318
|
+
*
|
|
4319
|
+
* Columns with runtime defaults (defined with a callback) are supported here.
|
|
4320
|
+
* The value for such a column will be injected unless selected from a related table or provided in a data object.
|
|
4321
|
+
*
|
|
4322
|
+
* ```ts
|
|
4323
|
+
* const twoRecords = await db.table.createManyFrom(
|
|
4324
|
+
* db.relatedTable
|
|
4325
|
+
* // use select to map columns from one table to another
|
|
4326
|
+
* .select({
|
|
4327
|
+
* // relatedTable's id will be inserted as "relatedId"
|
|
4328
|
+
* relatedId: 'id',
|
|
4329
|
+
* })
|
|
4330
|
+
* .findBy({ key: 'value' }),
|
|
4331
|
+
* [
|
|
4332
|
+
* {
|
|
4333
|
+
* key: 'value 1',
|
|
4334
|
+
* // supports sql, nested select, create, update, delete queries
|
|
4335
|
+
* fromSql: () => sql`custom sql`,
|
|
4336
|
+
* fromQuery: () => db.otherTable.find(id).update(data).get('column'),
|
|
4337
|
+
* fromRelated: (q) => q.relatedTable.create(data).get('column'),
|
|
4338
|
+
* },
|
|
4339
|
+
* {
|
|
4340
|
+
* key: 'value 2',
|
|
4341
|
+
* },
|
|
4342
|
+
* ],
|
|
4343
|
+
* );
|
|
4344
|
+
* ```
|
|
4345
|
+
*
|
|
4346
|
+
* The query above will produce such a SQL (omitting `from*` values):
|
|
4347
|
+
*
|
|
4348
|
+
* ```sql
|
|
4349
|
+
* WITH "relatedTable" AS (
|
|
4350
|
+
* SELECT "relatedTable"."id" AS "relatedId", 'value'
|
|
4351
|
+
* FROM "relatedTable"
|
|
4352
|
+
* WHERE "relatedTable"."key" = 'value'
|
|
4353
|
+
* LIMIT 1
|
|
4354
|
+
* )
|
|
4355
|
+
* INSERT INTO "table"("relatedId", "key")
|
|
4356
|
+
* SELECT "relatedTable".*, v."key"::text
|
|
4357
|
+
* FROM "relatedTable", (VALUES ('value1'), ('value2')) v("key")
|
|
4358
|
+
* RETURNING *
|
|
4359
|
+
* ```
|
|
4360
|
+
*
|
|
4361
|
+
* @param query - query to create new records from
|
|
4362
|
+
* @param data - array of records to create
|
|
4363
|
+
*/
|
|
4364
|
+
createManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>[]): CreateManyFromResult<T>;
|
|
4365
|
+
/**
|
|
4366
|
+
* Works exactly as {@link createManyFrom}, except that it returns inserted row count by default.
|
|
4367
|
+
*
|
|
4368
|
+
* @param query - query to create new records from
|
|
4369
|
+
* @param data - array of records to create
|
|
4370
|
+
*/
|
|
4371
|
+
insertManyFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>[]): InsertManyFromResult<T>;
|
|
4372
|
+
/**
|
|
4373
|
+
* Inserts a single record per every record found in a given query.
|
|
4374
|
+
*
|
|
4375
|
+
* Performs a single SQL query based on `INSERT ... SELECT ... FROM`.
|
|
4376
|
+
*
|
|
4377
|
+
* Unlike {@link createOneFrom}, it doesn't accept second argument with data.
|
|
4378
|
+
*
|
|
4379
|
+
* Runtime defaults cannot work with it.
|
|
4380
|
+
*
|
|
4381
|
+
* ```ts
|
|
4382
|
+
* const manyRecords = await db.table.createForEachFrom(
|
|
4383
|
+
* RelatedTable.select({ relatedId: 'id' }).where({ key: 'value' }),
|
|
4384
|
+
* );
|
|
4385
|
+
* ```
|
|
4386
|
+
*
|
|
4387
|
+
* @param query - query to create new records from
|
|
4388
|
+
*/
|
|
4389
|
+
createForEachFrom<T extends CreateSelf>(this: T, query: IsQuery): CreateManyFromResult<T>;
|
|
4390
|
+
/**
|
|
4391
|
+
* Works exactly as {@link createForEachFrom}, except that it returns inserted row count by default.
|
|
4392
|
+
*
|
|
4393
|
+
* @param query - query to create new records from
|
|
4394
|
+
*/
|
|
4395
|
+
insertForEachFrom<T extends CreateSelf>(this: T, query: IsQuery): InsertManyFromResult<T>;
|
|
4396
|
+
}
|
|
4397
|
+
|
|
4226
4398
|
interface CreateSelf extends IsQuery, PickQueryMetaResultRelationsWithDataReturnTypeShape, PickQueryUniqueProperties {
|
|
4227
4399
|
inputType: RecordUnknown;
|
|
4228
4400
|
}
|
|
@@ -4252,19 +4424,11 @@ type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union exte
|
|
|
4252
4424
|
type CreateResult<T extends CreateSelf, BT> = T extends {
|
|
4253
4425
|
isCount: true;
|
|
4254
4426
|
} ? SetQueryKind<T, 'create'> : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>>;
|
|
4255
|
-
type CreateRawOrFromResult<T extends CreateSelf> = T extends {
|
|
4256
|
-
isCount: true;
|
|
4257
|
-
} ? SetQueryKind<T, 'create'> : T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKind<T, 'create'> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKind<T, 'create'> : SetQueryKind<T, 'create'>;
|
|
4258
4427
|
type InsertResult<T extends CreateSelf, BT> = T['meta']['hasSelect'] extends true ? T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryReturnsRowCount<T, 'create'>;
|
|
4259
|
-
type InsertRawOrFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends undefined | 'all' ? SetQueryReturnsOneKind<T, 'create'> : T['returnType'] extends 'pluck' ? SetQueryReturnsColumnKind<T, 'create'> : SetQueryKind<T, 'create'> : SetQueryReturnsRowCount<T, 'create'>;
|
|
4260
4428
|
type CreateManyResult<T extends CreateSelf, BT> = T extends {
|
|
4261
4429
|
isCount: true;
|
|
4262
4430
|
} ? SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>>;
|
|
4263
|
-
type CreateManyFromResult<T extends CreateSelf> = T extends {
|
|
4264
|
-
isCount: true;
|
|
4265
|
-
} ? SetQueryKind<T, 'create'> : T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKind<T, 'create'> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKind<T, 'create'> : SetQueryKind<T, 'create'>;
|
|
4266
4431
|
type InsertManyResult<T extends CreateSelf, BT> = T['meta']['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKindResult<T, 'create', NarrowCreateResult<T, BT>> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryKindResult<T, 'create', NarrowCreateResult<T, BT>> : SetQueryReturnsRowCountMany<T, 'create'>;
|
|
4267
|
-
type InsertManyFromResult<T extends CreateSelf> = T['meta']['hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllKind<T, 'create'> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnKind<T, 'create'> : SetQueryKind<T, 'create'> : SetQueryReturnsRowCountMany<T, 'create'>;
|
|
4268
4432
|
/**
|
|
4269
4433
|
* When creating a record with a *belongs to* nested record,
|
|
4270
4434
|
* un-nullify foreign key columns of the result.
|
|
@@ -4297,24 +4461,16 @@ interface CreateCtx {
|
|
|
4297
4461
|
resultAll: RecordUnknown[];
|
|
4298
4462
|
}
|
|
4299
4463
|
declare const _queryCreate: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(q: T, data: CreateData<T, BT>) => CreateResult<T, BT>;
|
|
4300
|
-
declare const _queryInsert: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(
|
|
4464
|
+
declare const _queryInsert: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(query: T, data: CreateData<T, BT>) => InsertResult<T, BT>;
|
|
4301
4465
|
declare const _queryCreateMany: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(q: T, data: CreateData<T, BT>[]) => CreateManyResult<T, BT>;
|
|
4302
4466
|
declare const _queryInsertMany: <T extends CreateSelf, BT extends CreateBelongsToData<T>>(q: T, data: CreateData<T, BT>[]) => InsertManyResult<T, BT>;
|
|
4303
|
-
interface QueryReturningOne extends IsQuery {
|
|
4304
|
-
result: QueryColumns;
|
|
4305
|
-
returnType: 'one' | 'oneOrThrow';
|
|
4306
|
-
}
|
|
4307
|
-
declare const _queryCreateFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>) => CreateRawOrFromResult<T>;
|
|
4308
|
-
declare const _queryInsertFrom: <T extends CreateSelf, Q extends QueryReturningOne>(q: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>) => InsertRawOrFromResult<T>;
|
|
4309
|
-
declare const _queryCreateManyFrom: <T extends CreateSelf>(q: T, query: IsQuery) => CreateManyFromResult<T>;
|
|
4310
|
-
declare const _queryInsertManyFrom: <T extends CreateSelf>(q: T, query: IsQuery) => InsertManyFromResult<T>;
|
|
4311
4467
|
declare const _queryDefaults: <T extends CreateSelf, Data extends Partial<CreateData<T, CreateBelongsToData<T>>>>(q: T, data: Data) => AddQueryDefaults<T, { [K in keyof Data]: true; }>;
|
|
4312
4468
|
/**
|
|
4313
4469
|
* Names of all create methods,
|
|
4314
4470
|
* is used in relational query to remove these methods if chained relation shouldn't have them,
|
|
4315
4471
|
* for the case of has one/many through.
|
|
4316
4472
|
*/
|
|
4317
|
-
type CreateMethodsNames = 'create' | 'insert' | 'createMany' | 'insertMany' |
|
|
4473
|
+
type CreateMethodsNames = 'create' | 'insert' | 'createMany' | 'insertMany' | CreateFromMethodNames;
|
|
4318
4474
|
declare class QueryCreate {
|
|
4319
4475
|
/**
|
|
4320
4476
|
* `create` and `insert` create a single record.
|
|
@@ -4420,77 +4576,6 @@ declare class QueryCreate {
|
|
|
4420
4576
|
* @param data - array of records data, may have values, raw SQL, queries, relation operations
|
|
4421
4577
|
*/
|
|
4422
4578
|
insertMany<T extends CreateSelf, BT extends CreateBelongsToData<T>>(this: T, data: CreateData<T, BT>[]): InsertManyResult<T, BT>;
|
|
4423
|
-
/**
|
|
4424
|
-
* These methods are for creating a single record, for batch creating see {@link createManyFrom}.
|
|
4425
|
-
*
|
|
4426
|
-
* `createFrom` is to perform the `INSERT ... SELECT ...` SQL statement, it does select and insert by performing a single query.
|
|
4427
|
-
*
|
|
4428
|
-
* The first argument is a query for a **single** record, it should have `find`, `take`, or similar.
|
|
4429
|
-
*
|
|
4430
|
-
* The second optional argument is a data which will be merged with columns returned from the select query.
|
|
4431
|
-
*
|
|
4432
|
-
* The data for the second argument is the same as in {@link create}.
|
|
4433
|
-
*
|
|
4434
|
-
* Columns with runtime defaults (defined with a callback) are supported here.
|
|
4435
|
-
* The value for such a column will be injected unless selected from a related table or provided in a data object.
|
|
4436
|
-
*
|
|
4437
|
-
* ```ts
|
|
4438
|
-
* const oneRecord = await db.table.createFrom(
|
|
4439
|
-
* // In the select, key is a related table column, value is a column to insert as
|
|
4440
|
-
* RelatedTable.select({ relatedId: 'id' }).findBy({ key: 'value' }),
|
|
4441
|
-
* // optional argument:
|
|
4442
|
-
* {
|
|
4443
|
-
* key: 'value',
|
|
4444
|
-
* // supports sql, nested select, create, update, delete queries
|
|
4445
|
-
* fromSql: () => sql`custom sql`,
|
|
4446
|
-
* fromQuery: () => db.otherTable.find(id).update(data).get('column'),
|
|
4447
|
-
* fromRelated: (q) => q.relatedTable.create(data).get('column'),
|
|
4448
|
-
* },
|
|
4449
|
-
* );
|
|
4450
|
-
* ```
|
|
4451
|
-
*
|
|
4452
|
-
* The query above will produce such SQL:
|
|
4453
|
-
*
|
|
4454
|
-
* ```sql
|
|
4455
|
-
* INSERT INTO "table"("relatedId", "key")
|
|
4456
|
-
* SELECT "relatedTable"."id" AS "relatedId", 'value'
|
|
4457
|
-
* FROM "relatedTable"
|
|
4458
|
-
* WHERE "relatedTable"."key" = 'value'
|
|
4459
|
-
* LIMIT 1
|
|
4460
|
-
* RETURNING *
|
|
4461
|
-
* ```
|
|
4462
|
-
*
|
|
4463
|
-
* @param query - query to create new records from
|
|
4464
|
-
* @param data - additionally you can set some columns
|
|
4465
|
-
*/
|
|
4466
|
-
createFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>): CreateRawOrFromResult<T>;
|
|
4467
|
-
/**
|
|
4468
|
-
* Works exactly as {@link createFrom}, except that it returns inserted row count by default.
|
|
4469
|
-
*
|
|
4470
|
-
* @param query - query to create new records from
|
|
4471
|
-
* @param data - additionally you can set some columns
|
|
4472
|
-
*/
|
|
4473
|
-
insertFrom<T extends CreateSelf, Q extends QueryReturningOne>(this: T, query: Q, data?: Omit<CreateData<T, CreateBelongsToData<T>>, keyof Q['result']>): InsertRawOrFromResult<T>;
|
|
4474
|
-
/**
|
|
4475
|
-
* Similar to `createFrom`, but intended to create many records.
|
|
4476
|
-
*
|
|
4477
|
-
* Unlike `createFrom`, it doesn't accept second argument with data, and runtime defaults cannot work with it.
|
|
4478
|
-
*
|
|
4479
|
-
* ```ts
|
|
4480
|
-
* const manyRecords = await db.table.createManyFrom(
|
|
4481
|
-
* RelatedTable.select({ relatedId: 'id' }).where({ key: 'value' }),
|
|
4482
|
-
* );
|
|
4483
|
-
* ```
|
|
4484
|
-
*
|
|
4485
|
-
* @param query - query to create new records from
|
|
4486
|
-
*/
|
|
4487
|
-
createManyFrom<T extends CreateSelf>(this: T, query: IsQuery): CreateManyFromResult<T>;
|
|
4488
|
-
/**
|
|
4489
|
-
* Works exactly as {@link createManyFrom}, except that it returns inserted row count by default.
|
|
4490
|
-
*
|
|
4491
|
-
* @param query - query to create new records from
|
|
4492
|
-
*/
|
|
4493
|
-
insertManyFrom<T extends CreateSelf>(this: T, query: IsQuery): InsertManyFromResult<T>;
|
|
4494
4579
|
/**
|
|
4495
4580
|
* `defaults` allows setting values that will be used later in `create`.
|
|
4496
4581
|
*
|
|
@@ -5774,6 +5859,7 @@ type WithSqlResult<T extends PickQueryWithDataColumnTypes, Name extends string,
|
|
|
5774
5859
|
} : K extends keyof T['withData'] ? T['withData'][K] : never;
|
|
5775
5860
|
} : T[K];
|
|
5776
5861
|
};
|
|
5862
|
+
declare const _addWith: (query: IsQuery, withStore: object, item: WithItem, key?: string | number) => void;
|
|
5777
5863
|
declare const moveQueryValueToWith: (q: Query, withStore: object, value: Query, withKey: string | number, set?: RecordUnknown, key?: string) => string | undefined;
|
|
5778
5864
|
declare class WithMethods {
|
|
5779
5865
|
/**
|
|
@@ -7187,7 +7273,7 @@ interface SubQueryReturningSingle extends QueryMetaIsSubQuery {
|
|
|
7187
7273
|
returnType: 'one' | 'oneOrThrow';
|
|
7188
7274
|
}
|
|
7189
7275
|
type WrapQueryArg = FromQuerySelf;
|
|
7190
|
-
interface QueryMethods<ColumnTypes> extends QueryAsMethods, AggregateMethods, Select, FromMethods, Join, WithMethods, Union, JsonMethods, QueryCreate, Update, Delete, Transaction, For, Where, SearchMethods, Clear, Having, QueryLog, QueryHooks, QueryUpsert, QueryOrCreate, QueryGet, MergeQueryMethods, SqlMethod<ColumnTypes>, TransformMethods, QueryMap, ScopeMethods, SoftDeleteMethods, ExpressionMethods {
|
|
7276
|
+
interface QueryMethods<ColumnTypes> extends QueryAsMethods, AggregateMethods, Select, FromMethods, Join, WithMethods, Union, JsonMethods, QueryCreate, QueryCreateFrom, Update, Delete, Transaction, For, Where, SearchMethods, Clear, Having, QueryLog, QueryHooks, QueryUpsert, QueryOrCreate, QueryGet, MergeQueryMethods, SqlMethod<ColumnTypes>, TransformMethods, QueryMap, ScopeMethods, SoftDeleteMethods, ExpressionMethods {
|
|
7191
7277
|
}
|
|
7192
7278
|
declare class QueryMethods<ColumnTypes> {
|
|
7193
7279
|
/**
|
|
@@ -8769,4 +8855,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
8769
8855
|
*/
|
|
8770
8856
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
8771
8857
|
|
|
8772
|
-
export { type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorHandler, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, ArrayColumn, type ArrayColumnValue, type ArrayData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsConfig, type ComputedOptionsFactory, type CopyOptions, type CreateBelongsToData, type
|
|
8858
|
+
export { type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorHandler, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, ArrayColumn, type ArrayColumnValue, type ArrayData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsConfig, type ComputedOptionsFactory, type CopyOptions, type CreateBelongsToData, type CreateCtx, type CreateData, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbOptionsWithAdapter, type DbResult, type DbSharedOptions, type DbSqlQuery, type DbStructureDomainsMap, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, type ExpressionOutput, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, For, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratedColumn, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, Having, type HavingItem, type HookAction, type HookSelectArg, type IdentityColumn, InetColumn, type InsertQueryDataObjectValues, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinResultRequireMain, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MergeQuery, MergeQueryMethods, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, type OnConflictSet$1 as OnConflictSet, type OnConflictTarget, OnMethods, type Operator, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNumber, type OperatorsText, type OperatorsTime, OrExpression, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, PathColumn, type PickColumnData, type PickQueryBaseQuery, type PickQueryDataShapeAndJoinedShapes, type PickQueryDataShapeAndJoinedShapesAndAliases, type PickQueryInternal, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, QueryAsMethods, type QueryBatchResult, type QueryBeforeHook, type QueryBeforeHookInternal, type QueryBuilder, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryIfResultThen, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpressionBooleanOrNullResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, type QueryTake, type QueryTakeOptional, QueryUpsert, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type ReturnsQueryOrExpression, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsValue, type SelectItem, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsValueOrThrowKind, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, type TransactionOptions, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfigs, type WithItem, type WithItems, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _addWith, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryChangeCounter, _queryCreate, _queryCreateForEachFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateOneFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertForEachFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertOneFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDbWithAdapter, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, performQuery, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
|