pqb 0.38.8 → 0.39.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 +4 -4
- package/dist/index.js +83 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -16
package/dist/index.d.ts
CHANGED
|
@@ -553,8 +553,9 @@ declare class NotFoundError extends OrchidOrmError {
|
|
|
553
553
|
constructor(query: Query, message?: string);
|
|
554
554
|
}
|
|
555
555
|
declare class OrchidOrmInternalError extends Error {
|
|
556
|
-
|
|
556
|
+
#private;
|
|
557
557
|
constructor(query: Query, message?: string);
|
|
558
|
+
get query(): Query;
|
|
558
559
|
}
|
|
559
560
|
type QueryErrorName = 'parseComplete' | 'bindComplete' | 'closeComplete' | 'noData' | 'portalSuspended' | 'replicationStart' | 'emptyQuery' | 'copyDone' | 'copyData' | 'rowDescription' | 'parameterDescription' | 'parameterStatus' | 'backendKeyData' | 'notification' | 'readyForQuery' | 'commandComplete' | 'dataRow' | 'copyInResponse' | 'copyOutResponse' | 'authenticationOk' | 'authenticationMD5Password' | 'authenticationCleartextPassword' | 'authenticationSASL' | 'authenticationSASLContinue' | 'authenticationSASLFinal' | 'error' | 'notice';
|
|
560
561
|
declare abstract class QueryError<T extends PickQueryShape = PickQueryShape> extends OrchidOrmInternalError {
|
|
@@ -587,7 +588,6 @@ declare class MoreThanOneRowError extends OrchidOrmInternalError {
|
|
|
587
588
|
constructor(query: Query, message?: string);
|
|
588
589
|
}
|
|
589
590
|
declare class UnhandledTypeError extends OrchidOrmInternalError {
|
|
590
|
-
query: Query;
|
|
591
591
|
constructor(query: Query, value: never);
|
|
592
592
|
}
|
|
593
593
|
|
|
@@ -2683,7 +2683,7 @@ declare class ArrayColumn<Schema extends ColumnTypeSchemaArg, Item extends Array
|
|
|
2683
2683
|
constructor(schema: Schema, item: Item, inputType: InputType, outputType?: OutputType, queryType?: QueryType);
|
|
2684
2684
|
toSQL(): string;
|
|
2685
2685
|
toCode(this: ArrayColumn<ColumnSchemaConfig, ArrayColumnValue, unknown, unknown, unknown>, ctx: ColumnToCodeCtx, key: string): Code;
|
|
2686
|
-
parseFn: ((
|
|
2686
|
+
parseFn: ((source: string) => unknown[]) & {
|
|
2687
2687
|
hideFromCode: boolean;
|
|
2688
2688
|
};
|
|
2689
2689
|
}
|
|
@@ -7893,7 +7893,7 @@ declare class BooleanColumn<Schema extends ColumnSchemaConfig> extends ColumnTyp
|
|
|
7893
7893
|
operators: OperatorsBoolean;
|
|
7894
7894
|
constructor(schema: Schema);
|
|
7895
7895
|
toCode(ctx: ColumnToCodeCtx, key: string): Code;
|
|
7896
|
-
parseItem
|
|
7896
|
+
parseItem(input: string): boolean;
|
|
7897
7897
|
}
|
|
7898
7898
|
|
|
7899
7899
|
declare class CustomTypeColumn<Schema extends ColumnSchemaConfig> extends ColumnType<Schema, unknown, ReturnType<Schema['unknown']>, typeof Operators.any> {
|
package/dist/index.js
CHANGED
|
@@ -1826,12 +1826,14 @@ class BooleanColumn extends ColumnType {
|
|
|
1826
1826
|
super(schema, schema.boolean());
|
|
1827
1827
|
this.dataType = "bool";
|
|
1828
1828
|
this.operators = Operators.boolean;
|
|
1829
|
-
this.parseItem = (input) => input[0] === "t";
|
|
1830
1829
|
this.data.alias = "boolean";
|
|
1831
1830
|
}
|
|
1832
1831
|
toCode(ctx, key) {
|
|
1833
1832
|
return columnCode(this, ctx, key, "boolean()");
|
|
1834
1833
|
}
|
|
1834
|
+
parseItem(input) {
|
|
1835
|
+
return input[0] === "t";
|
|
1836
|
+
}
|
|
1835
1837
|
}
|
|
1836
1838
|
|
|
1837
1839
|
const encodeFn = (x) => x === null ? x : JSON.stringify(x);
|
|
@@ -1991,6 +1993,25 @@ const pushDistinctSql = (ctx, table, distinct, quotedAs) => {
|
|
|
1991
1993
|
}
|
|
1992
1994
|
};
|
|
1993
1995
|
|
|
1996
|
+
var __accessCheck = (obj, member, msg) => {
|
|
1997
|
+
if (!member.has(obj))
|
|
1998
|
+
throw TypeError("Cannot " + msg);
|
|
1999
|
+
};
|
|
2000
|
+
var __privateGet = (obj, member, getter) => {
|
|
2001
|
+
__accessCheck(obj, member, "read from private field");
|
|
2002
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
2003
|
+
};
|
|
2004
|
+
var __privateAdd = (obj, member, value) => {
|
|
2005
|
+
if (member.has(obj))
|
|
2006
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
2007
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
2008
|
+
};
|
|
2009
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
2010
|
+
__accessCheck(obj, member, "write to private field");
|
|
2011
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
2012
|
+
return value;
|
|
2013
|
+
};
|
|
2014
|
+
var _query;
|
|
1994
2015
|
class OrchidOrmError extends Error {
|
|
1995
2016
|
}
|
|
1996
2017
|
class NotFoundError extends OrchidOrmError {
|
|
@@ -2002,9 +2023,14 @@ class NotFoundError extends OrchidOrmError {
|
|
|
2002
2023
|
class OrchidOrmInternalError extends Error {
|
|
2003
2024
|
constructor(query, message) {
|
|
2004
2025
|
super(message);
|
|
2005
|
-
this
|
|
2026
|
+
__privateAdd(this, _query, void 0);
|
|
2027
|
+
__privateSet(this, _query, query);
|
|
2028
|
+
}
|
|
2029
|
+
get query() {
|
|
2030
|
+
return __privateGet(this, _query);
|
|
2006
2031
|
}
|
|
2007
2032
|
}
|
|
2033
|
+
_query = new WeakMap();
|
|
2008
2034
|
class QueryError extends OrchidOrmInternalError {
|
|
2009
2035
|
get isUnique() {
|
|
2010
2036
|
return this.code === "23505";
|
|
@@ -2034,7 +2060,6 @@ class MoreThanOneRowError extends OrchidOrmInternalError {
|
|
|
2034
2060
|
class UnhandledTypeError extends OrchidOrmInternalError {
|
|
2035
2061
|
constructor(query, value) {
|
|
2036
2062
|
super(query, `Unhandled type: ${JSON.stringify(value)} received`);
|
|
2037
|
-
this.query = query;
|
|
2038
2063
|
}
|
|
2039
2064
|
}
|
|
2040
2065
|
|
|
@@ -2950,16 +2975,9 @@ class ArrayColumn extends ColumnType {
|
|
|
2950
2975
|
this.dataType = "array";
|
|
2951
2976
|
this.operators = Operators.array;
|
|
2952
2977
|
this.parseFn = Object.assign(
|
|
2953
|
-
(
|
|
2978
|
+
(source) => {
|
|
2954
2979
|
const entries = [];
|
|
2955
|
-
|
|
2956
|
-
input,
|
|
2957
|
-
0,
|
|
2958
|
-
input.length,
|
|
2959
|
-
entries,
|
|
2960
|
-
false,
|
|
2961
|
-
this.data.item
|
|
2962
|
-
);
|
|
2980
|
+
parsePostgresArray(source, entries, this.data.item.parseItem);
|
|
2963
2981
|
return entries;
|
|
2964
2982
|
},
|
|
2965
2983
|
{
|
|
@@ -2991,70 +3009,60 @@ class ArrayColumn extends ColumnType {
|
|
|
2991
3009
|
return columnCode(this, ctx, key, code);
|
|
2992
3010
|
}
|
|
2993
3011
|
}
|
|
2994
|
-
const
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3012
|
+
const parsePostgresArray = (source, entries, transform) => {
|
|
3013
|
+
let pos = 0;
|
|
3014
|
+
if (source[0] === "[") {
|
|
3015
|
+
pos = source.indexOf("=") + 1;
|
|
3016
|
+
if (!pos)
|
|
3017
|
+
pos = source.length;
|
|
3018
|
+
}
|
|
3019
|
+
if (source[pos] === "{")
|
|
3020
|
+
pos++;
|
|
3021
|
+
let recorded = "";
|
|
3022
|
+
while (pos < source.length) {
|
|
3023
|
+
const character = source[pos++];
|
|
3024
|
+
if (character === "{") {
|
|
3025
|
+
const innerEntries = [];
|
|
3026
|
+
entries.push(innerEntries);
|
|
3027
|
+
pos += parsePostgresArray(source.slice(pos - 1), innerEntries, transform) - 1;
|
|
3028
|
+
} else if (character === "}") {
|
|
3029
|
+
if (recorded) {
|
|
3030
|
+
entries.push(
|
|
3031
|
+
recorded === "NULL" ? null : transform ? transform(recorded) : recorded
|
|
3032
|
+
);
|
|
3000
3033
|
}
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
if (escaped) {
|
|
3011
|
-
char = input[pos++];
|
|
3012
|
-
}
|
|
3013
|
-
if (char === '"' && !escaped) {
|
|
3014
|
-
if (quote) {
|
|
3015
|
-
pushEntry(input, start, pos, entries, item);
|
|
3016
|
-
} else {
|
|
3017
|
-
start = pos;
|
|
3018
|
-
}
|
|
3019
|
-
quote = !quote;
|
|
3020
|
-
} else if (char === "," && !quote) {
|
|
3021
|
-
if (start !== pos) {
|
|
3022
|
-
pushEntry(input, start, pos, entries, item);
|
|
3023
|
-
}
|
|
3024
|
-
start = pos;
|
|
3025
|
-
} else if (char === "{" && !quote) {
|
|
3026
|
-
let array;
|
|
3027
|
-
let nestedItem = item;
|
|
3028
|
-
if (nested) {
|
|
3029
|
-
array = [];
|
|
3030
|
-
entries.push(array);
|
|
3031
|
-
if ("item" in item.data) {
|
|
3032
|
-
nestedItem = item.data.item;
|
|
3034
|
+
return pos;
|
|
3035
|
+
} else if (character === '"') {
|
|
3036
|
+
let esc = false;
|
|
3037
|
+
let rec = "";
|
|
3038
|
+
while (pos < source.length) {
|
|
3039
|
+
let char;
|
|
3040
|
+
while ((char = source[pos++]) === "\\") {
|
|
3041
|
+
if (!(esc = !esc))
|
|
3042
|
+
rec += "\\";
|
|
3033
3043
|
}
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3044
|
+
if (esc) {
|
|
3045
|
+
esc = false;
|
|
3046
|
+
} else if (char === '"') {
|
|
3047
|
+
break;
|
|
3048
|
+
}
|
|
3049
|
+
rec += char;
|
|
3050
|
+
}
|
|
3051
|
+
entries.push(transform ? transform(rec) : rec);
|
|
3052
|
+
recorded = "";
|
|
3053
|
+
} else if (character === ",") {
|
|
3054
|
+
if (recorded) {
|
|
3055
|
+
entries.push(
|
|
3056
|
+
recorded === "NULL" ? null : transform ? transform(recorded) : recorded
|
|
3057
|
+
);
|
|
3058
|
+
recorded = "";
|
|
3042
3059
|
}
|
|
3043
|
-
|
|
3044
|
-
|
|
3060
|
+
} else {
|
|
3061
|
+
recorded += character;
|
|
3045
3062
|
}
|
|
3046
3063
|
}
|
|
3047
3064
|
return pos;
|
|
3048
3065
|
};
|
|
3049
|
-
const pushEntry = (input, start, pos, entries, item) => {
|
|
3050
|
-
let entry = input.slice(start, pos - 1);
|
|
3051
|
-
if (entry === "NULL") {
|
|
3052
|
-
entry = null;
|
|
3053
|
-
} else if (item.parseItem) {
|
|
3054
|
-
entry = item.parseItem(entry);
|
|
3055
|
-
}
|
|
3056
|
-
entries.push(entry);
|
|
3057
|
-
};
|
|
3058
3066
|
|
|
3059
3067
|
const parseDateToNumber = (value) => value ? Date.parse(value) : value;
|
|
3060
3068
|
const parseDateToDate = (value) => value ? new Date(value) : value;
|
|
@@ -4512,8 +4520,10 @@ const maybeUnNameColumn = (column, isSubQuery) => {
|
|
|
4512
4520
|
return isSubQuery && (column == null ? void 0 : column.data.name) ? orchidCore.setColumnData(column, "name", void 0) : column;
|
|
4513
4521
|
};
|
|
4514
4522
|
function _querySelect(q, args) {
|
|
4523
|
+
var _a, _b;
|
|
4515
4524
|
const len = args.length;
|
|
4516
4525
|
if (!len) {
|
|
4526
|
+
(_b = (_a = q.q).select) != null ? _b : _a.select = [];
|
|
4517
4527
|
return q;
|
|
4518
4528
|
}
|
|
4519
4529
|
const as = q.q.as || q.table;
|
|
@@ -4806,7 +4816,9 @@ function queryJson(self, coalesce) {
|
|
|
4806
4816
|
}
|
|
4807
4817
|
|
|
4808
4818
|
const pushSelectSql = (ctx, table, query, quotedAs) => {
|
|
4809
|
-
|
|
4819
|
+
const sql = selectToSql(ctx, table, query, quotedAs);
|
|
4820
|
+
if (sql)
|
|
4821
|
+
ctx.sql.push(sql);
|
|
4810
4822
|
};
|
|
4811
4823
|
const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect) => {
|
|
4812
4824
|
var _a, _b;
|
|
@@ -4917,7 +4929,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
|
|
|
4917
4929
|
list.push(sql);
|
|
4918
4930
|
}
|
|
4919
4931
|
}
|
|
4920
|
-
return list.length ? list.join(", ") : selectAllSql(table, query, quotedAs);
|
|
4932
|
+
return list.length ? list.join(", ") : query.select ? "" : selectAllSql(table, query, quotedAs);
|
|
4921
4933
|
};
|
|
4922
4934
|
function selectedObjectToSQL(ctx, quotedAs, item) {
|
|
4923
4935
|
const sql = item.toSQL(ctx, quotedAs);
|