pqb 0.67.6 → 0.68.0
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 +564 -223
- package/dist/index.js +40 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -12
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +557 -227
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -315,6 +315,29 @@ const templateLiteralSQLToCode = (sql) => {
|
|
|
315
315
|
code += parts[i];
|
|
316
316
|
return code + "`";
|
|
317
317
|
};
|
|
318
|
+
var SqlJoinExpression = class extends Expression {
|
|
319
|
+
constructor(items, separator) {
|
|
320
|
+
super();
|
|
321
|
+
this.items = items;
|
|
322
|
+
this.separator = separator;
|
|
323
|
+
this.result = { value: emptyObject };
|
|
324
|
+
this.q = { expr: this };
|
|
325
|
+
}
|
|
326
|
+
makeSQL(ctx, quotedAs) {
|
|
327
|
+
let sql = "";
|
|
328
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
329
|
+
if (i > 0) sql += this.separator ? this.separator.toSQL(ctx, quotedAs) : ", ";
|
|
330
|
+
const item = this.items[i];
|
|
331
|
+
if (item instanceof Expression) sql += item.toSQL(ctx, quotedAs);
|
|
332
|
+
else {
|
|
333
|
+
ctx.values.push(item);
|
|
334
|
+
sql += `$${ctx.values.length}`;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return sql;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
SqlJoinExpression.prototype.type = ExpressionTypeMethod.prototype.type;
|
|
318
341
|
/**
|
|
319
342
|
* Expression for a SQL identifier reference.
|
|
320
343
|
* Used to safely quote identifiers in raw SQL queries.
|
|
@@ -435,6 +458,7 @@ const sqlFn = ((...args) => {
|
|
|
435
458
|
return (...args) => new RawSql(args, arg);
|
|
436
459
|
});
|
|
437
460
|
sqlFn.ref = (name) => new SqlRefExpression(name);
|
|
461
|
+
sqlFn.join = (items, separator) => new SqlJoinExpression(items, separator);
|
|
438
462
|
sqlFn.unsafe = (sql) => new UnsafeSqlExpression(sql);
|
|
439
463
|
var UnsafeSqlExpression = class extends Expression {
|
|
440
464
|
constructor(sql) {
|
|
@@ -1849,9 +1873,11 @@ const ordinalText = {
|
|
|
1849
1873
|
};
|
|
1850
1874
|
const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
1851
1875
|
const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${options?.vars ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : options?.silent ? ", NULL, true" : ""})`;
|
|
1876
|
+
const shouldEncodeJson = (ctx) => ctx.q.adapter.driverAdapter.schemaConfig?.jsonEncodedByDriver === false;
|
|
1852
1877
|
const quoteJsonValue = (arg, ctx, quotedAs, IN) => {
|
|
1853
1878
|
if (arg && typeof arg === "object") {
|
|
1854
|
-
if (IN && Array.isArray(arg)) return `(${arg.map((value) => addValue(ctx.values, JSON.stringify(value))
|
|
1879
|
+
if (IN && Array.isArray(arg)) return `(${arg.map((value) => shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(value)) : addValue(ctx.values, value)).join(", ")})`;
|
|
1880
|
+
if (Array.isArray(arg)) return shouldEncodeJson(ctx) ? addValue(ctx.values, JSON.stringify(arg)) : addValue(ctx.values, arg);
|
|
1855
1881
|
if (isExpression(arg)) return "to_jsonb(" + arg.toSQL(ctx, quotedAs) + ")";
|
|
1856
1882
|
if ("toSQL" in arg) return `to_jsonb((${moveMutativeQueryToCte$1(ctx, arg)}))`;
|
|
1857
1883
|
}
|
|
@@ -2036,8 +2062,8 @@ var IntervalColumn = class extends Column {
|
|
|
2036
2062
|
}
|
|
2037
2063
|
};
|
|
2038
2064
|
var ArrayColumn = class ArrayColumn extends Column {
|
|
2039
|
-
constructor(schema, item,
|
|
2040
|
-
super(schema,
|
|
2065
|
+
constructor(schema, item, __inputType, defaultEncode, __outputType, __queryType) {
|
|
2066
|
+
super(schema, __inputType, __outputType, __queryType);
|
|
2041
2067
|
this.dataType = "array";
|
|
2042
2068
|
this.operators = Operators.array;
|
|
2043
2069
|
item.data.isNullable = true;
|
|
@@ -2117,8 +2143,8 @@ const parsePostgresArray = (source, entries, transform) => {
|
|
|
2117
2143
|
};
|
|
2118
2144
|
const encodeJson = (x) => x === null ? x : JSON.stringify(x);
|
|
2119
2145
|
var JSONColumn = class extends Column {
|
|
2120
|
-
constructor(schema,
|
|
2121
|
-
super(schema,
|
|
2146
|
+
constructor(schema, __inputType, encodedByDriver = true) {
|
|
2147
|
+
super(schema, __inputType);
|
|
2122
2148
|
this.dataType = "jsonb";
|
|
2123
2149
|
this.operators = Operators.json;
|
|
2124
2150
|
if (!encodedByDriver) this.data.encode = encodeJson;
|
|
@@ -2130,10 +2156,10 @@ var JSONColumn = class extends Column {
|
|
|
2130
2156
|
};
|
|
2131
2157
|
var JSONTextColumn = class JSONTextColumn extends Column {
|
|
2132
2158
|
static get instance() {
|
|
2133
|
-
return this._instance ??= new JSONTextColumn(internalSchemaConfig);
|
|
2159
|
+
return this._instance ??= new JSONTextColumn(internalSchemaConfig, void 0);
|
|
2134
2160
|
}
|
|
2135
|
-
constructor(schema) {
|
|
2136
|
-
super(schema,
|
|
2161
|
+
constructor(schema, __inputType) {
|
|
2162
|
+
super(schema, __inputType);
|
|
2137
2163
|
this.dataType = "json";
|
|
2138
2164
|
this.operators = Operators.text;
|
|
2139
2165
|
}
|
|
@@ -2344,6 +2370,9 @@ const defaultSchemaConfig = (options) => {
|
|
|
2344
2370
|
json() {
|
|
2345
2371
|
return new JSONColumn(schemaConfig, void 0, options?.jsonEncodedByDriver);
|
|
2346
2372
|
},
|
|
2373
|
+
jsonText() {
|
|
2374
|
+
return new JSONTextColumn(schemaConfig, void 0);
|
|
2375
|
+
},
|
|
2347
2376
|
setErrors: noop,
|
|
2348
2377
|
smallint: () => new SmallIntColumn(schemaConfig),
|
|
2349
2378
|
integer: () => new IntegerColumn(schemaConfig),
|
|
@@ -2972,9 +3001,7 @@ const makeColumnTypes = (schema) => {
|
|
|
2972
3001
|
return new XMLColumn(schema);
|
|
2973
3002
|
},
|
|
2974
3003
|
json: schema.json,
|
|
2975
|
-
jsonText
|
|
2976
|
-
return new JSONTextColumn(schema);
|
|
2977
|
-
},
|
|
3004
|
+
jsonText: schema.jsonText,
|
|
2978
3005
|
type(dataType) {
|
|
2979
3006
|
return new CustomTypeColumn(schema, dataType);
|
|
2980
3007
|
},
|
|
@@ -11122,7 +11149,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
|
|
|
11122
11149
|
if (returnType === "value" || returnType === "valueOrThrow") {
|
|
11123
11150
|
const type = it.q.getColumn;
|
|
11124
11151
|
result[key] = type ? mapSubSelectColumn(type, isSubQuery) : UnknownColumn.instance;
|
|
11125
|
-
} else result[key] = new JSONTextColumn(internalSchemaConfig);
|
|
11152
|
+
} else result[key] = new JSONTextColumn(internalSchemaConfig, void 0);
|
|
11126
11153
|
}
|
|
11127
11154
|
}
|
|
11128
11155
|
}
|
|
@@ -14236,6 +14263,7 @@ function _createDbSqlMethod(columnTypes) {
|
|
|
14236
14263
|
return sql;
|
|
14237
14264
|
});
|
|
14238
14265
|
fn.ref = sqlFn.ref;
|
|
14266
|
+
fn.join = sqlFn.join;
|
|
14239
14267
|
fn.unsafe = sqlFn.unsafe;
|
|
14240
14268
|
return fn;
|
|
14241
14269
|
}
|