pqb 0.11.15 → 0.11.17
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 +1 -0
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -160,7 +160,7 @@ const getJoinedColumnName = (data, shape, table, key, isOwnColumn) => {
|
|
|
160
160
|
var _a, _b, _c;
|
|
161
161
|
return (_c = (isOwnColumn ? shape[key] : void 0) || ((_b = (_a = data.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[key])) == null ? void 0 : _c.data.name;
|
|
162
162
|
};
|
|
163
|
-
const revealColumnToSql = (data, shape, column, quotedAs) => {
|
|
163
|
+
const revealColumnToSql = (data, shape, column, quotedAs, select) => {
|
|
164
164
|
var _a, _b;
|
|
165
165
|
const index = column.indexOf(".");
|
|
166
166
|
if (index !== -1) {
|
|
@@ -171,14 +171,14 @@ const revealColumnToSql = (data, shape, column, quotedAs) => {
|
|
|
171
171
|
getJoinedColumnName(data, shape, table, key, quoted === quotedAs) || key
|
|
172
172
|
)}`;
|
|
173
173
|
} else if ((_a = data.joinedShapes) == null ? void 0 : _a[column]) {
|
|
174
|
-
return `row_to_json("${column}".*)`;
|
|
174
|
+
return select ? `row_to_json("${column}".*)` : `"${column}".r`;
|
|
175
175
|
} else if (quotedAs && shape[column]) {
|
|
176
176
|
return `${quotedAs}.${q(shape[column].data.name || column)}`;
|
|
177
177
|
} else {
|
|
178
178
|
return q(((_b = shape[column]) == null ? void 0 : _b.data.name) || column);
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
|
-
const revealColumnToSqlWithAs = (data, column, quotedAs) => {
|
|
181
|
+
const revealColumnToSqlWithAs = (data, column, quotedAs, select) => {
|
|
182
182
|
var _a, _b;
|
|
183
183
|
const index = column.indexOf(".");
|
|
184
184
|
if (index !== -1) {
|
|
@@ -194,14 +194,14 @@ const revealColumnToSqlWithAs = (data, column, quotedAs) => {
|
|
|
194
194
|
);
|
|
195
195
|
return `${quoted}.${q(name || key)}${name && name !== key ? ` AS ${q(key)}` : ""}`;
|
|
196
196
|
} else if ((_a = data.joinedShapes) == null ? void 0 : _a[column]) {
|
|
197
|
-
return `row_to_json("${column}".*) "${column}"`;
|
|
197
|
+
return select ? `row_to_json("${column}".*) "${column}"` : `"${column}".r "${column}"`;
|
|
198
198
|
} else {
|
|
199
199
|
const name = (_b = data.shape[column]) == null ? void 0 : _b.data.name;
|
|
200
200
|
return `${quotedAs ? `${quotedAs}.` : ""}${q(name || column)}${name && name !== column ? ` AS ${q(column)}` : ""}`;
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
|
-
const rawOrRevealColumnToSql = (data, expr, values, quotedAs, shape = data.shape) => {
|
|
204
|
-
return typeof expr === "string" ? revealColumnToSql(data, shape, expr, quotedAs) : getRaw(expr, values);
|
|
203
|
+
const rawOrRevealColumnToSql = (data, expr, values, quotedAs, shape = data.shape, select) => {
|
|
204
|
+
return typeof expr === "string" ? revealColumnToSql(data, shape, expr, quotedAs, select) : getRaw(expr, values);
|
|
205
205
|
};
|
|
206
206
|
const quoteSchemaAndTable = (schema, table) => {
|
|
207
207
|
return schema ? `${q(schema)}.${q(table)}` : q(table);
|
|
@@ -2320,7 +2320,7 @@ const selectToSql = (ctx, table, query, quotedAs) => {
|
|
|
2320
2320
|
for (const item of query.select) {
|
|
2321
2321
|
if (typeof item === "string") {
|
|
2322
2322
|
list.push(
|
|
2323
|
-
item === "*" ? selectAllSql(table, query, quotedAs) : revealColumnToSqlWithAs(table.query, item, quotedAs)
|
|
2323
|
+
item === "*" ? selectAllSql(table, query, quotedAs) : revealColumnToSqlWithAs(table.query, item, quotedAs, true)
|
|
2324
2324
|
);
|
|
2325
2325
|
} else {
|
|
2326
2326
|
if ("selectAs" in item) {
|
|
@@ -2339,7 +2339,8 @@ const selectToSql = (ctx, table, query, quotedAs) => {
|
|
|
2339
2339
|
table.query,
|
|
2340
2340
|
table.query.shape,
|
|
2341
2341
|
value,
|
|
2342
|
-
quotedAs
|
|
2342
|
+
quotedAs,
|
|
2343
|
+
true
|
|
2343
2344
|
)} AS ${q(as)}`
|
|
2344
2345
|
);
|
|
2345
2346
|
}
|
|
@@ -2383,14 +2384,14 @@ const pushSubQuerySql = (query, as, values, list) => {
|
|
|
2383
2384
|
switch (returnType) {
|
|
2384
2385
|
case "one":
|
|
2385
2386
|
case "oneOrThrow":
|
|
2386
|
-
sql = `row_to_json("${
|
|
2387
|
+
sql = `row_to_json("${query.query.joinedForSelect}".*)`;
|
|
2387
2388
|
break;
|
|
2388
2389
|
case "all":
|
|
2389
2390
|
case "pluck":
|
|
2390
2391
|
case "value":
|
|
2391
2392
|
case "valueOrThrow":
|
|
2392
2393
|
case "rows":
|
|
2393
|
-
sql = `"${
|
|
2394
|
+
sql = `"${query.query.joinedForSelect}".r`;
|
|
2394
2395
|
break;
|
|
2395
2396
|
case "rowCount":
|
|
2396
2397
|
case "void":
|
|
@@ -3854,7 +3855,7 @@ const _joinLateral = (q, type, arg, cb, as) => {
|
|
|
3854
3855
|
if (relation) {
|
|
3855
3856
|
result = relation.joinQuery(q, result);
|
|
3856
3857
|
}
|
|
3857
|
-
const joinKey = result.query.as || result.table;
|
|
3858
|
+
const joinKey = as || result.query.as || result.table;
|
|
3858
3859
|
if (joinKey) {
|
|
3859
3860
|
const shape = getShapeFromSelect(result, true);
|
|
3860
3861
|
setQueryObjectValue(q, "joinedShapes", joinKey, shape);
|
|
@@ -3970,9 +3971,8 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
3970
3971
|
value = value(q);
|
|
3971
3972
|
q.isSubQuery = isSubQuery;
|
|
3972
3973
|
if (!orchidCore.isRaw(value) && value.joinQuery) {
|
|
3973
|
-
value.query.as = key;
|
|
3974
3974
|
value = value.joinQuery(q, value);
|
|
3975
|
-
value.query.joinedForSelect =
|
|
3975
|
+
value.query.joinedForSelect = key;
|
|
3976
3976
|
let query;
|
|
3977
3977
|
const returnType = value.query.returnType;
|
|
3978
3978
|
if (!returnType || returnType === "all") {
|