pqb 0.4.1 → 0.4.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 +9 -5
- package/dist/index.esm.js +26 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/queryMethods/create.test.ts +3 -1
- package/src/queryMethods/create.ts +41 -36
- package/src/relations.ts +20 -8
package/dist/index.js
CHANGED
|
@@ -4259,7 +4259,7 @@ const handleManyData = (q, data, ctx) => {
|
|
|
4259
4259
|
const insert = (self, {
|
|
4260
4260
|
columns,
|
|
4261
4261
|
values
|
|
4262
|
-
}, returnType, ctx
|
|
4262
|
+
}, returnType, ctx) => {
|
|
4263
4263
|
const q = self;
|
|
4264
4264
|
const returning = q.query.select;
|
|
4265
4265
|
delete q.query.and;
|
|
@@ -4267,7 +4267,6 @@ const insert = (self, {
|
|
|
4267
4267
|
q.query.type = "insert";
|
|
4268
4268
|
q.query.columns = columns;
|
|
4269
4269
|
q.query.values = values;
|
|
4270
|
-
q.query.fromQuery = fromQuery;
|
|
4271
4270
|
if (!ctx) {
|
|
4272
4271
|
q.query.returnType = returnType;
|
|
4273
4272
|
return q;
|
|
@@ -4348,11 +4347,33 @@ class Create {
|
|
|
4348
4347
|
return this.clone()._create(data);
|
|
4349
4348
|
}
|
|
4350
4349
|
_create(data) {
|
|
4350
|
+
var _a;
|
|
4351
4351
|
handleSelect(this);
|
|
4352
4352
|
const ctx = createCtx(this);
|
|
4353
|
+
const obj = handleOneData(this, data, ctx);
|
|
4354
|
+
let { columns } = obj;
|
|
4355
|
+
const { fromQuery } = this.query;
|
|
4356
|
+
if (fromQuery) {
|
|
4357
|
+
if (!queryTypeWithLimitOne[fromQuery.query.returnType]) {
|
|
4358
|
+
throw new Error(
|
|
4359
|
+
"Cannot create based on a query which returns multiple records"
|
|
4360
|
+
);
|
|
4361
|
+
}
|
|
4362
|
+
const queryColumns = [];
|
|
4363
|
+
(_a = fromQuery.query.select) == null ? void 0 : _a.forEach((item) => {
|
|
4364
|
+
if (typeof item === "string") {
|
|
4365
|
+
const index = item.indexOf(".");
|
|
4366
|
+
queryColumns.push(index === -1 ? item : item.slice(index + 1));
|
|
4367
|
+
} else if ("selectAs" in item) {
|
|
4368
|
+
queryColumns.push(...Object.keys(item.selectAs));
|
|
4369
|
+
}
|
|
4370
|
+
});
|
|
4371
|
+
queryColumns.push(...columns);
|
|
4372
|
+
columns = queryColumns;
|
|
4373
|
+
}
|
|
4353
4374
|
return insert(
|
|
4354
4375
|
this,
|
|
4355
|
-
|
|
4376
|
+
{ columns, values: obj.values },
|
|
4356
4377
|
getSingleReturnType(this),
|
|
4357
4378
|
ctx
|
|
4358
4379
|
);
|
|
@@ -4381,34 +4402,8 @@ class Create {
|
|
|
4381
4402
|
return this.clone()._createFrom(query, data);
|
|
4382
4403
|
}
|
|
4383
4404
|
_createFrom(query, data) {
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
throw new Error(
|
|
4387
|
-
"createFrom accepts only a query which returns one record"
|
|
4388
|
-
);
|
|
4389
|
-
}
|
|
4390
|
-
if (!this.query.select) {
|
|
4391
|
-
this.query.select = ["*"];
|
|
4392
|
-
}
|
|
4393
|
-
const ctx = createCtx(this);
|
|
4394
|
-
const queryColumns = [];
|
|
4395
|
-
(_a = query.query.select) == null ? void 0 : _a.forEach((item) => {
|
|
4396
|
-
if (typeof item === "string") {
|
|
4397
|
-
const index = item.indexOf(".");
|
|
4398
|
-
queryColumns.push(index === -1 ? item : item.slice(index + 1));
|
|
4399
|
-
} else if ("selectAs" in item) {
|
|
4400
|
-
queryColumns.push(...Object.keys(item.selectAs));
|
|
4401
|
-
}
|
|
4402
|
-
});
|
|
4403
|
-
const { columns, values } = handleOneData(this, data, ctx);
|
|
4404
|
-
queryColumns.push(...columns);
|
|
4405
|
-
return insert(
|
|
4406
|
-
this,
|
|
4407
|
-
{ columns: queryColumns, values },
|
|
4408
|
-
"one",
|
|
4409
|
-
ctx,
|
|
4410
|
-
query
|
|
4411
|
-
);
|
|
4405
|
+
this.query.fromQuery = query;
|
|
4406
|
+
return this._create(data);
|
|
4412
4407
|
}
|
|
4413
4408
|
defaults(data) {
|
|
4414
4409
|
return this.clone()._defaults(data);
|