pqb 0.51.0 → 0.51.1
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 +18 -8
- package/dist/index.js +69 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1999,18 +1999,14 @@ const getFullColumnTable = (q, column, index, as) => {
|
|
|
1999
1999
|
return as && table !== as && q.q.aliases?.[table] === as ? as : table;
|
|
2000
2000
|
};
|
|
2001
2001
|
|
|
2002
|
-
|
|
2003
|
-
addColumnParserToQuery(q, as, computed.result.value);
|
|
2004
|
-
return computed.toSQL(ctx, quotedAs);
|
|
2005
|
-
};
|
|
2006
|
-
function simpleColumnToSQL(ctx, q, key, column, quotedAs) {
|
|
2002
|
+
function simpleColumnToSQL(ctx, key, column, quotedAs) {
|
|
2007
2003
|
if (!column) return `"${key}"`;
|
|
2008
2004
|
const { data } = column;
|
|
2009
|
-
return data.computed ?
|
|
2005
|
+
return data.computed ? data.computed.toSQL(ctx, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
2010
2006
|
}
|
|
2011
|
-
function simpleExistingColumnToSQL(ctx,
|
|
2007
|
+
function simpleExistingColumnToSQL(ctx, key, column, quotedAs) {
|
|
2012
2008
|
const { data } = column;
|
|
2013
|
-
return data.computed ?
|
|
2009
|
+
return data.computed ? data.computed.toSQL(ctx, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
2014
2010
|
}
|
|
2015
2011
|
const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
2016
2012
|
const index = column.indexOf(".");
|
|
@@ -2028,7 +2024,7 @@ const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
|
2028
2024
|
if (!select && data.joinedShapes?.[column]) {
|
|
2029
2025
|
return `"${column}".r`;
|
|
2030
2026
|
}
|
|
2031
|
-
return simpleColumnToSQL(ctx,
|
|
2027
|
+
return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
|
|
2032
2028
|
};
|
|
2033
2029
|
const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
2034
2030
|
const index = column.indexOf(".");
|
|
@@ -2042,12 +2038,12 @@ const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
|
|
|
2042
2038
|
for (const s of data.select) {
|
|
2043
2039
|
if (typeof s === "object" && "selectAs" in s) {
|
|
2044
2040
|
if (column in s.selectAs) {
|
|
2045
|
-
return simpleColumnToSQL(ctx,
|
|
2041
|
+
return simpleColumnToSQL(ctx, column, data.shape[column]);
|
|
2046
2042
|
}
|
|
2047
2043
|
}
|
|
2048
2044
|
}
|
|
2049
2045
|
}
|
|
2050
|
-
return simpleColumnToSQL(ctx,
|
|
2046
|
+
return simpleColumnToSQL(ctx, column, data.shape[column], quotedAs);
|
|
2051
2047
|
}
|
|
2052
2048
|
};
|
|
2053
2049
|
const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) => {
|
|
@@ -2065,7 +2061,7 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
2065
2061
|
return `"${tableName}"."${col.data.name}"`;
|
|
2066
2062
|
}
|
|
2067
2063
|
if (col.data.computed) {
|
|
2068
|
-
return
|
|
2064
|
+
return col.data.computed.toSQL(ctx, quoted);
|
|
2069
2065
|
}
|
|
2070
2066
|
return `"${tableName}"."${key}"`;
|
|
2071
2067
|
}
|
|
@@ -2105,13 +2101,7 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
|
|
|
2105
2101
|
return `"${tableName}"."${col.data.name}" "${as}"`;
|
|
2106
2102
|
}
|
|
2107
2103
|
if (col.data.computed) {
|
|
2108
|
-
return `${
|
|
2109
|
-
ctx,
|
|
2110
|
-
data,
|
|
2111
|
-
col.data.computed,
|
|
2112
|
-
as,
|
|
2113
|
-
quoted
|
|
2114
|
-
)} "${as}"`;
|
|
2104
|
+
return `${col.data.computed.toSQL(ctx, quoted)} "${as}"`;
|
|
2115
2105
|
}
|
|
2116
2106
|
}
|
|
2117
2107
|
return `"${tableName}"."${key}"${key === as ? "" : ` "${as}"`}`;
|
|
@@ -2124,13 +2114,7 @@ const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select, jsonList)
|
|
|
2124
2114
|
return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}"${col.data.name === as ? "" : ` "${as}"`}`;
|
|
2125
2115
|
}
|
|
2126
2116
|
if (col.data.computed) {
|
|
2127
|
-
return `${
|
|
2128
|
-
ctx,
|
|
2129
|
-
data,
|
|
2130
|
-
col.data.computed,
|
|
2131
|
-
as,
|
|
2132
|
-
quotedAs
|
|
2133
|
-
)} "${as}"`;
|
|
2117
|
+
return `${col.data.computed.toSQL(ctx, quotedAs)} "${as}"`;
|
|
2134
2118
|
}
|
|
2135
2119
|
}
|
|
2136
2120
|
return `${quotedAs ? `${quotedAs}.` : ""}"${column}"${column === as ? "" : ` "${as}"`}`;
|
|
@@ -2146,7 +2130,7 @@ const makeRowToJson = (table, shape, aliasName) => {
|
|
|
2146
2130
|
const list = [];
|
|
2147
2131
|
for (const key in shape) {
|
|
2148
2132
|
const column = shape[key];
|
|
2149
|
-
if (column.data.explicitSelect
|
|
2133
|
+
if (column.data.explicitSelect) {
|
|
2150
2134
|
continue;
|
|
2151
2135
|
}
|
|
2152
2136
|
if (aliasName && column.data.name || column.data.jsonCast) {
|
|
@@ -3077,10 +3061,23 @@ const applyComputedColumns = (q, fn) => {
|
|
|
3077
3061
|
[key]: item
|
|
3078
3062
|
};
|
|
3079
3063
|
} else {
|
|
3080
|
-
|
|
3064
|
+
let col = item.result.value;
|
|
3065
|
+
if (!col) {
|
|
3066
|
+
item.result.value = col = Object.create(
|
|
3067
|
+
UnknownColumn.instance
|
|
3068
|
+
);
|
|
3069
|
+
col.data = { ...col.data };
|
|
3070
|
+
}
|
|
3071
|
+
q.shape[key] = col;
|
|
3072
|
+
const { data } = col;
|
|
3081
3073
|
data.computed = item;
|
|
3082
3074
|
data.explicitSelect = true;
|
|
3083
3075
|
data.readonly = true;
|
|
3076
|
+
addColumnParserToQuery(
|
|
3077
|
+
q.q,
|
|
3078
|
+
key,
|
|
3079
|
+
item.result.value
|
|
3080
|
+
);
|
|
3084
3081
|
}
|
|
3085
3082
|
}
|
|
3086
3083
|
q.computeAtRuntime = q.computeBatchAtRuntime = void 0;
|
|
@@ -4179,58 +4176,49 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
4179
4176
|
const setParserForSelectedString = (query, arg, as, columnAs) => {
|
|
4180
4177
|
const { q } = query;
|
|
4181
4178
|
const index = arg.indexOf(".");
|
|
4182
|
-
if (index
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
if (parser) setParserToQuery(q, columnAs || column, parser);
|
|
4203
|
-
const batchParsers = q.joinedBatchParsers?.[table];
|
|
4204
|
-
if (batchParsers) {
|
|
4205
|
-
let cloned = false;
|
|
4206
|
-
for (const bp of batchParsers) {
|
|
4207
|
-
if (bp.path[0] === column) {
|
|
4208
|
-
if (!cloned) {
|
|
4209
|
-
q.batchParsers = [...q.batchParsers || []];
|
|
4210
|
-
cloned = true;
|
|
4211
|
-
}
|
|
4212
|
-
q.batchParsers.push(bp);
|
|
4179
|
+
if (index === -1) return selectColumn(query, q, arg, columnAs);
|
|
4180
|
+
const table = getFullColumnTable(query, arg, index, as);
|
|
4181
|
+
const column = arg.slice(index + 1);
|
|
4182
|
+
if (column === "*") {
|
|
4183
|
+
addParsersForSelectJoined(query, table, columnAs);
|
|
4184
|
+
return table === as ? column : arg;
|
|
4185
|
+
}
|
|
4186
|
+
if (table === as) {
|
|
4187
|
+
return selectColumn(query, q, column, columnAs);
|
|
4188
|
+
}
|
|
4189
|
+
const parser = q.joinedParsers?.[table]?.[column];
|
|
4190
|
+
if (parser) setParserToQuery(q, columnAs || column, parser);
|
|
4191
|
+
const batchParsers = q.joinedBatchParsers?.[table];
|
|
4192
|
+
if (batchParsers) {
|
|
4193
|
+
let cloned = false;
|
|
4194
|
+
for (const bp of batchParsers) {
|
|
4195
|
+
if (bp.path[0] === column) {
|
|
4196
|
+
if (!cloned) {
|
|
4197
|
+
q.batchParsers = [...q.batchParsers || []];
|
|
4198
|
+
cloned = true;
|
|
4213
4199
|
}
|
|
4200
|
+
q.batchParsers.push(bp);
|
|
4214
4201
|
}
|
|
4215
4202
|
}
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
}
|
|
4223
|
-
setObjectValueImmutable(q, "selectedComputeds", column, computed);
|
|
4224
|
-
return;
|
|
4225
|
-
}
|
|
4226
|
-
return arg;
|
|
4227
|
-
} else {
|
|
4228
|
-
if (columnAs && q.parsers) {
|
|
4229
|
-
const parser = q.parsers?.[arg];
|
|
4230
|
-
if (parser) setObjectValueImmutable(q, "parsers", columnAs, parser);
|
|
4203
|
+
}
|
|
4204
|
+
const computeds = q.joinedComputeds?.[table];
|
|
4205
|
+
if (computeds?.[column]) {
|
|
4206
|
+
const computed = computeds[column];
|
|
4207
|
+
const map = q.hookSelect = new Map(q.hookSelect);
|
|
4208
|
+
for (const column2 of computed.deps) {
|
|
4209
|
+
map.set(column2, { select: `${table}.${column2}` });
|
|
4231
4210
|
}
|
|
4232
|
-
|
|
4211
|
+
setObjectValueImmutable(q, "selectedComputeds", column, computed);
|
|
4212
|
+
return;
|
|
4233
4213
|
}
|
|
4214
|
+
return arg;
|
|
4215
|
+
};
|
|
4216
|
+
const selectColumn = (query, q, key, columnAs) => {
|
|
4217
|
+
if (columnAs && q.parsers) {
|
|
4218
|
+
const parser = q.parsers[key];
|
|
4219
|
+
if (parser) setObjectValueImmutable(q, "parsers", columnAs, parser);
|
|
4220
|
+
}
|
|
4221
|
+
return handleComputed(query, q.computeds, key);
|
|
4234
4222
|
};
|
|
4235
4223
|
const handleComputed = (q, computeds, column) => {
|
|
4236
4224
|
if (computeds?.[column]) {
|
|
@@ -4952,7 +4940,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
|
|
|
4952
4940
|
quotedTable = quotedAs;
|
|
4953
4941
|
columnName = select;
|
|
4954
4942
|
col = query.shape[select];
|
|
4955
|
-
sql = simpleColumnToSQL(ctx,
|
|
4943
|
+
sql = simpleColumnToSQL(ctx, select, col, quotedAs);
|
|
4956
4944
|
}
|
|
4957
4945
|
} else {
|
|
4958
4946
|
columnName = column;
|
|
@@ -5834,13 +5822,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
5834
5822
|
let column = query.shape[key];
|
|
5835
5823
|
let quotedColumn;
|
|
5836
5824
|
if (column) {
|
|
5837
|
-
quotedColumn = simpleExistingColumnToSQL(
|
|
5838
|
-
ctx,
|
|
5839
|
-
query,
|
|
5840
|
-
key,
|
|
5841
|
-
column,
|
|
5842
|
-
quotedAs
|
|
5843
|
-
);
|
|
5825
|
+
quotedColumn = simpleExistingColumnToSQL(ctx, key, column, quotedAs);
|
|
5844
5826
|
} else if (!column) {
|
|
5845
5827
|
const index = key.indexOf(".");
|
|
5846
5828
|
if (index !== -1) {
|
|
@@ -5848,7 +5830,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
5848
5830
|
const quoted = `"${table2}"`;
|
|
5849
5831
|
const name = key.slice(index + 1);
|
|
5850
5832
|
column = quotedAs === quoted ? query.shape[name] : query.joinedShapes?.[table2]?.[name];
|
|
5851
|
-
quotedColumn = simpleColumnToSQL(ctx,
|
|
5833
|
+
quotedColumn = simpleColumnToSQL(ctx, name, column, quoted);
|
|
5852
5834
|
} else {
|
|
5853
5835
|
column = query.joinedShapes?.[key]?.value;
|
|
5854
5836
|
quotedColumn = `"${key}".r`;
|
|
@@ -7388,6 +7370,7 @@ class VirtualColumn extends ColumnType {
|
|
|
7388
7370
|
super(schema, inputSchema);
|
|
7389
7371
|
this.dataType = "";
|
|
7390
7372
|
this.operators = Operators.any;
|
|
7373
|
+
this.data.explicitSelect = true;
|
|
7391
7374
|
}
|
|
7392
7375
|
toCode() {
|
|
7393
7376
|
throw new Error(`toCode is not implemented for virtual column`);
|
|
@@ -7397,6 +7380,8 @@ class VirtualColumn extends ColumnType {
|
|
|
7397
7380
|
const _UnknownColumn = class _UnknownColumn extends VirtualColumn {
|
|
7398
7381
|
constructor(schema) {
|
|
7399
7382
|
super(schema, schema.unknown());
|
|
7383
|
+
this.selectable = true;
|
|
7384
|
+
this.data.explicitSelect = void 0;
|
|
7400
7385
|
}
|
|
7401
7386
|
};
|
|
7402
7387
|
_UnknownColumn.instance = new _UnknownColumn(defaultSchemaConfig);
|
|
@@ -11720,8 +11705,6 @@ class ColumnRefExpression extends Expression {
|
|
|
11720
11705
|
makeSQL(ctx, quotedAs) {
|
|
11721
11706
|
return simpleExistingColumnToSQL(
|
|
11722
11707
|
ctx,
|
|
11723
|
-
// it's for parsers for computed SQL. In the column ref case, parsers should be set when selecting the column ref.
|
|
11724
|
-
{},
|
|
11725
11708
|
this.name,
|
|
11726
11709
|
this.result.value,
|
|
11727
11710
|
quotedAs
|