pqb 0.67.2 → 0.67.4
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 +25 -3
- package/dist/index.js +113 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -24
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +46 -25
- package/dist/internal.js +6 -0
- package/dist/internal.mjs +2 -2
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -748,6 +748,15 @@ var Column = class {
|
|
|
748
748
|
return setColumnData(this, "explicitSelect", !value);
|
|
749
749
|
}
|
|
750
750
|
/**
|
|
751
|
+
* Set SQL to use when selecting this column.
|
|
752
|
+
*
|
|
753
|
+
* The column remains a regular writable database column. Create, update,
|
|
754
|
+
* filters, ordering, grouping, and migrations still use the physical column.
|
|
755
|
+
*/
|
|
756
|
+
selectSql(fn) {
|
|
757
|
+
return setColumnData(this, "selectSqlFn", fn);
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
751
760
|
* Forbid the column to be used in [create](/guide/create-update-delete.html#create-insert) and [update](/guide/create-update-delete.html#update) methods.
|
|
752
761
|
*
|
|
753
762
|
* `readOnly` column is still can be set from a [hook](http://localhost:5173/guide/hooks.html#set-values-before-create-or-update).
|
|
@@ -3969,6 +3978,7 @@ const applyComputedColumns = (q, fn) => {
|
|
|
3969
3978
|
q.shape[key] = col;
|
|
3970
3979
|
const { data } = col;
|
|
3971
3980
|
data.computed = item;
|
|
3981
|
+
data.selectSql = item;
|
|
3972
3982
|
data.explicitSelect = true;
|
|
3973
3983
|
data.readOnly = true;
|
|
3974
3984
|
const parse = col._parse;
|
|
@@ -4540,7 +4550,11 @@ const loadRelations = async (state, result, savepointState, renames) => {
|
|
|
4540
4550
|
const q = state.query;
|
|
4541
4551
|
const primaryKeys = requirePrimaryKeys(q, "Cannot select a relation of a table that has no primary keys");
|
|
4542
4552
|
const selectQuery = _unscope(q, "nonDeleted");
|
|
4543
|
-
selectQuery.q.type =
|
|
4553
|
+
selectQuery.q.type = void 0;
|
|
4554
|
+
selectQuery.q.returnType = void 0;
|
|
4555
|
+
selectQuery.q.with = void 0;
|
|
4556
|
+
selectQuery.q.appendQueries = void 0;
|
|
4557
|
+
selectQuery.q.valuesJoinedAs = void 0;
|
|
4544
4558
|
const matchSourceTableIds = {};
|
|
4545
4559
|
for (const pkey of primaryKeys) matchSourceTableIds[pkey] = { in: result.map((row) => row[pkey]) };
|
|
4546
4560
|
(selectQuery.q.and ??= []).push(matchSourceTableIds);
|
|
@@ -6500,6 +6514,15 @@ const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
|
6500
6514
|
if (index !== -1) return columnWithDotToSql(ctx, data, shape, column, index, quotedAs, select);
|
|
6501
6515
|
return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
|
|
6502
6516
|
};
|
|
6517
|
+
const selectedColumnToSql = (ctx, data, shape, column, quotedAs) => {
|
|
6518
|
+
const index = column.indexOf(".");
|
|
6519
|
+
return index !== -1 ? selectedColumnWithDotToSql(ctx, data, shape, column, index, quotedAs) : selectedSimpleColumnToSql(ctx, column, shape[column], quotedAs);
|
|
6520
|
+
};
|
|
6521
|
+
const selectedSimpleColumnToSql = (ctx, key, column, quotedAs) => {
|
|
6522
|
+
if (!column) return `"${key}"`;
|
|
6523
|
+
const { data } = column;
|
|
6524
|
+
return data.selectSql ? `(${data.selectSql.toSQL(ctx, quotedAs)})` : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
6525
|
+
};
|
|
6503
6526
|
/**
|
|
6504
6527
|
* in a case when ordering or grouping by a column which was selected as expression:
|
|
6505
6528
|
* ```ts
|
|
@@ -6525,7 +6548,7 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
6525
6548
|
const key = column.slice(index + 1);
|
|
6526
6549
|
if (key === "*") {
|
|
6527
6550
|
const shape = data.joinedShapes?.[table];
|
|
6528
|
-
return shape ? select ? makeRowToJson(table, shape, true) : `"${table}".*` : column;
|
|
6551
|
+
return shape ? select ? makeRowToJson(ctx, table, shape, true) : `"${table}".*` : column;
|
|
6529
6552
|
}
|
|
6530
6553
|
const tableName = _getQueryAliasOrName(data, table);
|
|
6531
6554
|
const quoted = `"${table}"`;
|
|
@@ -6537,6 +6560,22 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
6537
6560
|
}
|
|
6538
6561
|
return `"${tableName}"."${key}"`;
|
|
6539
6562
|
};
|
|
6563
|
+
const selectedColumnWithDotToSql = (ctx, data, shape, column, index, quotedAs) => {
|
|
6564
|
+
const table = column.slice(0, index);
|
|
6565
|
+
const key = column.slice(index + 1);
|
|
6566
|
+
if (key === "*") {
|
|
6567
|
+
const shape = data.joinedShapes?.[table];
|
|
6568
|
+
return shape ? makeRowToJson(ctx, table, shape, true) : column;
|
|
6569
|
+
}
|
|
6570
|
+
const tableName = _getQueryAliasOrName(data, table);
|
|
6571
|
+
const quoted = `"${table}"`;
|
|
6572
|
+
const col = quoted === quotedAs ? shape[key] : data.joinedShapes?.[tableName]?.[key];
|
|
6573
|
+
if (col) {
|
|
6574
|
+
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quoted)})`;
|
|
6575
|
+
if (col.data.name) return `"${tableName}"."${col.data.name}"`;
|
|
6576
|
+
}
|
|
6577
|
+
return `"${tableName}"."${key}"`;
|
|
6578
|
+
};
|
|
6540
6579
|
const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select, jsonList) => {
|
|
6541
6580
|
const index = column.indexOf(".");
|
|
6542
6581
|
return index !== -1 ? tableColumnToSqlWithAs(ctx, data, column, column.slice(0, index), column.slice(index + 1), as, quotedAs, select, jsonList) : ownColumnToSqlWithAs(ctx, data, column, as, quotedAs, select, jsonList);
|
|
@@ -6546,7 +6585,7 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
|
|
|
6546
6585
|
if (jsonList) jsonList[as] = void 0;
|
|
6547
6586
|
const shape = data.joinedShapes?.[table];
|
|
6548
6587
|
if (shape) {
|
|
6549
|
-
if (select) return makeRowToJson(table, shape, true) + ` "${as}"`;
|
|
6588
|
+
if (select) return makeRowToJson(ctx, table, shape, true) + ` "${as}"`;
|
|
6550
6589
|
return `"${table}"."${table}" "${as}"`;
|
|
6551
6590
|
}
|
|
6552
6591
|
return column;
|
|
@@ -6554,10 +6593,10 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
|
|
|
6554
6593
|
const tableName = _getQueryAliasOrName(data, table);
|
|
6555
6594
|
const quoted = `"${table}"`;
|
|
6556
6595
|
const col = quoted === quotedAs ? data.shape[key] : data.joinedShapes?.[tableName][key];
|
|
6557
|
-
if (jsonList) jsonList[as] = col;
|
|
6596
|
+
if (jsonList) jsonList[as] = col && getSelectedColumnData(col);
|
|
6558
6597
|
if (col) {
|
|
6598
|
+
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quoted)}) "${as}"`;
|
|
6559
6599
|
if (col.data.name && col.data.name !== key) return `"${tableName}"."${col.data.name}" "${as}"`;
|
|
6560
|
-
if (col.data.computed) return `(${col.data.computed.toSQL(ctx, quoted)}) "${as}"`;
|
|
6561
6600
|
}
|
|
6562
6601
|
return `"${tableName}"."${key}"${key === as ? "" : ` "${as}"`}`;
|
|
6563
6602
|
};
|
|
@@ -6567,10 +6606,10 @@ const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select, jsonList)
|
|
|
6567
6606
|
return `"${column}"."${column}" "${as}"`;
|
|
6568
6607
|
}
|
|
6569
6608
|
const col = data.shape[column];
|
|
6570
|
-
if (jsonList) jsonList[as] = col;
|
|
6609
|
+
if (jsonList) jsonList[as] = col && getSelectedColumnData(col);
|
|
6571
6610
|
if (col) {
|
|
6611
|
+
if (col.data.selectSql) return `(${col.data.selectSql.toSQL(ctx, quotedAs)}) "${as}"`;
|
|
6572
6612
|
if (col.data.name && col.data.name !== column) return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}"${col.data.name === as ? "" : ` "${as}"`}`;
|
|
6573
|
-
if (col.data.computed) return `(${col.data.computed.toSQL(ctx, quotedAs)}) "${as}"`;
|
|
6574
6613
|
}
|
|
6575
6614
|
return `${quotedAs ? `${quotedAs}.` : ""}"${column}"${column === as ? "" : ` "${as}"`}`;
|
|
6576
6615
|
};
|
|
@@ -6726,7 +6765,7 @@ var SelectItemExpression = class extends Expression {
|
|
|
6726
6765
|
}
|
|
6727
6766
|
makeSQL(ctx, quotedAs) {
|
|
6728
6767
|
const q = this.q;
|
|
6729
|
-
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(q, quotedAs).join(", ") :
|
|
6768
|
+
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(q, quotedAs, void 0, ctx).join(", ") : selectedColumnToSql(ctx, q, q.shape, this.item, quotedAs) : this.item.toSQL(ctx, quotedAs);
|
|
6730
6769
|
}
|
|
6731
6770
|
};
|
|
6732
6771
|
const _getSelectableColumn = (q, arg) => {
|
|
@@ -6938,22 +6977,33 @@ const setMutativeQueriesSelectRelationsSqlState = (d, as, rel) => {
|
|
|
6938
6977
|
const handleInsertAndUpdateSelectRelationsSqlState = (ctx, state) => {
|
|
6939
6978
|
if (state) ctx.topCtx.mutativeQueriesSelectRelationsSqlState = state;
|
|
6940
6979
|
};
|
|
6980
|
+
const unsetValuesJoinedAsForMutativeSelectRelations = (query) => {
|
|
6981
|
+
if (!query.q.selectRelation || !query.q.valuesJoinedAs) return;
|
|
6982
|
+
const { valuesJoinedAs } = query.q;
|
|
6983
|
+
query.q.valuesJoinedAs = void 0;
|
|
6984
|
+
return valuesJoinedAs;
|
|
6985
|
+
};
|
|
6986
|
+
const restoreValuesJoinedAsForMutativeSelectRelations = (query, valuesJoinedAs) => {
|
|
6987
|
+
if (valuesJoinedAs) query.q.valuesJoinedAs = valuesJoinedAs;
|
|
6988
|
+
};
|
|
6941
6989
|
const handleDeleteSelectRelationsSqlState = (ctx, query, relationSelectState) => {
|
|
6942
6990
|
const selectRelations = relationSelectState?.value;
|
|
6943
6991
|
if (!selectRelations) return;
|
|
6944
6992
|
const selectPrimaryKeysQuery = prepareSubQueryForSql(query, _clone(query));
|
|
6993
|
+
selectPrimaryKeysQuery.q.valuesJoinedAs = void 0;
|
|
6945
6994
|
const primaryKeys = requirePrimaryKeys(query, "primary keys are required for selecting relation in delete");
|
|
6946
6995
|
_addToHookSelect(selectPrimaryKeysQuery, primaryKeys, true);
|
|
6947
6996
|
const { as: cteAs } = moveQueryToCte(ctx, selectPrimaryKeysQuery, void 0, true);
|
|
6948
6997
|
const relKeys = Object.keys(selectRelations);
|
|
6949
6998
|
const hookSelect = selectPrimaryKeysQuery.q.hookSelect;
|
|
6999
|
+
const queryAs = getQueryAs(query);
|
|
6950
7000
|
const join = {
|
|
6951
7001
|
type: "JOIN",
|
|
6952
7002
|
args: {
|
|
6953
7003
|
w: cteAs,
|
|
6954
7004
|
a: [Object.fromEntries(primaryKeys.map((key) => {
|
|
6955
7005
|
const selected = hookSelect.get(key);
|
|
6956
|
-
return [cteAs + "." + (selected.as || selected.select), key];
|
|
7006
|
+
return [cteAs + "." + (selected.as || selected.select), `${queryAs}.${key}`];
|
|
6957
7007
|
}))]
|
|
6958
7008
|
}
|
|
6959
7009
|
};
|
|
@@ -7072,12 +7122,12 @@ const selectToSqlList = (ctx, table, query, quotedAs, hookSelect = query.hookSel
|
|
|
7072
7122
|
quotedTable = `"${tableName}"`;
|
|
7073
7123
|
columnName = select.slice(index + 1);
|
|
7074
7124
|
col = table.q.joinedShapes?.[tableName]?.[columnName];
|
|
7075
|
-
sql =
|
|
7125
|
+
sql = selectedColumnToSql(ctx, table.q, table.q.shape, select, void 0);
|
|
7076
7126
|
} else {
|
|
7077
7127
|
quotedTable = quotedAs;
|
|
7078
7128
|
columnName = select;
|
|
7079
7129
|
col = query.shape[select];
|
|
7080
|
-
sql =
|
|
7130
|
+
sql = selectedColumnToSql(ctx, table.q, query.shape, select, quotedAs);
|
|
7081
7131
|
}
|
|
7082
7132
|
} else {
|
|
7083
7133
|
columnName = column;
|
|
@@ -7117,17 +7167,24 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
7117
7167
|
return selectToSqlList(ctx, table, query, quotedAs, hookSelect, isSubSql, aliases, jsonList, delayedRelationSelect).join(", ");
|
|
7118
7168
|
};
|
|
7119
7169
|
const internalSelectAllSql = (ctx, query, quotedAs, jsonList) => {
|
|
7120
|
-
if (jsonList)
|
|
7170
|
+
if (jsonList) for (const key in query.selectAllShape) {
|
|
7171
|
+
const column = query.selectAllShape[key];
|
|
7172
|
+
jsonList[key] = getSelectedColumnData(column);
|
|
7173
|
+
}
|
|
7121
7174
|
let columnsCount;
|
|
7122
7175
|
if (query.shape !== anyShape) {
|
|
7123
7176
|
columnsCount = 0;
|
|
7124
7177
|
for (const key in query.shape) if (!query.shape[key].data.explicitSelect) columnsCount++;
|
|
7125
7178
|
ctx.selectedCount += columnsCount;
|
|
7126
7179
|
}
|
|
7127
|
-
return selectAllSql(query, quotedAs, columnsCount);
|
|
7180
|
+
return selectAllSql(query, quotedAs, columnsCount, ctx);
|
|
7181
|
+
};
|
|
7182
|
+
const selectAllSql = (q, quotedAs, columnsCount, ctx) => {
|
|
7183
|
+
return q.join?.length || q.updateFrom || q.updateMany ? q.selectAllColumns?.map((item) => selectAllColumnToSql(item, ctx, quotedAs, true)) || (isEmptySelect(q.shape, columnsCount) ? [] : [`${quotedAs}.*`]) : q.selectAllColumns ? q.selectAllColumns.map((item) => selectAllColumnToSql(item, ctx, quotedAs)) : isEmptySelect(q.shape, columnsCount) ? [] : ["*"];
|
|
7128
7184
|
};
|
|
7129
|
-
const
|
|
7130
|
-
|
|
7185
|
+
const selectAllColumnToSql = (item, ctx, quotedAs, prefix) => {
|
|
7186
|
+
if (typeof item !== "string") return item(ctx, quotedAs);
|
|
7187
|
+
return prefix ? `${quotedAs}.${item}` : item;
|
|
7131
7188
|
};
|
|
7132
7189
|
const isEmptySelect = (shape, columnsCount) => columnsCount === void 0 ? shape === anyShape ? false : isObjectEmpty(shape) : !columnsCount;
|
|
7133
7190
|
const pushSubQuerySql = (ctx, mainQuery, query, as, list, quotedAs, aliases) => {
|
|
@@ -7161,7 +7218,7 @@ const pushSubQuerySql = (ctx, mainQuery, query, as, list, quotedAs, aliases) =>
|
|
|
7161
7218
|
case "oneOrThrow": {
|
|
7162
7219
|
const table = query.q.joinedForSelect;
|
|
7163
7220
|
const shape = mainQuery.joinedShapes?.[as];
|
|
7164
|
-
sql = makeRowToJson(table, shape, false);
|
|
7221
|
+
sql = makeRowToJson(ctx, table, shape, false);
|
|
7165
7222
|
break;
|
|
7166
7223
|
}
|
|
7167
7224
|
case "all":
|
|
@@ -7688,6 +7745,14 @@ function pushLimitSQL(sql, values, q) {
|
|
|
7688
7745
|
}
|
|
7689
7746
|
}
|
|
7690
7747
|
const pushUpdateSql = (ctx, query, q, quotedAs, isSubSql) => {
|
|
7748
|
+
const valuesJoinedAs = unsetValuesJoinedAsForMutativeSelectRelations(query);
|
|
7749
|
+
try {
|
|
7750
|
+
return pushUpdateSqlWithoutValuesJoinedAs(ctx, query, q, quotedAs, isSubSql);
|
|
7751
|
+
} finally {
|
|
7752
|
+
restoreValuesJoinedAsForMutativeSelectRelations(query, valuesJoinedAs);
|
|
7753
|
+
}
|
|
7754
|
+
};
|
|
7755
|
+
const pushUpdateSqlWithoutValuesJoinedAs = (ctx, query, q, quotedAs, isSubSql) => {
|
|
7691
7756
|
const quotedTable = `"${query.table || q.from}"`;
|
|
7692
7757
|
const from = quoteTableWithSchema(query);
|
|
7693
7758
|
const set = [];
|
|
@@ -9546,6 +9611,8 @@ const toSql = (table, type, topCtx, isSubSql, cteName, calledByThen, dontAddTabl
|
|
|
9546
9611
|
_queryInsert(upsertOrCreate, query.upsertInsert());
|
|
9547
9612
|
upsertOrCreate.q.type = "upsert";
|
|
9548
9613
|
}
|
|
9614
|
+
upsertOrCreate.q.appendQueries = query.upsertCreateAppendQueries;
|
|
9615
|
+
upsertOrCreate.q.asFns = query.upsertCreateAsFns;
|
|
9549
9616
|
const { makeSql: makeSecondSql } = moveMutativeQueryToCteBase(toSql, ctx, upsertOrCreate, "insert");
|
|
9550
9617
|
sql.push(makeFirstSql(isSubSql), "UNION ALL", makeSecondSql(isSubSql));
|
|
9551
9618
|
} else {
|
|
@@ -9619,7 +9686,7 @@ const toSql = (table, type, topCtx, isSubSql, cteName, calledByThen, dontAddTabl
|
|
|
9619
9686
|
if (ctx.topCtx.cteHooks.hasSelect) {
|
|
9620
9687
|
if (prependedSelectParenthesis) result.text += ")";
|
|
9621
9688
|
const { tableHooks, ensureCount } = ctx.topCtx.cteHooks;
|
|
9622
|
-
const keyValues = [...tableHooks ? Object.entries(tableHooks).map(([cteName, data]) => `'${cteName}', (SELECT json_agg(${makeRowToJson(cteName, data.shape, false, true)}) FROM "${cteName}")`) : emptyArray, ...ensureCount ? Object.entries(ensureCount).map(([cteName, item]) => `'#${cteName}', CASE WHEN ${"count" in item ? `(SELECT count(*) FROM "${cteName}") < ${item.count}` : `(SELECT "${cteName}"."${item.jsonNotNull}" FROM "${cteName}") IS NULL`} THEN (SELECT 'not-found')::int END`) : emptyArray];
|
|
9689
|
+
const keyValues = [...tableHooks ? Object.entries(tableHooks).map(([cteName, data]) => `'${cteName}', (SELECT json_agg(${makeRowToJson(ctx, cteName, data.shape, false, true)}) FROM "${cteName}")`) : emptyArray, ...ensureCount ? Object.entries(ensureCount).map(([cteName, item]) => `'#${cteName}', CASE WHEN ${"count" in item ? `(SELECT count(*) FROM "${cteName}") < ${item.count}` : `(SELECT "${cteName}"."${item.jsonNotNull}" FROM "${cteName}") IS NULL`} THEN (SELECT 'not-found')::int END`) : emptyArray];
|
|
9623
9690
|
result.text += ` UNION ALL SELECT ${"NULL, ".repeat(ctx.selectedCount || 0)}json_build_object(${keyValues.join(", ")})`;
|
|
9624
9691
|
}
|
|
9625
9692
|
}
|
|
@@ -9701,9 +9768,9 @@ const addTopCteInternal = (place, ctx, item, type, dontAddTableHook) => {
|
|
|
9701
9768
|
topCTE.stack.pop();
|
|
9702
9769
|
};
|
|
9703
9770
|
const addWithToSql = (ctx, sql, isSubSql) => {
|
|
9704
|
-
if (!isSubSql && ctx.topCtx.topCTE) {
|
|
9771
|
+
if (!isSubSql && ctx.topCtx.topCTE?.append.length) {
|
|
9705
9772
|
const sqls = [];
|
|
9706
|
-
|
|
9773
|
+
for (const append of ctx.topCtx.topCTE.append) sqls.push(...append);
|
|
9707
9774
|
sql.text = "WITH " + sqls.join(", ") + " " + sql.text;
|
|
9708
9775
|
}
|
|
9709
9776
|
};
|
|
@@ -9747,17 +9814,23 @@ const quoteFromWithSchema = (schema, table) => {
|
|
|
9747
9814
|
const s = typeof schema === "function" ? schema() : schema;
|
|
9748
9815
|
return s ? `"${s}"."${table}"` : `"${table}"`;
|
|
9749
9816
|
};
|
|
9750
|
-
const makeRowToJson = (table, shape, aliasName, includingExplicitSelect) => {
|
|
9817
|
+
const makeRowToJson = (ctx, table, shape, aliasName, includingExplicitSelect) => {
|
|
9751
9818
|
let isSimple = true;
|
|
9752
9819
|
const list = [];
|
|
9753
9820
|
for (const key in shape) {
|
|
9754
9821
|
const column = shape[key];
|
|
9755
9822
|
if (!includingExplicitSelect && column.data.explicitSelect) continue;
|
|
9756
|
-
|
|
9757
|
-
|
|
9823
|
+
const selectSql = !column.data.computed ? column.data.selectSql : void 0;
|
|
9824
|
+
const outputColumn = getSelectedColumnData(column);
|
|
9825
|
+
if (aliasName && column.data.name || outputColumn.data.jsonCast || selectSql) isSimple = false;
|
|
9826
|
+
const value = selectSql ? selectSql.toSQL(ctx, `"${table}"`) : `"${table}"."${aliasName && column.data.name || key}"`;
|
|
9827
|
+
list.push(`'${key}', ${value}${outputColumn.data.jsonCast ? `::${outputColumn.data.jsonCast}` : ""}`);
|
|
9758
9828
|
}
|
|
9759
9829
|
return isSimple ? `row_to_json("${table}".*)` : `CASE WHEN to_jsonb("${table}") IS NULL THEN NULL ELSE json_build_object(` + list.join(", ") + ") END";
|
|
9760
9830
|
};
|
|
9831
|
+
const getSelectedColumnData = (column) => {
|
|
9832
|
+
return column.data.selectSql?.result.value || column;
|
|
9833
|
+
};
|
|
9761
9834
|
const getSqlText = (sql) => {
|
|
9762
9835
|
if ("text" in sql) return sql.text;
|
|
9763
9836
|
throw new Error(`Batch SQL is not supported in this query`);
|
|
@@ -12347,6 +12420,9 @@ var QueryExpressions = class {
|
|
|
12347
12420
|
const _appendQuery = (main, append, asFn) => {
|
|
12348
12421
|
return pushQueryValueImmutable(pushQueryValueImmutable(main, "appendQueries", prepareSubQueryForSql(main, append)), "asFns", asFn);
|
|
12349
12422
|
};
|
|
12423
|
+
const _appendQueryOnUpsertCreate = (main, append, asFn) => {
|
|
12424
|
+
return pushQueryValueImmutable(pushQueryValueImmutable(main, "upsertCreateAppendQueries", prepareSubQueryForSql(main, append)), "upsertCreateAsFns", asFn);
|
|
12425
|
+
};
|
|
12350
12426
|
const mergableObjects = new Set([
|
|
12351
12427
|
"shape",
|
|
12352
12428
|
"withShapes",
|
|
@@ -12393,6 +12469,10 @@ var MergeQueryMethods = class {
|
|
|
12393
12469
|
return query;
|
|
12394
12470
|
}
|
|
12395
12471
|
};
|
|
12472
|
+
const applyColumnSelectSql = (column) => {
|
|
12473
|
+
const { selectSqlFn } = column.data;
|
|
12474
|
+
if (selectSqlFn) column.data.selectSql = selectSqlFn(new ColumnRefExpression(column, column.data.key));
|
|
12475
|
+
};
|
|
12396
12476
|
const DEFAULT_PRIVILEGE = {
|
|
12397
12477
|
OBJECT_TYPES: [
|
|
12398
12478
|
"TABLES",
|
|
@@ -13763,6 +13843,10 @@ var Db = class extends QueryMethods {
|
|
|
13763
13843
|
}
|
|
13764
13844
|
if (column.data.explicitSelect) prepareSelectAll = true;
|
|
13765
13845
|
else selectAllCount++;
|
|
13846
|
+
if (column.data.selectSqlFn) {
|
|
13847
|
+
applyColumnSelectSql(column);
|
|
13848
|
+
prepareSelectAll = true;
|
|
13849
|
+
}
|
|
13766
13850
|
const { modifyQuery: mq } = column.data;
|
|
13767
13851
|
if (mq) modifyQuery = pushOrNewArray(modifyQuery, (q) => mq(q, column));
|
|
13768
13852
|
if (typeof column.data.default === "function") {
|
|
@@ -13820,7 +13904,12 @@ var Db = class extends QueryMethods {
|
|
|
13820
13904
|
for (const key in shape) {
|
|
13821
13905
|
const column = shape[key];
|
|
13822
13906
|
if (!column.data.explicitSelect) {
|
|
13823
|
-
|
|
13907
|
+
const { data } = column;
|
|
13908
|
+
const { selectSql } = data;
|
|
13909
|
+
let item;
|
|
13910
|
+
if (selectSql) item = (ctx, quotedAs) => `(${selectSql.toSQL(ctx, quotedAs)}) "${key}"`;
|
|
13911
|
+
else item = data.name ? `"${data.name}" "${key}"` : `"${key}"`;
|
|
13912
|
+
list.push(item);
|
|
13824
13913
|
selectAllShape[key] = column;
|
|
13825
13914
|
}
|
|
13826
13915
|
}
|
|
@@ -14309,6 +14398,6 @@ const testTransaction = {
|
|
|
14309
14398
|
if (db.internal[trxForTest]?.length === 0) return db.q.adapter.close();
|
|
14310
14399
|
}
|
|
14311
14400
|
};
|
|
14312
|
-
export { AdapterClass, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Column, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, Expression, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MoneyColumn, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, Operators, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryError, QueryHookUtils, QueryHooks, RawSql, RealColumn, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, TransactionAdapterClass, TsQueryColumn, TsVectorColumn, UUIDColumn, UnknownColumn, VarCharColumn, VirtualColumn, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
|
14401
|
+
export { AdapterClass, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Column, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, Expression, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MoneyColumn, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, Operators, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryError, QueryHookUtils, QueryHooks, RawSql, RealColumn, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, TransactionAdapterClass, TsQueryColumn, TsVectorColumn, UUIDColumn, UnknownColumn, VarCharColumn, VirtualColumn, XMLColumn, _appendQuery, _appendQueryOnUpsertCreate, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
|
14313
14402
|
|
|
14314
14403
|
//# sourceMappingURL=index.mjs.map
|