pqb 0.39.1 → 0.39.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 +111 -23
- package/dist/index.js +337 -173
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +336 -174
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -117,25 +117,25 @@ const sqlFn = (...args) => {
|
|
|
117
117
|
return (...args2) => new RawSQL(args2, arg);
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
var __defProp$
|
|
121
|
-
var __defProps$
|
|
122
|
-
var __getOwnPropDescs$
|
|
123
|
-
var __getOwnPropSymbols$
|
|
124
|
-
var __hasOwnProp$
|
|
125
|
-
var __propIsEnum$
|
|
126
|
-
var __defNormalProp$
|
|
127
|
-
var __spreadValues$
|
|
120
|
+
var __defProp$m = Object.defineProperty;
|
|
121
|
+
var __defProps$d = Object.defineProperties;
|
|
122
|
+
var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
|
|
123
|
+
var __getOwnPropSymbols$n = Object.getOwnPropertySymbols;
|
|
124
|
+
var __hasOwnProp$n = Object.prototype.hasOwnProperty;
|
|
125
|
+
var __propIsEnum$n = Object.prototype.propertyIsEnumerable;
|
|
126
|
+
var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
127
|
+
var __spreadValues$m = (a, b) => {
|
|
128
128
|
for (var prop in b || (b = {}))
|
|
129
|
-
if (__hasOwnProp$
|
|
130
|
-
__defNormalProp$
|
|
131
|
-
if (__getOwnPropSymbols$
|
|
132
|
-
for (var prop of __getOwnPropSymbols$
|
|
133
|
-
if (__propIsEnum$
|
|
134
|
-
__defNormalProp$
|
|
129
|
+
if (__hasOwnProp$n.call(b, prop))
|
|
130
|
+
__defNormalProp$m(a, prop, b[prop]);
|
|
131
|
+
if (__getOwnPropSymbols$n)
|
|
132
|
+
for (var prop of __getOwnPropSymbols$n(b)) {
|
|
133
|
+
if (__propIsEnum$n.call(b, prop))
|
|
134
|
+
__defNormalProp$m(a, prop, b[prop]);
|
|
135
135
|
}
|
|
136
136
|
return a;
|
|
137
137
|
};
|
|
138
|
-
var __spreadProps$
|
|
138
|
+
var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b));
|
|
139
139
|
class ColumnType extends ColumnTypeBase {
|
|
140
140
|
/**
|
|
141
141
|
* Mark the column as a primary key.
|
|
@@ -334,13 +334,13 @@ class ColumnType extends ColumnTypeBase {
|
|
|
334
334
|
*/
|
|
335
335
|
searchIndex(...args) {
|
|
336
336
|
return pushColumnData(this, "indexes", {
|
|
337
|
-
options: __spreadValues$
|
|
337
|
+
options: __spreadValues$m(__spreadValues$m({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
|
|
338
338
|
name: typeof args[0] === "string" ? args[0] : void 0
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
341
|
unique(...args) {
|
|
342
342
|
return pushColumnData(this, "indexes", {
|
|
343
|
-
options: __spreadProps$
|
|
343
|
+
options: __spreadProps$d(__spreadValues$m({}, typeof args[0] === "string" ? args[1] : args[0]), {
|
|
344
344
|
unique: true
|
|
345
345
|
}),
|
|
346
346
|
name: typeof args[0] === "string" ? args[0] : void 0
|
|
@@ -383,25 +383,25 @@ class ColumnType extends ColumnTypeBase {
|
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
-
var __defProp$
|
|
387
|
-
var __defProps$
|
|
388
|
-
var __getOwnPropDescs$
|
|
389
|
-
var __getOwnPropSymbols$
|
|
390
|
-
var __hasOwnProp$
|
|
391
|
-
var __propIsEnum$
|
|
392
|
-
var __defNormalProp$
|
|
393
|
-
var __spreadValues$
|
|
386
|
+
var __defProp$l = Object.defineProperty;
|
|
387
|
+
var __defProps$c = Object.defineProperties;
|
|
388
|
+
var __getOwnPropDescs$c = Object.getOwnPropertyDescriptors;
|
|
389
|
+
var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
|
|
390
|
+
var __hasOwnProp$m = Object.prototype.hasOwnProperty;
|
|
391
|
+
var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
|
|
392
|
+
var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
393
|
+
var __spreadValues$l = (a, b) => {
|
|
394
394
|
for (var prop in b || (b = {}))
|
|
395
|
-
if (__hasOwnProp$
|
|
396
|
-
__defNormalProp$
|
|
397
|
-
if (__getOwnPropSymbols$
|
|
398
|
-
for (var prop of __getOwnPropSymbols$
|
|
399
|
-
if (__propIsEnum$
|
|
400
|
-
__defNormalProp$
|
|
395
|
+
if (__hasOwnProp$m.call(b, prop))
|
|
396
|
+
__defNormalProp$l(a, prop, b[prop]);
|
|
397
|
+
if (__getOwnPropSymbols$m)
|
|
398
|
+
for (var prop of __getOwnPropSymbols$m(b)) {
|
|
399
|
+
if (__propIsEnum$m.call(b, prop))
|
|
400
|
+
__defNormalProp$l(a, prop, b[prop]);
|
|
401
401
|
}
|
|
402
402
|
return a;
|
|
403
403
|
};
|
|
404
|
-
var __spreadProps$
|
|
404
|
+
var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
405
405
|
const knownDefaults = {
|
|
406
406
|
current_timestamp: "now()",
|
|
407
407
|
"transaction_timestamp()": "now()"
|
|
@@ -417,7 +417,7 @@ const simplifyColumnDefault = (value) => {
|
|
|
417
417
|
const instantiateColumn = (typeFn, params) => {
|
|
418
418
|
const column = typeFn();
|
|
419
419
|
const { dateTimePrecision } = params;
|
|
420
|
-
Object.assign(column.data, __spreadProps$
|
|
420
|
+
Object.assign(column.data, __spreadProps$c(__spreadValues$l({}, params), {
|
|
421
421
|
dateTimePrecision: (
|
|
422
422
|
// 0 is default for date, 6 is default for timestamp
|
|
423
423
|
dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
|
|
@@ -856,25 +856,25 @@ const getSqlText = (sql) => {
|
|
|
856
856
|
throw new Error(`Batch SQL is not supported in this query`);
|
|
857
857
|
};
|
|
858
858
|
|
|
859
|
-
var __defProp$
|
|
860
|
-
var __defProps$
|
|
861
|
-
var __getOwnPropDescs$
|
|
862
|
-
var __getOwnPropSymbols$
|
|
863
|
-
var __hasOwnProp$
|
|
864
|
-
var __propIsEnum$
|
|
865
|
-
var __defNormalProp$
|
|
866
|
-
var __spreadValues$
|
|
859
|
+
var __defProp$k = Object.defineProperty;
|
|
860
|
+
var __defProps$b = Object.defineProperties;
|
|
861
|
+
var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
|
|
862
|
+
var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
|
|
863
|
+
var __hasOwnProp$l = Object.prototype.hasOwnProperty;
|
|
864
|
+
var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
|
|
865
|
+
var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
866
|
+
var __spreadValues$k = (a, b) => {
|
|
867
867
|
for (var prop in b || (b = {}))
|
|
868
|
-
if (__hasOwnProp$
|
|
869
|
-
__defNormalProp$
|
|
870
|
-
if (__getOwnPropSymbols$
|
|
871
|
-
for (var prop of __getOwnPropSymbols$
|
|
872
|
-
if (__propIsEnum$
|
|
873
|
-
__defNormalProp$
|
|
868
|
+
if (__hasOwnProp$l.call(b, prop))
|
|
869
|
+
__defNormalProp$k(a, prop, b[prop]);
|
|
870
|
+
if (__getOwnPropSymbols$l)
|
|
871
|
+
for (var prop of __getOwnPropSymbols$l(b)) {
|
|
872
|
+
if (__propIsEnum$l.call(b, prop))
|
|
873
|
+
__defNormalProp$k(a, prop, b[prop]);
|
|
874
874
|
}
|
|
875
875
|
return a;
|
|
876
876
|
};
|
|
877
|
-
var __spreadProps$
|
|
877
|
+
var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
878
878
|
function setQueryOperators(query, operators) {
|
|
879
879
|
const q = query.q;
|
|
880
880
|
if (q.operators !== operators) {
|
|
@@ -963,7 +963,7 @@ const base = {
|
|
|
963
963
|
(key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue$1(value, ctx, quotedAs)}`
|
|
964
964
|
)
|
|
965
965
|
};
|
|
966
|
-
const boolean = __spreadProps$
|
|
966
|
+
const boolean = __spreadProps$b(__spreadValues$k({}, base), {
|
|
967
967
|
and: make(
|
|
968
968
|
(key, value, ctx, quotedAs) => `${key} AND ${value.q.expr.toSQL(ctx, quotedAs)}`
|
|
969
969
|
),
|
|
@@ -971,7 +971,7 @@ const boolean = __spreadProps$9(__spreadValues$j({}, base), {
|
|
|
971
971
|
(key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
|
|
972
972
|
)
|
|
973
973
|
});
|
|
974
|
-
const numeric = __spreadProps$
|
|
974
|
+
const numeric = __spreadProps$b(__spreadValues$k({}, base), {
|
|
975
975
|
lt: make(
|
|
976
976
|
(key, value, ctx, quotedAs) => `${key} < ${quoteValue$1(value, ctx, quotedAs)}`
|
|
977
977
|
),
|
|
@@ -992,7 +992,7 @@ const numeric = __spreadProps$9(__spreadValues$j({}, base), {
|
|
|
992
992
|
)}`
|
|
993
993
|
)
|
|
994
994
|
});
|
|
995
|
-
const text = __spreadProps$
|
|
995
|
+
const text = __spreadProps$b(__spreadValues$k({}, base), {
|
|
996
996
|
contains: make(
|
|
997
997
|
(key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
|
|
998
998
|
),
|
|
@@ -1014,7 +1014,7 @@ const text = __spreadProps$9(__spreadValues$j({}, base), {
|
|
|
1014
1014
|
});
|
|
1015
1015
|
const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
1016
1016
|
const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${(options == null ? void 0 : options.vars) ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : (options == null ? void 0 : options.silent) ? ", NULL, true" : ""})`;
|
|
1017
|
-
const json = __spreadProps$
|
|
1017
|
+
const json = __spreadProps$b(__spreadValues$k({}, base), {
|
|
1018
1018
|
jsonPathQueryFirst: Object.assign(
|
|
1019
1019
|
function(path, options) {
|
|
1020
1020
|
var _a, _b, _c, _d, _e;
|
|
@@ -1264,25 +1264,25 @@ class BigSerialColumn extends NumberAsStringBaseColumn {
|
|
|
1264
1264
|
}
|
|
1265
1265
|
}
|
|
1266
1266
|
|
|
1267
|
-
var __defProp$
|
|
1268
|
-
var __defProps$
|
|
1269
|
-
var __getOwnPropDescs$
|
|
1270
|
-
var __getOwnPropSymbols$
|
|
1271
|
-
var __hasOwnProp$
|
|
1272
|
-
var __propIsEnum$
|
|
1273
|
-
var __defNormalProp$
|
|
1274
|
-
var __spreadValues$
|
|
1267
|
+
var __defProp$j = Object.defineProperty;
|
|
1268
|
+
var __defProps$a = Object.defineProperties;
|
|
1269
|
+
var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
|
|
1270
|
+
var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
|
|
1271
|
+
var __hasOwnProp$k = Object.prototype.hasOwnProperty;
|
|
1272
|
+
var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
|
|
1273
|
+
var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1274
|
+
var __spreadValues$j = (a, b) => {
|
|
1275
1275
|
for (var prop in b || (b = {}))
|
|
1276
|
-
if (__hasOwnProp$
|
|
1277
|
-
__defNormalProp$
|
|
1278
|
-
if (__getOwnPropSymbols$
|
|
1279
|
-
for (var prop of __getOwnPropSymbols$
|
|
1280
|
-
if (__propIsEnum$
|
|
1281
|
-
__defNormalProp$
|
|
1276
|
+
if (__hasOwnProp$k.call(b, prop))
|
|
1277
|
+
__defNormalProp$j(a, prop, b[prop]);
|
|
1278
|
+
if (__getOwnPropSymbols$k)
|
|
1279
|
+
for (var prop of __getOwnPropSymbols$k(b)) {
|
|
1280
|
+
if (__propIsEnum$k.call(b, prop))
|
|
1281
|
+
__defNormalProp$j(a, prop, b[prop]);
|
|
1282
1282
|
}
|
|
1283
1283
|
return a;
|
|
1284
1284
|
};
|
|
1285
|
-
var __spreadProps$
|
|
1285
|
+
var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
1286
1286
|
class TextBaseColumn extends ColumnType {
|
|
1287
1287
|
constructor(schema, schemaType = schema.stringSchema()) {
|
|
1288
1288
|
super(schema, schemaType);
|
|
@@ -1336,7 +1336,7 @@ class StringColumn extends VarCharColumn {
|
|
|
1336
1336
|
}
|
|
1337
1337
|
}
|
|
1338
1338
|
const textColumnToCode = (column, ctx, key) => {
|
|
1339
|
-
const data = __spreadValues$
|
|
1339
|
+
const data = __spreadValues$j({}, column.data);
|
|
1340
1340
|
let args = "";
|
|
1341
1341
|
const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
|
|
1342
1342
|
if (data.minArg !== void 0 && data.min === data.minArg || hasMax) {
|
|
@@ -1640,7 +1640,7 @@ class UUIDColumn extends ColumnType {
|
|
|
1640
1640
|
key,
|
|
1641
1641
|
`uuid()`,
|
|
1642
1642
|
// don't output the default default
|
|
1643
|
-
data.default instanceof RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$
|
|
1643
|
+
data.default instanceof RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$a(__spreadValues$j({}, data), { default: void 0 }) : data
|
|
1644
1644
|
);
|
|
1645
1645
|
}
|
|
1646
1646
|
}
|
|
@@ -1866,15 +1866,22 @@ const queryTypeWithLimitOne = {
|
|
|
1866
1866
|
};
|
|
1867
1867
|
const isQueryReturnsAll = (q) => !q.q.returnType || q.q.returnType === "all";
|
|
1868
1868
|
|
|
1869
|
-
|
|
1869
|
+
const applySqlComputed = (ctx, q, computed, as, quotedAs) => {
|
|
1870
|
+
var _a;
|
|
1871
|
+
const parser = computed.result.value.parseFn;
|
|
1872
|
+
if (parser)
|
|
1873
|
+
((_a = q.parsers) != null ? _a : q.parsers = {})[as] = parser;
|
|
1874
|
+
return computed.toSQL(ctx, quotedAs);
|
|
1875
|
+
};
|
|
1876
|
+
function simpleColumnToSQL(ctx, q, key, column, quotedAs) {
|
|
1870
1877
|
if (!column)
|
|
1871
1878
|
return `"${key}"`;
|
|
1872
1879
|
const { data } = column;
|
|
1873
|
-
return data.computed ? data.computed
|
|
1880
|
+
return data.computed ? applySqlComputed(ctx, q, data.computed, key, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
1874
1881
|
}
|
|
1875
|
-
function simpleExistingColumnToSQL(ctx, key, column, quotedAs) {
|
|
1882
|
+
function simpleExistingColumnToSQL(ctx, q, key, column, quotedAs) {
|
|
1876
1883
|
const { data } = column;
|
|
1877
|
-
return data.computed ? data.computed
|
|
1884
|
+
return data.computed ? applySqlComputed(ctx, q, data.computed, key, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
1878
1885
|
}
|
|
1879
1886
|
const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
1880
1887
|
var _a;
|
|
@@ -1893,7 +1900,7 @@ const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
|
1893
1900
|
if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
|
|
1894
1901
|
return `"${column}".r`;
|
|
1895
1902
|
}
|
|
1896
|
-
return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
|
|
1903
|
+
return simpleColumnToSQL(ctx, data, column, shape[column], quotedAs);
|
|
1897
1904
|
};
|
|
1898
1905
|
const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
1899
1906
|
var _a;
|
|
@@ -1908,12 +1915,12 @@ const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
|
1908
1915
|
for (const s of data.select) {
|
|
1909
1916
|
if (typeof s === "object" && "selectAs" in s) {
|
|
1910
1917
|
if (column in s.selectAs) {
|
|
1911
|
-
return simpleColumnToSQL(ctx, column, data.shape[column]);
|
|
1918
|
+
return simpleColumnToSQL(ctx, data, column, data.shape[column]);
|
|
1912
1919
|
}
|
|
1913
1920
|
}
|
|
1914
1921
|
}
|
|
1915
1922
|
}
|
|
1916
|
-
return simpleColumnToSQL(ctx, column, data.shape[column], quotedAs);
|
|
1923
|
+
return simpleColumnToSQL(ctx, data, column, data.shape[column], quotedAs);
|
|
1917
1924
|
}
|
|
1918
1925
|
};
|
|
1919
1926
|
const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) => {
|
|
@@ -1931,17 +1938,30 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
1931
1938
|
return `"${tableName}"."${col.data.name}"`;
|
|
1932
1939
|
}
|
|
1933
1940
|
if (col.data.computed) {
|
|
1934
|
-
return
|
|
1941
|
+
return applySqlComputed(ctx, data, col.data.computed, column, quoted);
|
|
1935
1942
|
}
|
|
1936
1943
|
return `"${tableName}"."${key}"`;
|
|
1937
1944
|
}
|
|
1938
1945
|
return `"${tableName}"."${key}"`;
|
|
1939
1946
|
};
|
|
1940
|
-
const
|
|
1947
|
+
const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
|
|
1948
|
+
const index = column.indexOf(".");
|
|
1949
|
+
return index !== -1 ? tableColumnToSqlWithAs(
|
|
1950
|
+
ctx,
|
|
1951
|
+
data,
|
|
1952
|
+
column,
|
|
1953
|
+
column.slice(0, index),
|
|
1954
|
+
column.slice(index + 1),
|
|
1955
|
+
as,
|
|
1956
|
+
quotedAs,
|
|
1957
|
+
select
|
|
1958
|
+
) : ownColumnToSqlWithAs(ctx, data, column, as, quotedAs, select);
|
|
1959
|
+
};
|
|
1960
|
+
const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select) => {
|
|
1941
1961
|
var _a, _b, _c;
|
|
1942
1962
|
if (key === "*") {
|
|
1943
1963
|
if ((_a = data.joinedShapes) == null ? void 0 : _a[table]) {
|
|
1944
|
-
return select ? `row_to_json("${table}".*) "${
|
|
1964
|
+
return select ? `row_to_json("${table}".*) "${as}"` : `"${table}".r "${as}"`;
|
|
1945
1965
|
}
|
|
1946
1966
|
return column;
|
|
1947
1967
|
}
|
|
@@ -1950,29 +1970,41 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, quotedAs, select)
|
|
|
1950
1970
|
const col = quoted === quotedAs ? data.shape[key] : (_c = data.joinedShapes) == null ? void 0 : _c[tableName][key];
|
|
1951
1971
|
if (col) {
|
|
1952
1972
|
if (col.data.name && col.data.name !== key) {
|
|
1953
|
-
return `"${tableName}"."${col.data.name}" "${
|
|
1973
|
+
return `"${tableName}"."${col.data.name}" "${as}"`;
|
|
1954
1974
|
}
|
|
1955
1975
|
if (col.data.computed) {
|
|
1956
|
-
return `${
|
|
1976
|
+
return `${applySqlComputed(
|
|
1977
|
+
ctx,
|
|
1978
|
+
data,
|
|
1979
|
+
col.data.computed,
|
|
1980
|
+
as,
|
|
1981
|
+
quoted
|
|
1982
|
+
)} "${as}"`;
|
|
1957
1983
|
}
|
|
1958
1984
|
}
|
|
1959
|
-
return `"${tableName}"."${key}"`;
|
|
1985
|
+
return `"${tableName}"."${key}"${key === as ? "" : ` "${as}"`}`;
|
|
1960
1986
|
};
|
|
1961
|
-
const ownColumnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
|
|
1987
|
+
const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
|
|
1962
1988
|
var _a;
|
|
1963
1989
|
if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
|
|
1964
|
-
return select ? `row_to_json("${column}".*) "${
|
|
1990
|
+
return select ? `row_to_json("${column}".*) "${as}"` : `"${column}".r "${as}"`;
|
|
1965
1991
|
}
|
|
1966
1992
|
const col = data.shape[column];
|
|
1967
1993
|
if (col) {
|
|
1968
1994
|
if (col.data.name && col.data.name !== column) {
|
|
1969
|
-
return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}" "${
|
|
1995
|
+
return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}"${col.data.name === as ? "" : ` "${as}"`}`;
|
|
1970
1996
|
}
|
|
1971
1997
|
if (col.data.computed) {
|
|
1972
|
-
return `${
|
|
1998
|
+
return `${applySqlComputed(
|
|
1999
|
+
ctx,
|
|
2000
|
+
data,
|
|
2001
|
+
col.data.computed,
|
|
2002
|
+
as,
|
|
2003
|
+
quotedAs
|
|
2004
|
+
)} "${as}"`;
|
|
1973
2005
|
}
|
|
1974
2006
|
}
|
|
1975
|
-
return `${quotedAs ? `${quotedAs}.` : ""}"${column}"`;
|
|
2007
|
+
return `${quotedAs ? `${quotedAs}.` : ""}"${column}"${column === as ? "" : ` "${as}"`}`;
|
|
1976
2008
|
};
|
|
1977
2009
|
const rawOrColumnToSql = (ctx, data, expr, quotedAs, shape = data.shape, select) => {
|
|
1978
2010
|
return typeof expr === "string" ? columnToSql(ctx, data, shape, expr, quotedAs, select) : expr.toSQL(ctx, quotedAs);
|
|
@@ -2009,26 +2041,33 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
2009
2041
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
2010
2042
|
return value;
|
|
2011
2043
|
};
|
|
2012
|
-
var _query;
|
|
2044
|
+
var _query, _query2;
|
|
2013
2045
|
class OrchidOrmError extends Error {
|
|
2014
2046
|
}
|
|
2015
2047
|
class NotFoundError extends OrchidOrmError {
|
|
2016
2048
|
constructor(query, message = "Record is not found") {
|
|
2017
2049
|
super(message);
|
|
2018
|
-
|
|
2050
|
+
// `#query` is private to prevent it from serializing to not cause problems to test runner reports
|
|
2051
|
+
__privateAdd(this, _query, void 0);
|
|
2052
|
+
__privateSet(this, _query, query);
|
|
2053
|
+
}
|
|
2054
|
+
get query() {
|
|
2055
|
+
return __privateGet(this, _query);
|
|
2019
2056
|
}
|
|
2020
2057
|
}
|
|
2058
|
+
_query = new WeakMap();
|
|
2021
2059
|
class OrchidOrmInternalError extends Error {
|
|
2022
2060
|
constructor(query, message) {
|
|
2023
2061
|
super(message);
|
|
2024
|
-
|
|
2025
|
-
|
|
2062
|
+
// `#query` is private to prevent it from serializing to not cause problems to test runner reports
|
|
2063
|
+
__privateAdd(this, _query2, void 0);
|
|
2064
|
+
__privateSet(this, _query2, query);
|
|
2026
2065
|
}
|
|
2027
2066
|
get query() {
|
|
2028
|
-
return __privateGet(this,
|
|
2067
|
+
return __privateGet(this, _query2);
|
|
2029
2068
|
}
|
|
2030
2069
|
}
|
|
2031
|
-
|
|
2070
|
+
_query2 = new WeakMap();
|
|
2032
2071
|
class QueryError extends OrchidOrmInternalError {
|
|
2033
2072
|
get isUnique() {
|
|
2034
2073
|
return this.code === "23505";
|
|
@@ -2304,7 +2343,13 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2304
2343
|
let column = query.shape[key];
|
|
2305
2344
|
let quotedColumn;
|
|
2306
2345
|
if (column) {
|
|
2307
|
-
quotedColumn = simpleExistingColumnToSQL(
|
|
2346
|
+
quotedColumn = simpleExistingColumnToSQL(
|
|
2347
|
+
ctx,
|
|
2348
|
+
query,
|
|
2349
|
+
key,
|
|
2350
|
+
column,
|
|
2351
|
+
quotedAs
|
|
2352
|
+
);
|
|
2308
2353
|
} else if (!column) {
|
|
2309
2354
|
const index = key.indexOf(".");
|
|
2310
2355
|
if (index !== -1) {
|
|
@@ -2312,7 +2357,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2312
2357
|
const quoted = `"${table2}"`;
|
|
2313
2358
|
const name = key.slice(index + 1);
|
|
2314
2359
|
column = quotedAs === quoted ? query.shape[name] : (_b = (_a = query.joinedShapes) == null ? void 0 : _a[table2]) == null ? void 0 : _b[name];
|
|
2315
|
-
quotedColumn = simpleColumnToSQL(ctx, name, column, quoted);
|
|
2360
|
+
quotedColumn = simpleColumnToSQL(ctx, query, name, column, quoted);
|
|
2316
2361
|
} else {
|
|
2317
2362
|
column = (_d = (_c = query.joinedShapes) == null ? void 0 : _c[key]) == null ? void 0 : _d.value;
|
|
2318
2363
|
quotedColumn = `"${key}".r`;
|
|
@@ -2378,25 +2423,25 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
|
|
|
2378
2423
|
ands.push(`${multiple ? `(${columnsSql})` : columnsSql} IN ${value}`);
|
|
2379
2424
|
};
|
|
2380
2425
|
|
|
2381
|
-
var __defProp$
|
|
2382
|
-
var __defProps$
|
|
2383
|
-
var __getOwnPropDescs$
|
|
2384
|
-
var __getOwnPropSymbols$
|
|
2385
|
-
var __hasOwnProp$
|
|
2386
|
-
var __propIsEnum$
|
|
2387
|
-
var __defNormalProp$
|
|
2388
|
-
var __spreadValues$
|
|
2426
|
+
var __defProp$i = Object.defineProperty;
|
|
2427
|
+
var __defProps$9 = Object.defineProperties;
|
|
2428
|
+
var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
|
|
2429
|
+
var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
|
|
2430
|
+
var __hasOwnProp$j = Object.prototype.hasOwnProperty;
|
|
2431
|
+
var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
|
|
2432
|
+
var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2433
|
+
var __spreadValues$i = (a, b) => {
|
|
2389
2434
|
for (var prop in b || (b = {}))
|
|
2390
|
-
if (__hasOwnProp$
|
|
2391
|
-
__defNormalProp$
|
|
2392
|
-
if (__getOwnPropSymbols$
|
|
2393
|
-
for (var prop of __getOwnPropSymbols$
|
|
2394
|
-
if (__propIsEnum$
|
|
2395
|
-
__defNormalProp$
|
|
2435
|
+
if (__hasOwnProp$j.call(b, prop))
|
|
2436
|
+
__defNormalProp$i(a, prop, b[prop]);
|
|
2437
|
+
if (__getOwnPropSymbols$j)
|
|
2438
|
+
for (var prop of __getOwnPropSymbols$j(b)) {
|
|
2439
|
+
if (__propIsEnum$j.call(b, prop))
|
|
2440
|
+
__defNormalProp$i(a, prop, b[prop]);
|
|
2396
2441
|
}
|
|
2397
2442
|
return a;
|
|
2398
2443
|
};
|
|
2399
|
-
var __spreadProps$
|
|
2444
|
+
var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
2400
2445
|
const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
2401
2446
|
let target;
|
|
2402
2447
|
let on;
|
|
@@ -2458,8 +2503,8 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
|
|
|
2458
2503
|
const whereSql = whereToSql(
|
|
2459
2504
|
ctx,
|
|
2460
2505
|
q,
|
|
2461
|
-
__spreadProps$
|
|
2462
|
-
joinedShapes: __spreadProps$
|
|
2506
|
+
__spreadProps$9(__spreadValues$i({}, q.q), {
|
|
2507
|
+
joinedShapes: __spreadProps$9(__spreadValues$i(__spreadValues$i({}, query.joinedShapes), q.q.joinedShapes), {
|
|
2463
2508
|
[table.q.as || table.table]: table.q.shape
|
|
2464
2509
|
})
|
|
2465
2510
|
}),
|
|
@@ -2606,25 +2651,25 @@ const getIsJoinSubQuery = (query) => {
|
|
|
2606
2651
|
return false;
|
|
2607
2652
|
};
|
|
2608
2653
|
|
|
2609
|
-
var __defProp$
|
|
2610
|
-
var __defProps$
|
|
2611
|
-
var __getOwnPropDescs$
|
|
2612
|
-
var __getOwnPropSymbols$
|
|
2613
|
-
var __hasOwnProp$
|
|
2614
|
-
var __propIsEnum$
|
|
2615
|
-
var __defNormalProp$
|
|
2616
|
-
var __spreadValues$
|
|
2654
|
+
var __defProp$h = Object.defineProperty;
|
|
2655
|
+
var __defProps$8 = Object.defineProperties;
|
|
2656
|
+
var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
|
|
2657
|
+
var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
|
|
2658
|
+
var __hasOwnProp$i = Object.prototype.hasOwnProperty;
|
|
2659
|
+
var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
|
|
2660
|
+
var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2661
|
+
var __spreadValues$h = (a, b) => {
|
|
2617
2662
|
for (var prop in b || (b = {}))
|
|
2618
|
-
if (__hasOwnProp$
|
|
2619
|
-
__defNormalProp$
|
|
2620
|
-
if (__getOwnPropSymbols$
|
|
2621
|
-
for (var prop of __getOwnPropSymbols$
|
|
2622
|
-
if (__propIsEnum$
|
|
2623
|
-
__defNormalProp$
|
|
2663
|
+
if (__hasOwnProp$i.call(b, prop))
|
|
2664
|
+
__defNormalProp$h(a, prop, b[prop]);
|
|
2665
|
+
if (__getOwnPropSymbols$i)
|
|
2666
|
+
for (var prop of __getOwnPropSymbols$i(b)) {
|
|
2667
|
+
if (__propIsEnum$i.call(b, prop))
|
|
2668
|
+
__defNormalProp$h(a, prop, b[prop]);
|
|
2624
2669
|
}
|
|
2625
2670
|
return a;
|
|
2626
2671
|
};
|
|
2627
|
-
var __spreadProps$
|
|
2672
|
+
var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
2628
2673
|
const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
|
|
2629
2674
|
var _a;
|
|
2630
2675
|
if (typeof first === "string") {
|
|
@@ -2661,13 +2706,13 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
|
|
|
2661
2706
|
logger: joinToQ.logger
|
|
2662
2707
|
};
|
|
2663
2708
|
j.baseQuery = j;
|
|
2664
|
-
const joinedShapes = __spreadProps$
|
|
2709
|
+
const joinedShapes = __spreadProps$8(__spreadValues$h({}, joinToQ.joinedShapes), {
|
|
2665
2710
|
[joinToQ.as || joinTo.table]: joinTo.shape
|
|
2666
2711
|
});
|
|
2667
2712
|
const r = args[0](
|
|
2668
2713
|
makeJoinQueryBuilder(
|
|
2669
2714
|
j,
|
|
2670
|
-
j.q.joinedShapes ? __spreadValues$
|
|
2715
|
+
j.q.joinedShapes ? __spreadValues$h(__spreadValues$h({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
|
|
2671
2716
|
joinTo
|
|
2672
2717
|
)
|
|
2673
2718
|
);
|
|
@@ -2694,16 +2739,16 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
|
|
|
2694
2739
|
pushQueryArray(q, "or", query.or);
|
|
2695
2740
|
}
|
|
2696
2741
|
if (query.scopes) {
|
|
2697
|
-
q.q.scopes = __spreadValues$
|
|
2742
|
+
q.q.scopes = __spreadValues$h(__spreadValues$h({}, q.q.scopes), query.scopes);
|
|
2698
2743
|
}
|
|
2699
2744
|
}
|
|
2700
|
-
const joinedShapes = __spreadProps$
|
|
2745
|
+
const joinedShapes = __spreadProps$8(__spreadValues$h({}, joinTo.q.joinedShapes), {
|
|
2701
2746
|
[joinTo.q.as || joinTo.table]: joinTo.shape
|
|
2702
2747
|
});
|
|
2703
2748
|
const r = args0(
|
|
2704
2749
|
makeJoinQueryBuilder(
|
|
2705
2750
|
q,
|
|
2706
|
-
q.q.joinedShapes ? __spreadValues$
|
|
2751
|
+
q.q.joinedShapes ? __spreadValues$h(__spreadValues$h({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
|
|
2707
2752
|
joinTo
|
|
2708
2753
|
)
|
|
2709
2754
|
);
|
|
@@ -2751,25 +2796,25 @@ const _queryNone = (q) => {
|
|
|
2751
2796
|
};
|
|
2752
2797
|
const isQueryNone = (q) => q.then === noneMethods.then;
|
|
2753
2798
|
|
|
2754
|
-
var __defProp$
|
|
2755
|
-
var __defProps$
|
|
2756
|
-
var __getOwnPropDescs$
|
|
2757
|
-
var __getOwnPropSymbols$
|
|
2758
|
-
var __hasOwnProp$
|
|
2759
|
-
var __propIsEnum$
|
|
2760
|
-
var __defNormalProp$
|
|
2761
|
-
var __spreadValues$
|
|
2799
|
+
var __defProp$g = Object.defineProperty;
|
|
2800
|
+
var __defProps$7 = Object.defineProperties;
|
|
2801
|
+
var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
|
|
2802
|
+
var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
|
|
2803
|
+
var __hasOwnProp$h = Object.prototype.hasOwnProperty;
|
|
2804
|
+
var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
|
|
2805
|
+
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2806
|
+
var __spreadValues$g = (a, b) => {
|
|
2762
2807
|
for (var prop in b || (b = {}))
|
|
2763
|
-
if (__hasOwnProp$
|
|
2764
|
-
__defNormalProp$
|
|
2765
|
-
if (__getOwnPropSymbols$
|
|
2766
|
-
for (var prop of __getOwnPropSymbols$
|
|
2767
|
-
if (__propIsEnum$
|
|
2768
|
-
__defNormalProp$
|
|
2808
|
+
if (__hasOwnProp$h.call(b, prop))
|
|
2809
|
+
__defNormalProp$g(a, prop, b[prop]);
|
|
2810
|
+
if (__getOwnPropSymbols$h)
|
|
2811
|
+
for (var prop of __getOwnPropSymbols$h(b)) {
|
|
2812
|
+
if (__propIsEnum$h.call(b, prop))
|
|
2813
|
+
__defNormalProp$g(a, prop, b[prop]);
|
|
2769
2814
|
}
|
|
2770
2815
|
return a;
|
|
2771
2816
|
};
|
|
2772
|
-
var __spreadProps$
|
|
2817
|
+
var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
2773
2818
|
const _join = (query, require2, type, first, args) => {
|
|
2774
2819
|
var _a, _b, _c, _d;
|
|
2775
2820
|
let joinKey;
|
|
@@ -2814,7 +2859,7 @@ const _join = (query, require2, type, first, args) => {
|
|
|
2814
2859
|
computeds = w == null ? void 0 : w.computeds;
|
|
2815
2860
|
if (shape) {
|
|
2816
2861
|
if (!require2)
|
|
2817
|
-
shape = __spreadValues$
|
|
2862
|
+
shape = __spreadValues$g({}, shape);
|
|
2818
2863
|
parsers = {};
|
|
2819
2864
|
for (const key in shape) {
|
|
2820
2865
|
const parser = shape[key].parseFn;
|
|
@@ -2914,7 +2959,7 @@ const _joinLateral = (self, type, arg, cb, as) => {
|
|
|
2914
2959
|
t.table = arg;
|
|
2915
2960
|
t.shape = w.shape;
|
|
2916
2961
|
t.computeds = w.computeds;
|
|
2917
|
-
t.q = __spreadProps$
|
|
2962
|
+
t.q = __spreadProps$7(__spreadValues$g({}, t.q), {
|
|
2918
2963
|
shape: w.shape
|
|
2919
2964
|
});
|
|
2920
2965
|
t.baseQuery = t;
|
|
@@ -3233,12 +3278,46 @@ class QueryLog {
|
|
|
3233
3278
|
}
|
|
3234
3279
|
}
|
|
3235
3280
|
|
|
3281
|
+
var __defProp$f = Object.defineProperty;
|
|
3282
|
+
var __defProps$6 = Object.defineProperties;
|
|
3283
|
+
var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
|
|
3284
|
+
var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
|
|
3285
|
+
var __hasOwnProp$g = Object.prototype.hasOwnProperty;
|
|
3286
|
+
var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
|
|
3287
|
+
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3288
|
+
var __spreadValues$f = (a, b) => {
|
|
3289
|
+
for (var prop in b || (b = {}))
|
|
3290
|
+
if (__hasOwnProp$g.call(b, prop))
|
|
3291
|
+
__defNormalProp$f(a, prop, b[prop]);
|
|
3292
|
+
if (__getOwnPropSymbols$g)
|
|
3293
|
+
for (var prop of __getOwnPropSymbols$g(b)) {
|
|
3294
|
+
if (__propIsEnum$g.call(b, prop))
|
|
3295
|
+
__defNormalProp$f(a, prop, b[prop]);
|
|
3296
|
+
}
|
|
3297
|
+
return a;
|
|
3298
|
+
};
|
|
3299
|
+
var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
3236
3300
|
const commitSql$1 = {
|
|
3237
3301
|
text: "COMMIT"
|
|
3238
3302
|
};
|
|
3239
3303
|
const rollbackSql$1 = {
|
|
3240
3304
|
text: "ROLLBACK"
|
|
3241
3305
|
};
|
|
3306
|
+
class AfterCommitError extends OrchidOrmError {
|
|
3307
|
+
constructor(result, hookResults) {
|
|
3308
|
+
super("After commit hooks have failed");
|
|
3309
|
+
this.result = result;
|
|
3310
|
+
this.hookResults = hookResults;
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
const _afterCommitError = (result, hookResults, catchAfterCommitError) => {
|
|
3314
|
+
const err = new AfterCommitError(result, hookResults);
|
|
3315
|
+
if (catchAfterCommitError) {
|
|
3316
|
+
catchAfterCommitError(err);
|
|
3317
|
+
} else {
|
|
3318
|
+
throw err;
|
|
3319
|
+
}
|
|
3320
|
+
};
|
|
3242
3321
|
class Transaction {
|
|
3243
3322
|
async transaction(cbOrOptions, cb) {
|
|
3244
3323
|
var _a;
|
|
@@ -3284,7 +3363,10 @@ class Transaction {
|
|
|
3284
3363
|
const result = await this.q.adapter.transaction(sql, callback);
|
|
3285
3364
|
if (log)
|
|
3286
3365
|
log.afterQuery(commitSql$1, logData);
|
|
3287
|
-
await runAfterCommit(
|
|
3366
|
+
await runAfterCommit(
|
|
3367
|
+
trx.afterCommit,
|
|
3368
|
+
result
|
|
3369
|
+
);
|
|
3288
3370
|
return result;
|
|
3289
3371
|
} catch (err) {
|
|
3290
3372
|
if (log)
|
|
@@ -3318,7 +3400,8 @@ class Transaction {
|
|
|
3318
3400
|
log.afterQuery(sql, logData);
|
|
3319
3401
|
if (transactionId === trx.testTransactionCount) {
|
|
3320
3402
|
await runAfterCommit(
|
|
3321
|
-
trx.afterCommit
|
|
3403
|
+
trx.afterCommit,
|
|
3404
|
+
result
|
|
3322
3405
|
);
|
|
3323
3406
|
}
|
|
3324
3407
|
return result;
|
|
@@ -3328,17 +3411,37 @@ class Transaction {
|
|
|
3328
3411
|
}
|
|
3329
3412
|
}
|
|
3330
3413
|
}
|
|
3331
|
-
const runAfterCommit = async (afterCommit) => {
|
|
3414
|
+
const runAfterCommit = async (afterCommit, result) => {
|
|
3332
3415
|
if (afterCommit) {
|
|
3333
3416
|
const promises = [];
|
|
3417
|
+
let catchAfterCommitError;
|
|
3334
3418
|
for (let i = 0, len = afterCommit.length; i < len; i += 3) {
|
|
3335
|
-
const
|
|
3419
|
+
const result2 = afterCommit[i];
|
|
3336
3420
|
const q = afterCommit[i + 1];
|
|
3421
|
+
if (q.q.catchAfterCommitError) {
|
|
3422
|
+
catchAfterCommitError = q.q.catchAfterCommitError;
|
|
3423
|
+
}
|
|
3337
3424
|
for (const fn of afterCommit[i + 2]) {
|
|
3338
|
-
|
|
3425
|
+
try {
|
|
3426
|
+
promises.push(fn(result2, q));
|
|
3427
|
+
} catch (err) {
|
|
3428
|
+
promises.push(Promise.reject(err));
|
|
3429
|
+
}
|
|
3339
3430
|
}
|
|
3340
3431
|
}
|
|
3341
|
-
await Promise.
|
|
3432
|
+
const hookResults = await Promise.allSettled(promises);
|
|
3433
|
+
if (hookResults.some((result2) => result2.status === "rejected")) {
|
|
3434
|
+
const resultsWithNames = [];
|
|
3435
|
+
let r = 0;
|
|
3436
|
+
for (let i = 0, len = afterCommit.length; i < len; i += 3) {
|
|
3437
|
+
for (const fn of afterCommit[i + 2]) {
|
|
3438
|
+
resultsWithNames.push(__spreadProps$6(__spreadValues$f({}, hookResults[r++]), {
|
|
3439
|
+
name: fn.name
|
|
3440
|
+
}));
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
_afterCommitError(result, resultsWithNames, catchAfterCommitError);
|
|
3444
|
+
}
|
|
3342
3445
|
}
|
|
3343
3446
|
};
|
|
3344
3447
|
|
|
@@ -3395,8 +3498,8 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
|
|
|
3395
3498
|
};
|
|
3396
3499
|
|
|
3397
3500
|
var __defProp$e = Object.defineProperty;
|
|
3398
|
-
var __defProps$
|
|
3399
|
-
var __getOwnPropDescs$
|
|
3501
|
+
var __defProps$5 = Object.defineProperties;
|
|
3502
|
+
var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
|
|
3400
3503
|
var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
|
|
3401
3504
|
var __hasOwnProp$f = Object.prototype.hasOwnProperty;
|
|
3402
3505
|
var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
|
|
@@ -3412,7 +3515,7 @@ var __spreadValues$e = (a, b) => {
|
|
|
3412
3515
|
}
|
|
3413
3516
|
return a;
|
|
3414
3517
|
};
|
|
3415
|
-
var __spreadProps$
|
|
3518
|
+
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
3416
3519
|
class ComputedColumn {
|
|
3417
3520
|
constructor(kind, deps, fn) {
|
|
3418
3521
|
this.kind = kind;
|
|
@@ -3429,7 +3532,7 @@ const applyComputedColumns = (q, fn) => {
|
|
|
3429
3532
|
for (const key in computed) {
|
|
3430
3533
|
const item = computed[key];
|
|
3431
3534
|
if (item instanceof ComputedColumn) {
|
|
3432
|
-
q.q.computeds = __spreadProps$
|
|
3535
|
+
q.q.computeds = __spreadProps$5(__spreadValues$e({}, q.q.computeds), { [key]: item });
|
|
3433
3536
|
} else {
|
|
3434
3537
|
(q.shape[key] = item.result.value || UnknownColumn.instance).data.computed = item;
|
|
3435
3538
|
}
|
|
@@ -3538,6 +3641,8 @@ const saveBatchComputed = (key, result, res, blanks) => {
|
|
|
3538
3641
|
};
|
|
3539
3642
|
|
|
3540
3643
|
var __defProp$d = Object.defineProperty;
|
|
3644
|
+
var __defProps$4 = Object.defineProperties;
|
|
3645
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
3541
3646
|
var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
|
|
3542
3647
|
var __hasOwnProp$e = Object.prototype.hasOwnProperty;
|
|
3543
3648
|
var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
|
|
@@ -3553,6 +3658,7 @@ var __spreadValues$d = (a, b) => {
|
|
|
3553
3658
|
}
|
|
3554
3659
|
return a;
|
|
3555
3660
|
};
|
|
3661
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
3556
3662
|
const queryMethodByReturnType = {
|
|
3557
3663
|
undefined: "query",
|
|
3558
3664
|
all: "query",
|
|
@@ -3773,15 +3879,35 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
3773
3879
|
)
|
|
3774
3880
|
);
|
|
3775
3881
|
}
|
|
3776
|
-
if (afterCommitHooks
|
|
3777
|
-
(
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3882
|
+
if (afterCommitHooks) {
|
|
3883
|
+
if (trx) {
|
|
3884
|
+
((_c = trx.afterCommit) != null ? _c : trx.afterCommit = []).push(
|
|
3885
|
+
result,
|
|
3886
|
+
q,
|
|
3887
|
+
afterCommitHooks
|
|
3888
|
+
);
|
|
3889
|
+
} else {
|
|
3890
|
+
const promises = [];
|
|
3891
|
+
for (const fn of afterCommitHooks) {
|
|
3892
|
+
try {
|
|
3893
|
+
promises.push(
|
|
3894
|
+
fn(result, q)
|
|
3895
|
+
);
|
|
3896
|
+
} catch (err) {
|
|
3897
|
+
promises.push(Promise.reject(err));
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
const hookResults = await Promise.allSettled(promises);
|
|
3901
|
+
if (hookResults.some((result2) => result2.status === "rejected")) {
|
|
3902
|
+
_afterCommitError(
|
|
3903
|
+
result,
|
|
3904
|
+
hookResults.map((result2, i) => __spreadProps$4(__spreadValues$d({}, result2), {
|
|
3905
|
+
name: afterCommitHooks[i].name
|
|
3906
|
+
})),
|
|
3907
|
+
q.q.catchAfterCommitError
|
|
3908
|
+
);
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3785
3911
|
}
|
|
3786
3912
|
} else if (query.after) {
|
|
3787
3913
|
const args = [result, q];
|
|
@@ -4847,13 +4973,21 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
|
|
|
4847
4973
|
item,
|
|
4848
4974
|
tableName,
|
|
4849
4975
|
key,
|
|
4976
|
+
key === "*" ? tableName : key,
|
|
4850
4977
|
quotedAs,
|
|
4851
4978
|
true
|
|
4852
4979
|
);
|
|
4853
4980
|
} else {
|
|
4854
4981
|
if (hookSelect == null ? void 0 : hookSelect.get(item))
|
|
4855
4982
|
(selected != null ? selected : selected = {})[item] = quotedAs;
|
|
4856
|
-
sql = ownColumnToSqlWithAs(
|
|
4983
|
+
sql = ownColumnToSqlWithAs(
|
|
4984
|
+
ctx,
|
|
4985
|
+
table.q,
|
|
4986
|
+
item,
|
|
4987
|
+
item,
|
|
4988
|
+
quotedAs,
|
|
4989
|
+
true
|
|
4990
|
+
);
|
|
4857
4991
|
}
|
|
4858
4992
|
}
|
|
4859
4993
|
list.push(sql);
|
|
@@ -4872,14 +5006,14 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
|
|
|
4872
5006
|
}
|
|
4873
5007
|
} else if (value) {
|
|
4874
5008
|
list.push(
|
|
4875
|
-
|
|
5009
|
+
columnToSqlWithAs(
|
|
4876
5010
|
ctx,
|
|
4877
5011
|
table.q,
|
|
4878
|
-
table.q.shape,
|
|
4879
5012
|
value,
|
|
5013
|
+
as,
|
|
4880
5014
|
quotedAs,
|
|
4881
5015
|
true
|
|
4882
|
-
)
|
|
5016
|
+
)
|
|
4883
5017
|
);
|
|
4884
5018
|
}
|
|
4885
5019
|
}
|
|
@@ -4908,7 +5042,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
|
|
|
4908
5042
|
quotedTable = quotedAs;
|
|
4909
5043
|
columnName = select;
|
|
4910
5044
|
col = query.shape[select];
|
|
4911
|
-
sql = simpleColumnToSQL(ctx, select, col, quotedAs);
|
|
5045
|
+
sql = simpleColumnToSQL(ctx, query, select, col, quotedAs);
|
|
4912
5046
|
}
|
|
4913
5047
|
if (selected == null ? void 0 : selected[columnName]) {
|
|
4914
5048
|
if ((selected == null ? void 0 : selected[columnName]) === quotedTable) {
|
|
@@ -8389,6 +8523,32 @@ class QueryHooks {
|
|
|
8389
8523
|
cb
|
|
8390
8524
|
);
|
|
8391
8525
|
}
|
|
8526
|
+
/**
|
|
8527
|
+
* Add `catchAfterCommitError` to the query to catch possible errors that are coming from after commit hooks.
|
|
8528
|
+
*
|
|
8529
|
+
* When it is used, the transaction will return its result disregarding of a failed hook.
|
|
8530
|
+
*
|
|
8531
|
+
* Without `catchAfterCommitError`, the transaction function throws and won't return result.
|
|
8532
|
+
* Result is still accessible from the error object [AfterCommitError](#AfterCommitError).
|
|
8533
|
+
*
|
|
8534
|
+
* ```ts
|
|
8535
|
+
* const result = await db
|
|
8536
|
+
* .$transaction(async () => {
|
|
8537
|
+
* return db.table.create(data);
|
|
8538
|
+
* })
|
|
8539
|
+
* .catchAfterCommitError((err) => {
|
|
8540
|
+
* // err is instance of AfterCommitError (see below)
|
|
8541
|
+
* });
|
|
8542
|
+
*
|
|
8543
|
+
* // result is available even if an after commit hook has failed
|
|
8544
|
+
* result.id;
|
|
8545
|
+
* ```
|
|
8546
|
+
*/
|
|
8547
|
+
catchAfterCommitError(fn) {
|
|
8548
|
+
const q = this.clone();
|
|
8549
|
+
q.q.catchAfterCommitError = fn;
|
|
8550
|
+
return q;
|
|
8551
|
+
}
|
|
8392
8552
|
}
|
|
8393
8553
|
|
|
8394
8554
|
class Join {
|
|
@@ -11377,6 +11537,8 @@ class ColumnRefExpression extends Expression {
|
|
|
11377
11537
|
makeSQL(ctx, quotedAs) {
|
|
11378
11538
|
return simpleExistingColumnToSQL(
|
|
11379
11539
|
ctx,
|
|
11540
|
+
// it's for parsers for computed SQL. In the column ref case, parsers should be set when selecting the column ref.
|
|
11541
|
+
{},
|
|
11380
11542
|
this.name,
|
|
11381
11543
|
this.result.value,
|
|
11382
11544
|
quotedAs
|
|
@@ -12841,5 +13003,5 @@ function copyTableData(query, arg) {
|
|
|
12841
13003
|
return q;
|
|
12842
13004
|
}
|
|
12843
13005
|
|
|
12844
|
-
export { Adapter, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
13006
|
+
export { Adapter, AfterCommitError, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _afterCommitError, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
12845
13007
|
//# sourceMappingURL=index.mjs.map
|