pqb 0.67.0 → 0.67.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 +191 -175
- package/dist/index.js +78 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6740,17 +6740,27 @@ const _get = (query, returnType, arg) => {
|
|
|
6740
6740
|
if (q.returning) q.returning = void 0;
|
|
6741
6741
|
q.returnType = returnType;
|
|
6742
6742
|
let type;
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6743
|
+
let value = arg;
|
|
6744
|
+
if (typeof value === "function") {
|
|
6745
|
+
const item = processSelectAsArg(query, getQueryAs(query), "value", value);
|
|
6746
|
+
if (item !== false) value = item;
|
|
6747
|
+
}
|
|
6748
|
+
if (typeof value === "string") {
|
|
6749
|
+
const joinedAs = q.valuesJoinedAs?.[value];
|
|
6750
|
+
type = joinedAs ? q.joinedShapes?.[joinedAs]?.value : _getSelectableColumn(query, value);
|
|
6746
6751
|
q.getColumn = type;
|
|
6747
|
-
const selected = setParserForSelectedString(query, joinedAs ? joinedAs + "." +
|
|
6752
|
+
const selected = setParserForSelectedString(query, joinedAs ? joinedAs + "." + value : value, getQueryAs(query), getValueKey);
|
|
6748
6753
|
q.select = selected ? [q.expr = new SelectItemExpression(query, selected, type)] : void 0;
|
|
6749
|
-
} else {
|
|
6750
|
-
type =
|
|
6754
|
+
} else if (isExpression(value)) {
|
|
6755
|
+
type = value.result.value;
|
|
6751
6756
|
q.getColumn = type;
|
|
6752
|
-
addParserForRawExpression(query, getValueKey,
|
|
6753
|
-
q.select = [q.expr =
|
|
6757
|
+
addParserForRawExpression(query, getValueKey, value);
|
|
6758
|
+
q.select = [q.expr = value];
|
|
6759
|
+
} else {
|
|
6760
|
+
const selected = value;
|
|
6761
|
+
q.getColumn = selected.q.getColumn;
|
|
6762
|
+
if (q.getColumn) addColumnParserToQuery(q, getValueKey, q.getColumn);
|
|
6763
|
+
q.select = selected ? [{ selectAs: { value: selected } }] : void 0;
|
|
6754
6764
|
}
|
|
6755
6765
|
return setQueryOperators(query, type?.operators || Operators.any);
|
|
6756
6766
|
};
|
|
@@ -10865,44 +10875,49 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
|
|
|
10865
10875
|
};
|
|
10866
10876
|
const emptyArrSQL = new RawSql("'[]'");
|
|
10867
10877
|
const processSelectArg = (q, as, arg, columnAs) => {
|
|
10868
|
-
const query = q;
|
|
10869
10878
|
if (typeof arg === "string") return setParserForSelectedString(q, arg, as, columnAs);
|
|
10870
10879
|
const selectAs = {};
|
|
10871
10880
|
for (const key in arg) {
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10882
|
-
|
|
10883
|
-
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10887
|
-
|
|
10888
|
-
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
|
|
10898
|
-
|
|
10899
|
-
|
|
10900
|
-
value
|
|
10881
|
+
const item = processSelectAsArg(q, as, key, arg[key]);
|
|
10882
|
+
if (item === false) return false;
|
|
10883
|
+
selectAs[key] = item;
|
|
10884
|
+
}
|
|
10885
|
+
return { selectAs };
|
|
10886
|
+
};
|
|
10887
|
+
const processSelectAsArg = (q, as, key, arg) => {
|
|
10888
|
+
const query = q;
|
|
10889
|
+
let value = arg;
|
|
10890
|
+
let joinQuery;
|
|
10891
|
+
if (typeof value === "function") {
|
|
10892
|
+
value = resolveSubQueryCallback(q, value);
|
|
10893
|
+
if (isQueryNone(value)) {
|
|
10894
|
+
if (value.q.innerJoinLateral) return false;
|
|
10895
|
+
}
|
|
10896
|
+
if (!isExpression(value)) {
|
|
10897
|
+
if (isRelationQuery(value) && value.q.subQuery !== 1) {
|
|
10898
|
+
joinQuery = true;
|
|
10899
|
+
setSelectRelation(query.q);
|
|
10900
|
+
value = value.joinQuery(value, q);
|
|
10901
|
+
let subQuery;
|
|
10902
|
+
const { returnType, innerJoinLateral } = value.q;
|
|
10903
|
+
if (!returnType || returnType === "all") {
|
|
10904
|
+
subQuery = value.json(false);
|
|
10905
|
+
if (!innerJoinLateral) value.q.coalesceValue = emptyArrSQL;
|
|
10906
|
+
} else if (returnType === "pluck") {
|
|
10907
|
+
subQuery = value.q.select ? value.wrap(cloneQueryBaseUnscoped(value)).jsonAgg(value.q.select[0]) : value.json(false);
|
|
10908
|
+
value.q.coalesceValue = emptyArrSQL;
|
|
10909
|
+
} else if (returnType === "value" || returnType === "valueOrThrow") if (value.q.select) {
|
|
10910
|
+
if (typeof value.q.select[0] === "string") value.q.select[0] = { selectAs: { r: value.q.select[0] } };
|
|
10911
|
+
subQuery = value;
|
|
10912
|
+
} else subQuery = value.json(false);
|
|
10913
|
+
else subQuery = value;
|
|
10914
|
+
const as = _joinLateral(q, innerJoinLateral || query.q.returnType === "valueOrThrow" ? "JOIN" : "LEFT JOIN", subQuery, key, innerJoinLateral && returnType !== "one" && returnType !== "oneOrThrow");
|
|
10915
|
+
if (as) value.q.joinedForSelect = _copyQueryAliasToQuery(value, q, as);
|
|
10901
10916
|
}
|
|
10917
|
+
value = prepareSubQueryForSql(q, value);
|
|
10902
10918
|
}
|
|
10903
|
-
selectAs[key] = addParserForSelectItem(q, as, key, value, key, joinQuery);
|
|
10904
10919
|
}
|
|
10905
|
-
return
|
|
10920
|
+
return addParserForSelectItem(query, as, key, value, key, joinQuery);
|
|
10906
10921
|
};
|
|
10907
10922
|
const setParserForSelectedString = (query, arg, as, columnAs, columnAlias) => {
|
|
10908
10923
|
const { q } = query;
|
|
@@ -12808,6 +12823,28 @@ var Having = class {
|
|
|
12808
12823
|
return pushQueryValueImmutable(_clone(this), "having", args);
|
|
12809
12824
|
}
|
|
12810
12825
|
};
|
|
12826
|
+
var QueryPluck = class {
|
|
12827
|
+
/**
|
|
12828
|
+
* `.pluck` returns a single array of a single selected column values:
|
|
12829
|
+
*
|
|
12830
|
+
* ```ts
|
|
12831
|
+
* const ids = await db.table.select('id').pluck();
|
|
12832
|
+
* // ids are an array of all users' id like [1, 2, 3]
|
|
12833
|
+
* ```
|
|
12834
|
+
* @param select - column name or a raw SQL
|
|
12835
|
+
*/
|
|
12836
|
+
pluck(select) {
|
|
12837
|
+
const q = _clone(this);
|
|
12838
|
+
q.q.returnType = "pluck";
|
|
12839
|
+
let selected;
|
|
12840
|
+
if (typeof select === "function") {
|
|
12841
|
+
const item = processSelectAsArg(q, q.q.as || q.table, "pluck", select);
|
|
12842
|
+
if (item !== false) selected = isExpression(item) ? item : { selectAs: { pluck: item } };
|
|
12843
|
+
} else selected = addParserForSelectItem(q, q.q.as || q.table, "pluck", select);
|
|
12844
|
+
q.q.select = selected ? [selected] : void 0;
|
|
12845
|
+
return q;
|
|
12846
|
+
}
|
|
12847
|
+
};
|
|
12811
12848
|
var QueryMap = class {
|
|
12812
12849
|
/**
|
|
12813
12850
|
* Use `map` to transform individual records of a query result.
|
|
@@ -13162,22 +13199,6 @@ var QueryMethods = class {
|
|
|
13162
13199
|
return _queryRows(_clone(this));
|
|
13163
13200
|
}
|
|
13164
13201
|
/**
|
|
13165
|
-
* `.pluck` returns a single array of a single selected column values:
|
|
13166
|
-
*
|
|
13167
|
-
* ```ts
|
|
13168
|
-
* const ids = await db.table.select('id').pluck();
|
|
13169
|
-
* // ids are an array of all users' id like [1, 2, 3]
|
|
13170
|
-
* ```
|
|
13171
|
-
* @param select - column name or a raw SQL
|
|
13172
|
-
*/
|
|
13173
|
-
pluck(select) {
|
|
13174
|
-
const q = _clone(this);
|
|
13175
|
-
q.q.returnType = "pluck";
|
|
13176
|
-
const selected = addParserForSelectItem(q, q.q.as || q.table, "pluck", select);
|
|
13177
|
-
q.q.select = selected ? [selected] : void 0;
|
|
13178
|
-
return q;
|
|
13179
|
-
}
|
|
13180
|
-
/**
|
|
13181
13202
|
* `.exec` won't parse the response at all, and returns undefined:
|
|
13182
13203
|
*
|
|
13183
13204
|
* ```ts
|
|
@@ -13632,6 +13653,7 @@ applyMixins(QueryMethods, [
|
|
|
13632
13653
|
QueryOrCreate,
|
|
13633
13654
|
QueryHooks,
|
|
13634
13655
|
QueryGet,
|
|
13656
|
+
QueryPluck,
|
|
13635
13657
|
MergeQueryMethods,
|
|
13636
13658
|
QuerySql,
|
|
13637
13659
|
QueryTransform,
|