pqb 0.45.0 → 0.45.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +62 -8
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2291,6 +2291,18 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
|
2291
2291
|
quotedAs
|
|
2292
2292
|
);
|
|
2293
2293
|
}
|
|
2294
|
+
} else if ("d" in args) {
|
|
2295
|
+
const shape = args.c;
|
|
2296
|
+
const { values } = ctx;
|
|
2297
|
+
target = `(VALUES ${args.d.map((x) => {
|
|
2298
|
+
return "(" + Object.entries(shape).map(([key, column]) => {
|
|
2299
|
+
const value = x[key];
|
|
2300
|
+
return addValue(
|
|
2301
|
+
values,
|
|
2302
|
+
value === null || value === void 0 ? null : column.data.encode ? column.data.encode(value) : value
|
|
2303
|
+
) + "::" + column.dataType;
|
|
2304
|
+
}).join(", ") + ")";
|
|
2305
|
+
}).join(", ")}) "${args.a}"(${Object.entries(shape).map(([key, column]) => `"${column.data.name || key}"`).join(", ")})`;
|
|
2294
2306
|
} else {
|
|
2295
2307
|
const { q, s } = args;
|
|
2296
2308
|
let joinAs;
|
|
@@ -9910,6 +9922,54 @@ class Join {
|
|
|
9910
9922
|
_joinLateralProcessArg(q, arg, cb)
|
|
9911
9923
|
);
|
|
9912
9924
|
}
|
|
9925
|
+
/**
|
|
9926
|
+
* This method may be useful
|
|
9927
|
+
* for combining with [createManyFrom](/guide/create-update-delete.html#createmanyfrom-insertmanyfrom).
|
|
9928
|
+
*
|
|
9929
|
+
* `createManyFrom` creates multiple record based on a selecting query:
|
|
9930
|
+
*
|
|
9931
|
+
* ```sql
|
|
9932
|
+
* INSERT INTO t1(c1, c2)
|
|
9933
|
+
* SELECT c1, c2 FROM t2
|
|
9934
|
+
* ```
|
|
9935
|
+
*
|
|
9936
|
+
* Such a query inserts one record per one selected record.
|
|
9937
|
+
*
|
|
9938
|
+
* Use `joinData` to insert a multiplication of selected records and the provided data.
|
|
9939
|
+
*
|
|
9940
|
+
* ```ts
|
|
9941
|
+
* const data = [{ column2: 'one' }, { column2: 'two' }, { column2: 'three' }];
|
|
9942
|
+
*
|
|
9943
|
+
* await db.table.createManyFrom(
|
|
9944
|
+
* db.otherTable
|
|
9945
|
+
* .joinData('data', (t) => ({ column2: t.text() }), data)
|
|
9946
|
+
* .select('otherTable.column1', 'data.column2'),
|
|
9947
|
+
* );
|
|
9948
|
+
* ```
|
|
9949
|
+
*
|
|
9950
|
+
* If the query on the other table returns 2 records,
|
|
9951
|
+
* and the data array contains 3 records, then 2 \* 3 = 6 will be inserted - every combination.
|
|
9952
|
+
*
|
|
9953
|
+
* Joined data values are available in `where` just as usual.
|
|
9954
|
+
*
|
|
9955
|
+
* @param as - alias to reference joined columns
|
|
9956
|
+
* @param fn - declare column types
|
|
9957
|
+
* @param data - array of data to join
|
|
9958
|
+
*/
|
|
9959
|
+
joinData(as, fn, data) {
|
|
9960
|
+
const shape = fn(this.columnTypes);
|
|
9961
|
+
const q = _clone(this);
|
|
9962
|
+
setQueryObjectValue(q, "joinedShapes", as, shape);
|
|
9963
|
+
const parsers = Object.fromEntries(
|
|
9964
|
+
Object.entries(shape).map(([key, column]) => [key, column._parse])
|
|
9965
|
+
);
|
|
9966
|
+
setQueryObjectValue(q, "joinedParsers", as, parsers);
|
|
9967
|
+
pushQueryValue(q, "join", {
|
|
9968
|
+
type: "JOIN",
|
|
9969
|
+
args: { a: as, c: shape, d: data }
|
|
9970
|
+
});
|
|
9971
|
+
return q;
|
|
9972
|
+
}
|
|
9913
9973
|
}
|
|
9914
9974
|
const makeOnItem = (joinTo, joinFrom, args) => ({
|
|
9915
9975
|
ON: {
|