pqb 0.40.10 → 0.40.11
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 +10 -2
- package/dist/index.js +91 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1775,8 +1775,24 @@ const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
|
|
|
1775
1775
|
const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select) => {
|
|
1776
1776
|
var _a, _b, _c;
|
|
1777
1777
|
if (key === "*") {
|
|
1778
|
-
|
|
1779
|
-
|
|
1778
|
+
const shape = (_a = data.joinedShapes) == null ? void 0 : _a[table];
|
|
1779
|
+
if (shape) {
|
|
1780
|
+
if (select) {
|
|
1781
|
+
let isSimple = true;
|
|
1782
|
+
const list = [];
|
|
1783
|
+
for (const key2 in shape) {
|
|
1784
|
+
const column2 = shape[key2];
|
|
1785
|
+
if (column2.data.explicitSelect || column2 instanceof VirtualColumn) {
|
|
1786
|
+
continue;
|
|
1787
|
+
}
|
|
1788
|
+
if (column2.data.name) {
|
|
1789
|
+
isSimple = false;
|
|
1790
|
+
}
|
|
1791
|
+
list.push(`'${key2}'`, `"${table}"."${column2.data.name || key2}"`);
|
|
1792
|
+
}
|
|
1793
|
+
return (isSimple ? `row_to_json("${table}".*)` : "json_build_object(" + list.join(", ") + ")") + ` "${as}"`;
|
|
1794
|
+
}
|
|
1795
|
+
return `"${table}".r "${as}"`;
|
|
1780
1796
|
}
|
|
1781
1797
|
return column;
|
|
1782
1798
|
}
|
|
@@ -1896,8 +1912,10 @@ class QueryError extends OrchidOrmInternalError {
|
|
|
1896
1912
|
const list = (_a = this.detail.match(/\((.*)\)=/)) == null ? void 0 : _a[1];
|
|
1897
1913
|
if (list) {
|
|
1898
1914
|
list.split(", ").forEach((item) => {
|
|
1915
|
+
var _a2;
|
|
1899
1916
|
const column = item.startsWith('"') ? item.slice(1, -1) : item;
|
|
1900
|
-
|
|
1917
|
+
const key = (_a2 = this.query.columnNameToKey(column)) != null ? _a2 : column;
|
|
1918
|
+
columns[key] = true;
|
|
1901
1919
|
});
|
|
1902
1920
|
}
|
|
1903
1921
|
}
|
|
@@ -1947,6 +1965,17 @@ const throwIfNoWhere = (q, method) => {
|
|
|
1947
1965
|
);
|
|
1948
1966
|
}
|
|
1949
1967
|
};
|
|
1968
|
+
const throwIfJoinLateral = (q, method) => {
|
|
1969
|
+
var _a;
|
|
1970
|
+
if ((_a = q.q.join) == null ? void 0 : _a.some(
|
|
1971
|
+
(x) => Array.isArray(x) || "s" in x.args && x.args.s
|
|
1972
|
+
)) {
|
|
1973
|
+
throw new OrchidOrmInternalError(
|
|
1974
|
+
q,
|
|
1975
|
+
`Cannot join a complex query in ${method}`
|
|
1976
|
+
);
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1950
1979
|
const saveSearchAlias = (q, as, key) => {
|
|
1951
1980
|
const shapes = q.q[key];
|
|
1952
1981
|
if (shapes == null ? void 0 : shapes[as]) {
|
|
@@ -2650,16 +2679,16 @@ const _join = (query, require2, type, first, args) => {
|
|
|
2650
2679
|
if (require2 && isQueryNone(first)) {
|
|
2651
2680
|
return _queryNone(query);
|
|
2652
2681
|
}
|
|
2653
|
-
const
|
|
2654
|
-
joinSubQuery = getIsJoinSubQuery(
|
|
2655
|
-
joinKey =
|
|
2682
|
+
const q2 = first;
|
|
2683
|
+
joinSubQuery = getIsJoinSubQuery(q2);
|
|
2684
|
+
joinKey = q2.q.as || q2.table;
|
|
2656
2685
|
if (joinKey) {
|
|
2657
|
-
shape = getShapeFromSelect(
|
|
2658
|
-
parsers =
|
|
2659
|
-
batchParsers =
|
|
2660
|
-
computeds =
|
|
2686
|
+
shape = getShapeFromSelect(q2, joinSubQuery && !!q2.q.select);
|
|
2687
|
+
parsers = q2.q.parsers;
|
|
2688
|
+
batchParsers = q2.q.batchParsers;
|
|
2689
|
+
computeds = q2.q.computeds;
|
|
2661
2690
|
if (joinSubQuery) {
|
|
2662
|
-
first =
|
|
2691
|
+
first = q2.clone();
|
|
2663
2692
|
first.shape = shape;
|
|
2664
2693
|
}
|
|
2665
2694
|
}
|
|
@@ -2742,10 +2771,14 @@ const _join = (query, require2, type, first, args) => {
|
|
|
2742
2771
|
computeds
|
|
2743
2772
|
);
|
|
2744
2773
|
}
|
|
2745
|
-
|
|
2774
|
+
const q = pushQueryValue(query, "join", {
|
|
2746
2775
|
type,
|
|
2747
2776
|
args: joinArgs
|
|
2748
2777
|
});
|
|
2778
|
+
if (query.q.type === "delete") {
|
|
2779
|
+
throwIfJoinLateral(q, query.q.type);
|
|
2780
|
+
}
|
|
2781
|
+
return q;
|
|
2749
2782
|
};
|
|
2750
2783
|
const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, computeds) => {
|
|
2751
2784
|
var _a, _b;
|
|
@@ -3549,7 +3582,9 @@ const applyComputedColumns = (q, fn) => {
|
|
|
3549
3582
|
if (item instanceof ComputedColumn) {
|
|
3550
3583
|
q.q.computeds = __spreadProps$5(__spreadValues$e({}, q.q.computeds), { [key]: item });
|
|
3551
3584
|
} else {
|
|
3552
|
-
(q.shape[key] = item.result.value || UnknownColumn.instance).data
|
|
3585
|
+
const data = (q.shape[key] = item.result.value || UnknownColumn.instance).data;
|
|
3586
|
+
data.computed = item;
|
|
3587
|
+
data.explicitSelect = true;
|
|
3553
3588
|
}
|
|
3554
3589
|
}
|
|
3555
3590
|
q.computeAtRuntime = q.computeBatchAtRuntime = void 0;
|
|
@@ -3964,6 +3999,16 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
3964
3999
|
error.cause = localError;
|
|
3965
4000
|
}
|
|
3966
4001
|
}
|
|
4002
|
+
const stack = localError.stack;
|
|
4003
|
+
if (stack) {
|
|
4004
|
+
const from = stack.indexOf("\n");
|
|
4005
|
+
if (from !== -1) {
|
|
4006
|
+
const to = stack.indexOf("\n", from + 1);
|
|
4007
|
+
if (to !== -1) {
|
|
4008
|
+
localError.stack = stack.slice(0, from) + stack.slice(to);
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
3967
4012
|
if (log && sql) {
|
|
3968
4013
|
log.onError(error, sql, logData);
|
|
3969
4014
|
}
|
|
@@ -5775,7 +5820,7 @@ const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
|
|
|
5775
5820
|
};
|
|
5776
5821
|
|
|
5777
5822
|
const pushDeleteSql = (ctx, table, query, quotedAs) => {
|
|
5778
|
-
var _a, _b, _c
|
|
5823
|
+
var _a, _b, _c;
|
|
5779
5824
|
const from = `"${table.table}"`;
|
|
5780
5825
|
ctx.sql.push(`DELETE FROM ${from}`);
|
|
5781
5826
|
if (from !== quotedAs) {
|
|
@@ -5787,27 +5832,16 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
|
|
|
5787
5832
|
const ons = [];
|
|
5788
5833
|
const joinSet = query.join.length > 1 ? /* @__PURE__ */ new Set() : null;
|
|
5789
5834
|
for (const item of query.join) {
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
`LATERAL (${getSqlText(q.toSQL(ctx))}) "${((_b = query.joinOverrides) == null ? void 0 : _b[as]) || as}"`
|
|
5797
|
-
);
|
|
5798
|
-
ctx.aliasValue = aliasValue;
|
|
5799
|
-
} else {
|
|
5800
|
-
const join = processJoinItem(ctx, table, query, item.args, quotedAs);
|
|
5801
|
-
const key = `${join.target}${join.on}`;
|
|
5802
|
-
if (joinSet) {
|
|
5803
|
-
if (joinSet.has(key))
|
|
5804
|
-
continue;
|
|
5805
|
-
joinSet.add(key);
|
|
5806
|
-
}
|
|
5807
|
-
targets.push(join.target);
|
|
5808
|
-
if (join.on)
|
|
5809
|
-
ons.push(join.on);
|
|
5835
|
+
const join = processJoinItem(ctx, table, query, item.args, quotedAs);
|
|
5836
|
+
const key = `${join.target}${join.on}`;
|
|
5837
|
+
if (joinSet) {
|
|
5838
|
+
if (joinSet.has(key))
|
|
5839
|
+
continue;
|
|
5840
|
+
joinSet.add(key);
|
|
5810
5841
|
}
|
|
5842
|
+
targets.push(join.target);
|
|
5843
|
+
if (join.on)
|
|
5844
|
+
ons.push(join.on);
|
|
5811
5845
|
}
|
|
5812
5846
|
if (targets.length) {
|
|
5813
5847
|
ctx.sql.push(`USING ${targets.join(", ")}`);
|
|
@@ -5816,7 +5850,7 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
|
|
|
5816
5850
|
}
|
|
5817
5851
|
pushWhereStatementSql(ctx, table, query, quotedAs);
|
|
5818
5852
|
if (conditions) {
|
|
5819
|
-
if (((
|
|
5853
|
+
if (((_b = query.and) == null ? void 0 : _b.length) || ((_c = query.or) == null ? void 0 : _c.length) || query.scopes) {
|
|
5820
5854
|
ctx.sql.push("AND", conditions);
|
|
5821
5855
|
} else {
|
|
5822
5856
|
ctx.sql.push("WHERE", conditions);
|
|
@@ -8196,6 +8230,7 @@ const _queryDelete = (query) => {
|
|
|
8196
8230
|
q.returnType = "rowCount";
|
|
8197
8231
|
}
|
|
8198
8232
|
throwIfNoWhere(query, "delete");
|
|
8233
|
+
throwIfJoinLateral(query, "delete");
|
|
8199
8234
|
q.type = "delete";
|
|
8200
8235
|
return query;
|
|
8201
8236
|
};
|
|
@@ -12784,16 +12819,18 @@ class Db {
|
|
|
12784
12819
|
applyComputedColumns(this, options.computed);
|
|
12785
12820
|
if (prepareSelectAll) {
|
|
12786
12821
|
const list = [];
|
|
12822
|
+
const keys = {};
|
|
12787
12823
|
for (const key in shape) {
|
|
12788
12824
|
const column = shape[key];
|
|
12789
12825
|
if (!column.data.explicitSelect) {
|
|
12790
12826
|
list.push(
|
|
12791
12827
|
column.data.name ? `"${column.data.name}" AS "${key}"` : `"${key}"`
|
|
12792
12828
|
);
|
|
12829
|
+
keys[key] = column;
|
|
12793
12830
|
}
|
|
12794
12831
|
}
|
|
12795
12832
|
this.q.selectAllColumns = list;
|
|
12796
|
-
this.q.selectAllKeys =
|
|
12833
|
+
this.q.selectAllKeys = keys;
|
|
12797
12834
|
}
|
|
12798
12835
|
if (modifyQuery) {
|
|
12799
12836
|
for (const cb of modifyQuery) {
|
|
@@ -12886,6 +12923,23 @@ class Db {
|
|
|
12886
12923
|
queryArrays(...args) {
|
|
12887
12924
|
return performQuery(this, args, "arrays");
|
|
12888
12925
|
}
|
|
12926
|
+
/**
|
|
12927
|
+
* In snake case mode, or when columns have custom names,
|
|
12928
|
+
* use this method to exchange a db column name to its runtime key.
|
|
12929
|
+
*/
|
|
12930
|
+
columnNameToKey(name) {
|
|
12931
|
+
var _a;
|
|
12932
|
+
let map = this.internal.columnNameToKeyMap;
|
|
12933
|
+
if (!map) {
|
|
12934
|
+
this.internal.columnNameToKeyMap = map = /* @__PURE__ */ new Map();
|
|
12935
|
+
const { shape } = this;
|
|
12936
|
+
for (const key in this.shape) {
|
|
12937
|
+
const column = shape[key];
|
|
12938
|
+
map.set((_a = column.data.name) != null ? _a : key, key);
|
|
12939
|
+
}
|
|
12940
|
+
}
|
|
12941
|
+
return map.get(name);
|
|
12942
|
+
}
|
|
12889
12943
|
}
|
|
12890
12944
|
const performQuery = async (q, args, method) => {
|
|
12891
12945
|
var _a;
|
|
@@ -13145,5 +13199,5 @@ function copyTableData(query, arg) {
|
|
|
13145
13199
|
return q;
|
|
13146
13200
|
}
|
|
13147
13201
|
|
|
13148
|
-
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, PostgisGeographyPointColumn, 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, escapeForLog, escapeForMigration, escapeString, 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, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
13202
|
+
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, PostgisGeographyPointColumn, 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, escapeForLog, escapeForMigration, escapeString, 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, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
13149
13203
|
//# sourceMappingURL=index.mjs.map
|