pqb 0.31.9 → 0.33.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 +233 -284
- package/dist/index.js +80 -245
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -245
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -879,6 +879,25 @@ const make = (_op) => {
|
|
|
879
879
|
return setQueryOperators(this, boolean);
|
|
880
880
|
},
|
|
881
881
|
{
|
|
882
|
+
// function to turn the operator expression into SQL
|
|
883
|
+
_op
|
|
884
|
+
}
|
|
885
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
886
|
+
);
|
|
887
|
+
};
|
|
888
|
+
const makeVarArg = (_op) => {
|
|
889
|
+
return Object.assign(
|
|
890
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
891
|
+
function(...args) {
|
|
892
|
+
var _a, _b, _c;
|
|
893
|
+
((_b = (_a = this.q).chain) != null ? _b : _a.chain = []).push(_op, args);
|
|
894
|
+
if ((_c = this.q.parsers) == null ? void 0 : _c[getValueKey]) {
|
|
895
|
+
this.q.parsers[getValueKey] = void 0;
|
|
896
|
+
}
|
|
897
|
+
return setQueryOperators(this, boolean);
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
// function to turn the operator expression into SQL
|
|
882
901
|
_op
|
|
883
902
|
}
|
|
884
903
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -961,15 +980,51 @@ const text = __spreadProps$7(__spreadValues$f({}, base), {
|
|
|
961
980
|
(key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteValue$1(value, ctx, quotedAs)}`
|
|
962
981
|
)
|
|
963
982
|
});
|
|
983
|
+
const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
|
|
984
|
+
const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${(options == null ? void 0 : options.vars) ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : (options == null ? void 0 : options.silent) ? ", NULL, true" : ""})`;
|
|
964
985
|
const json = __spreadProps$7(__spreadValues$f({}, base), {
|
|
965
|
-
|
|
966
|
-
(
|
|
986
|
+
jsonPathQueryFirst: Object.assign(
|
|
987
|
+
function(path, options) {
|
|
988
|
+
var _a, _b, _c, _d, _e;
|
|
989
|
+
((_b = (_a = this.q).chain) != null ? _b : _a.chain = []).push(jsonPathQueryOp, [path, options]);
|
|
990
|
+
if ((_c = this.q.parsers) == null ? void 0 : _c[getValueKey]) {
|
|
991
|
+
this.q.parsers[getValueKey] = void 0;
|
|
992
|
+
}
|
|
993
|
+
if (options == null ? void 0 : options.type) {
|
|
994
|
+
const parse = options.type(this.columnTypes).parseFn;
|
|
995
|
+
if (parse)
|
|
996
|
+
((_e = (_d = this.q).parsers) != null ? _e : _d.parsers = {})[getValueKey] = parse;
|
|
997
|
+
}
|
|
998
|
+
return this;
|
|
999
|
+
},
|
|
1000
|
+
{ _op: jsonPathQueryOp }
|
|
967
1001
|
),
|
|
968
1002
|
jsonSupersetOf: make(
|
|
969
1003
|
(key, value, ctx, quotedAs) => `${key} @> ${quoteValue$1(value, ctx, quotedAs, true)}`
|
|
970
1004
|
),
|
|
971
1005
|
jsonSubsetOf: make(
|
|
972
1006
|
(key, value, ctx, quotedAs) => `${key} <@ ${quoteValue$1(value, ctx, quotedAs, true)}`
|
|
1007
|
+
),
|
|
1008
|
+
jsonSet: makeVarArg(
|
|
1009
|
+
(key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${addValue(
|
|
1010
|
+
ctx.values,
|
|
1011
|
+
JSON.stringify(value)
|
|
1012
|
+
)})`
|
|
1013
|
+
),
|
|
1014
|
+
jsonReplace: makeVarArg(
|
|
1015
|
+
(key, [path, value], ctx) => `jsonb_set(${key}, ${encodeJsonPath(ctx, path)}, ${addValue(
|
|
1016
|
+
ctx.values,
|
|
1017
|
+
JSON.stringify(value)
|
|
1018
|
+
)}, false)`
|
|
1019
|
+
),
|
|
1020
|
+
jsonInsert: makeVarArg(
|
|
1021
|
+
(key, [path, value, options], ctx) => `jsonb_insert(${key}, ${encodeJsonPath(ctx, path)}, ${addValue(
|
|
1022
|
+
ctx.values,
|
|
1023
|
+
JSON.stringify(value)
|
|
1024
|
+
)}${(options == null ? void 0 : options.after) ? ", true" : ""})`
|
|
1025
|
+
),
|
|
1026
|
+
jsonRemove: makeVarArg(
|
|
1027
|
+
(key, [path], ctx) => `(${key} #- ${encodeJsonPath(ctx, path)})`
|
|
973
1028
|
)
|
|
974
1029
|
});
|
|
975
1030
|
const Operators = {
|
|
@@ -1738,7 +1793,8 @@ class BooleanColumn extends ColumnType {
|
|
|
1738
1793
|
}
|
|
1739
1794
|
}
|
|
1740
1795
|
|
|
1741
|
-
const
|
|
1796
|
+
const encodeFn = (x) => x === null ? x : JSON.stringify(x);
|
|
1797
|
+
const toCodeSkip = { encodeFn };
|
|
1742
1798
|
class JSONColumn extends ColumnType {
|
|
1743
1799
|
constructor() {
|
|
1744
1800
|
super(...arguments);
|
|
@@ -1749,7 +1805,7 @@ class JSONColumn extends ColumnType {
|
|
|
1749
1805
|
return columnCode(this, t, `json()`, m, this.data, toCodeSkip);
|
|
1750
1806
|
}
|
|
1751
1807
|
}
|
|
1752
|
-
JSONColumn.prototype.encodeFn =
|
|
1808
|
+
JSONColumn.prototype.encodeFn = encodeFn;
|
|
1753
1809
|
class JSONTextColumn extends ColumnType {
|
|
1754
1810
|
constructor(schema) {
|
|
1755
1811
|
super(schema, schema.stringSchema());
|
|
@@ -2074,9 +2130,13 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
|
|
|
2074
2130
|
if ("prototype" in data || "baseQuery" in data) {
|
|
2075
2131
|
const query2 = data;
|
|
2076
2132
|
if (query2.q.expr) {
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2133
|
+
if (query2.q.subQuery === 1) {
|
|
2134
|
+
ands.push(selectToSql(ctx, table, query2.q, quotedAs));
|
|
2135
|
+
} else {
|
|
2136
|
+
const q = joinSubQuery(table, query2);
|
|
2137
|
+
q.q.select = [query2.q.expr];
|
|
2138
|
+
ands.push(`(${getSqlText(makeSQL(q, ctx))})`);
|
|
2139
|
+
}
|
|
2080
2140
|
} else {
|
|
2081
2141
|
pushWhereToSql(
|
|
2082
2142
|
ands,
|
|
@@ -3607,7 +3667,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
|
|
|
3607
3667
|
(q2) => q2,
|
|
3608
3668
|
key
|
|
3609
3669
|
);
|
|
3610
|
-
} else if (((_d = value.q) == null ? void 0 : _d.
|
|
3670
|
+
} else if (((_d = value.q) == null ? void 0 : _d.subQuery) && value.q.expr) {
|
|
3611
3671
|
value = value.q.expr;
|
|
3612
3672
|
}
|
|
3613
3673
|
}
|
|
@@ -3782,7 +3842,7 @@ class SelectItemExpression extends Expression {
|
|
|
3782
3842
|
// except that it will use non-aliasing `columnToSql` when `ctx.aliasValue` is true,
|
|
3783
3843
|
// it is needed for relation sub-queries that returns a single column.
|
|
3784
3844
|
makeSQL(ctx, quotedAs) {
|
|
3785
|
-
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(this.query, this.q, quotedAs) : ctx.aliasValue ? columnToSql(ctx, this.q, this.q.shape, this.item, quotedAs, true) : columnToSqlWithAs(ctx, this.q, this.item, quotedAs, true) : selectedObjectToSQL(ctx,
|
|
3845
|
+
return typeof this.item === "string" ? this.item === "*" ? selectAllSql(this.query, this.q, quotedAs) : ctx.aliasValue ? columnToSql(ctx, this.q, this.q.shape, this.item, quotedAs, true) : columnToSqlWithAs(ctx, this.q, this.item, quotedAs, true) : selectedObjectToSQL(ctx, quotedAs, this.item);
|
|
3786
3846
|
}
|
|
3787
3847
|
}
|
|
3788
3848
|
|
|
@@ -3990,50 +4050,6 @@ function queryJson(self, coalesce) {
|
|
|
3990
4050
|
return q;
|
|
3991
4051
|
}
|
|
3992
4052
|
|
|
3993
|
-
const jsonColumnOrMethodToSql = (ctx, table, column, values, quotedAs) => {
|
|
3994
|
-
return typeof column === "string" ? columnToSql(ctx, table.q, table.q.shape, column, quotedAs) : jsonToSql(ctx, table, column, values, quotedAs);
|
|
3995
|
-
};
|
|
3996
|
-
const jsonToSql = (ctx, table, item, values, quotedAs) => {
|
|
3997
|
-
const json = item.__json;
|
|
3998
|
-
if (json[0] === "pathQuery") {
|
|
3999
|
-
const [, , , column, path, options] = json;
|
|
4000
|
-
return `jsonb_path_query(${jsonColumnOrMethodToSql(
|
|
4001
|
-
ctx,
|
|
4002
|
-
table,
|
|
4003
|
-
column,
|
|
4004
|
-
values,
|
|
4005
|
-
quotedAs
|
|
4006
|
-
)}, ${addValue(values, path)}${(options == null ? void 0 : options.vars) ? `, ${addValue(values, options.vars)}` : ""}${(options == null ? void 0 : options.silent) ? ", true" : ""})`;
|
|
4007
|
-
} else if (json[0] === "set") {
|
|
4008
|
-
const [, , , column, path, value, options] = json;
|
|
4009
|
-
return `jsonb_set(${jsonColumnOrMethodToSql(
|
|
4010
|
-
ctx,
|
|
4011
|
-
table,
|
|
4012
|
-
column,
|
|
4013
|
-
values,
|
|
4014
|
-
quotedAs
|
|
4015
|
-
)}, '{${path.join(", ")}}', ${addValue(values, JSON.stringify(value))}${(options == null ? void 0 : options.createIfMissing) ? ", true" : ""})`;
|
|
4016
|
-
} else if (json[0] === "insert") {
|
|
4017
|
-
const [, , , column, path, value, options] = json;
|
|
4018
|
-
return `jsonb_insert(${jsonColumnOrMethodToSql(
|
|
4019
|
-
ctx,
|
|
4020
|
-
table,
|
|
4021
|
-
column,
|
|
4022
|
-
values,
|
|
4023
|
-
quotedAs
|
|
4024
|
-
)}, '{${path.join(", ")}}', ${addValue(values, JSON.stringify(value))}${(options == null ? void 0 : options.insertAfter) ? ", true" : ""})`;
|
|
4025
|
-
} else if (json[0] === "remove") {
|
|
4026
|
-
const [, , , column, path] = json;
|
|
4027
|
-
return `${jsonColumnOrMethodToSql(
|
|
4028
|
-
ctx,
|
|
4029
|
-
table,
|
|
4030
|
-
column,
|
|
4031
|
-
values,
|
|
4032
|
-
quotedAs
|
|
4033
|
-
)} #- '{${path.join(", ")}}'`;
|
|
4034
|
-
}
|
|
4035
|
-
return "";
|
|
4036
|
-
};
|
|
4037
4053
|
const pushSelectSql = (ctx, table, query, quotedAs) => {
|
|
4038
4054
|
ctx.sql.push(selectToSql(ctx, table, query, quotedAs));
|
|
4039
4055
|
};
|
|
@@ -4067,7 +4083,7 @@ const selectToSql = (ctx, table, query, quotedAs) => {
|
|
|
4067
4083
|
}
|
|
4068
4084
|
}
|
|
4069
4085
|
} else {
|
|
4070
|
-
list.push(selectedObjectToSQL(ctx,
|
|
4086
|
+
list.push(selectedObjectToSQL(ctx, quotedAs, item));
|
|
4071
4087
|
}
|
|
4072
4088
|
}
|
|
4073
4089
|
return list.join(", ");
|
|
@@ -4075,10 +4091,7 @@ const selectToSql = (ctx, table, query, quotedAs) => {
|
|
|
4075
4091
|
return selectAllSql(table, query, quotedAs);
|
|
4076
4092
|
};
|
|
4077
4093
|
const selectedStringToSQL = (ctx, table, query, quotedAs, item) => item === "*" ? selectAllSql(table, query, quotedAs) : columnToSqlWithAs(ctx, table.q, item, quotedAs, true);
|
|
4078
|
-
function selectedObjectToSQL(ctx,
|
|
4079
|
-
if ("__json" in item) {
|
|
4080
|
-
return `${jsonToSql(ctx, table, item, ctx.values, quotedAs)} "${item.__json[1]}"`;
|
|
4081
|
-
}
|
|
4094
|
+
function selectedObjectToSQL(ctx, quotedAs, item) {
|
|
4082
4095
|
const sql = item.toSQL(ctx, quotedAs);
|
|
4083
4096
|
return ctx.aliasValue ? `${sql} r` : sql;
|
|
4084
4097
|
}
|
|
@@ -4768,11 +4781,12 @@ const processData = (ctx, table, set, data, quotedAs) => {
|
|
|
4768
4781
|
};
|
|
4769
4782
|
const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
|
|
4770
4783
|
if (value && typeof value === "object") {
|
|
4771
|
-
if (value
|
|
4772
|
-
return jsonToSql(ctx, table, value, ctx.values, quotedAs);
|
|
4773
|
-
} else if (isExpression(value)) {
|
|
4784
|
+
if (isExpression(value)) {
|
|
4774
4785
|
return value.toSQL(ctx, quotedAs);
|
|
4775
4786
|
} else if (value instanceof QueryClass) {
|
|
4787
|
+
if (value.q.subQuery === 1) {
|
|
4788
|
+
return selectToSql(ctx, table, value.q, quotedAs);
|
|
4789
|
+
}
|
|
4776
4790
|
return `(${getSqlText(
|
|
4777
4791
|
joinSubQuery(table, value).toSQL(ctx)
|
|
4778
4792
|
)})`;
|
|
@@ -5198,11 +5212,11 @@ const makeRegexToFindInSql = (value) => {
|
|
|
5198
5212
|
return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
|
|
5199
5213
|
};
|
|
5200
5214
|
const resolveSubQueryCallback = (q, cb) => {
|
|
5201
|
-
const {
|
|
5202
|
-
q.q.
|
|
5215
|
+
const { subQuery, relChain } = q.q;
|
|
5216
|
+
q.q.subQuery = 1;
|
|
5203
5217
|
q.q.relChain = void 0;
|
|
5204
5218
|
const result = cb(q);
|
|
5205
|
-
q.q.
|
|
5219
|
+
q.q.subQuery = subQuery;
|
|
5206
5220
|
q.q.relChain = relChain;
|
|
5207
5221
|
return result;
|
|
5208
5222
|
};
|
|
@@ -6652,7 +6666,7 @@ class Create {
|
|
|
6652
6666
|
* const createdCount = await db.table.insertMany([data, data, data]);
|
|
6653
6667
|
* ```
|
|
6654
6668
|
*
|
|
6655
|
-
* Because of a limitation of Postgres protocol, queries having more than **
|
|
6669
|
+
* Because of a limitation of Postgres protocol, queries having more than **65535** of values are going to fail in runtime.
|
|
6656
6670
|
* To solve this seamlessly, OrchidORM will automatically batch such queries, and wrap them into a transaction, unless they are already in a transaction.
|
|
6657
6671
|
*
|
|
6658
6672
|
* ```ts
|
|
@@ -8274,183 +8288,6 @@ class OnMethods {
|
|
|
8274
8288
|
}
|
|
8275
8289
|
}
|
|
8276
8290
|
|
|
8277
|
-
class JsonModifiers {
|
|
8278
|
-
/**
|
|
8279
|
-
* Return a JSON value/object/array where a given value is set at the given path.
|
|
8280
|
-
* The path is an array of keys to access the value.
|
|
8281
|
-
*
|
|
8282
|
-
* Can be used in `update` callback.
|
|
8283
|
-
*
|
|
8284
|
-
* ```ts
|
|
8285
|
-
* const result = await db.table.jsonSet('data', ['name'], 'new value').take();
|
|
8286
|
-
*
|
|
8287
|
-
* expect(result.data).toEqual({ name: 'new value' });
|
|
8288
|
-
* ```
|
|
8289
|
-
*
|
|
8290
|
-
* Optionally takes parameters of type `{ as?: string, createIfMissing?: boolean }`
|
|
8291
|
-
*
|
|
8292
|
-
* ```ts
|
|
8293
|
-
* await db.table.jsonSet('data', ['name'], 'new value', {
|
|
8294
|
-
* as: 'alias', // select data as `alias`
|
|
8295
|
-
* createIfMissing: true, // ignored if missing by default
|
|
8296
|
-
* });
|
|
8297
|
-
* ```
|
|
8298
|
-
*
|
|
8299
|
-
* @param column - name of JSON column, or a result of a nested json method
|
|
8300
|
-
* @param path - path to value inside the json
|
|
8301
|
-
* @param value - value to set into the json
|
|
8302
|
-
* @param options - `as` to alias the json value when selecting, `createIfMissing: true` will create a new JSON property if it didn't exist before
|
|
8303
|
-
*/
|
|
8304
|
-
jsonSet(column, path, value, options) {
|
|
8305
|
-
var _a;
|
|
8306
|
-
const q = this.clone();
|
|
8307
|
-
const json = {
|
|
8308
|
-
__json: [
|
|
8309
|
-
"set",
|
|
8310
|
-
(_a = options == null ? void 0 : options.as) != null ? _a : typeof column === "string" ? column : column.__json[1],
|
|
8311
|
-
typeof column === "string" ? q.q.shape[column] : column.__json[2],
|
|
8312
|
-
column,
|
|
8313
|
-
path,
|
|
8314
|
-
value,
|
|
8315
|
-
options
|
|
8316
|
-
]
|
|
8317
|
-
};
|
|
8318
|
-
return Object.assign(pushQueryValue(q, "select", json), json);
|
|
8319
|
-
}
|
|
8320
|
-
/**
|
|
8321
|
-
* Return a JSON value/object/array where a given value is inserted at the given JSON path. Value can be a single value or JSON object. If a value exists at the given path, the value is not replaced.
|
|
8322
|
-
*
|
|
8323
|
-
* Can be used in `update` callback.
|
|
8324
|
-
*
|
|
8325
|
-
* ```ts
|
|
8326
|
-
* // imagine user has data = { tags: ['two'] }
|
|
8327
|
-
* const result = await db.table.jsonInsert('data', ['tags', 0], 'one').take();
|
|
8328
|
-
*
|
|
8329
|
-
* // 'one' is inserted to 0 position
|
|
8330
|
-
* expect(result.data).toEqual({ tags: ['one', 'two'] });
|
|
8331
|
-
* ```
|
|
8332
|
-
*
|
|
8333
|
-
* Optionally takes parameters of type `{ as?: string, insertAfter?: boolean }`
|
|
8334
|
-
*
|
|
8335
|
-
* ```ts
|
|
8336
|
-
* // imagine user has data = { tags: ['one'] }
|
|
8337
|
-
* const result = await db.table
|
|
8338
|
-
* .jsonInsert('data', ['tags', 0], 'two', {
|
|
8339
|
-
* as: 'alias', // select as an alias
|
|
8340
|
-
* insertAfter: true, // insert after the specified position
|
|
8341
|
-
* })
|
|
8342
|
-
* .take();
|
|
8343
|
-
*
|
|
8344
|
-
* // 'one' is inserted to 0 position
|
|
8345
|
-
* expect(result.alias).toEqual({ tags: ['one', 'two'] });
|
|
8346
|
-
* ```
|
|
8347
|
-
* @param column - name of JSON column, or a result of a nested json method
|
|
8348
|
-
* @param path - path to the array inside the json, last path element is index to insert into
|
|
8349
|
-
* @param value - value to insert into the json array
|
|
8350
|
-
* @param options - `as` to alias the json value when selecting, `insertAfter: true` to insert after the specified position
|
|
8351
|
-
*/
|
|
8352
|
-
jsonInsert(column, path, value, options) {
|
|
8353
|
-
var _a;
|
|
8354
|
-
const q = this.clone();
|
|
8355
|
-
const json = {
|
|
8356
|
-
__json: [
|
|
8357
|
-
"insert",
|
|
8358
|
-
(_a = options == null ? void 0 : options.as) != null ? _a : typeof column === "string" ? column : column.__json[1],
|
|
8359
|
-
typeof column === "string" ? q.q.shape[column] : column.__json[2],
|
|
8360
|
-
column,
|
|
8361
|
-
path,
|
|
8362
|
-
value,
|
|
8363
|
-
options
|
|
8364
|
-
]
|
|
8365
|
-
};
|
|
8366
|
-
return Object.assign(pushQueryValue(q, "select", json), json);
|
|
8367
|
-
}
|
|
8368
|
-
/**
|
|
8369
|
-
* Return a JSON value/object/array where a given value is removed at the given JSON path.
|
|
8370
|
-
*
|
|
8371
|
-
* Can be used in `update` callback.
|
|
8372
|
-
*
|
|
8373
|
-
* ```ts
|
|
8374
|
-
* // imagine a user has data = { tags: ['one', 'two'] }
|
|
8375
|
-
* const result = await db.table
|
|
8376
|
-
* .jsonRemove(
|
|
8377
|
-
* 'data',
|
|
8378
|
-
* ['tags', 0],
|
|
8379
|
-
* // optional parameters:
|
|
8380
|
-
* {
|
|
8381
|
-
* as: 'alias', // select as an alias
|
|
8382
|
-
* },
|
|
8383
|
-
* )
|
|
8384
|
-
* .take();
|
|
8385
|
-
*
|
|
8386
|
-
* expect(result.alias).toEqual({ tags: ['two'] });
|
|
8387
|
-
* ```
|
|
8388
|
-
*
|
|
8389
|
-
* @param column - name of JSON column, or a result of a nested json method
|
|
8390
|
-
* @param path - path to the array inside the json, last path element is index to remove this element
|
|
8391
|
-
* @param options - `as` to alias the json value when selecting
|
|
8392
|
-
*/
|
|
8393
|
-
jsonRemove(column, path, options) {
|
|
8394
|
-
var _a;
|
|
8395
|
-
const q = this.clone();
|
|
8396
|
-
const json = {
|
|
8397
|
-
__json: [
|
|
8398
|
-
"remove",
|
|
8399
|
-
(_a = options == null ? void 0 : options.as) != null ? _a : typeof column === "string" ? column : column.__json[1],
|
|
8400
|
-
typeof column === "string" ? q.q.shape[column] : column.__json[2],
|
|
8401
|
-
column,
|
|
8402
|
-
path
|
|
8403
|
-
]
|
|
8404
|
-
};
|
|
8405
|
-
return Object.assign(pushQueryValue(q, "select", json), json);
|
|
8406
|
-
}
|
|
8407
|
-
/**
|
|
8408
|
-
* Selects a value from JSON data using a JSON path.
|
|
8409
|
-
*
|
|
8410
|
-
* ```ts
|
|
8411
|
-
* import { columnTypes } from 'orchid-orm';
|
|
8412
|
-
*
|
|
8413
|
-
* db.table.jsonPathQuery(
|
|
8414
|
-
* columnTypes.text(3, 100), // type of the value
|
|
8415
|
-
* 'data', // name of the JSON column
|
|
8416
|
-
* '$.name', // JSON path
|
|
8417
|
-
* 'name', // select value as name
|
|
8418
|
-
*
|
|
8419
|
-
* // Optionally supports `vars` and `silent` options
|
|
8420
|
-
* // check Postgres docs for jsonb_path_query for details
|
|
8421
|
-
* {
|
|
8422
|
-
* vars: 'vars',
|
|
8423
|
-
* silent: true,
|
|
8424
|
-
* },
|
|
8425
|
-
* );
|
|
8426
|
-
* ```
|
|
8427
|
-
*
|
|
8428
|
-
* Nested JSON operations can be used in place of JSON column name:
|
|
8429
|
-
*
|
|
8430
|
-
* ```ts
|
|
8431
|
-
* db.table.jsonPathQuery(
|
|
8432
|
-
* columnTypes.text(3, 100),
|
|
8433
|
-
* // Available: .jsonSet, .jsonInsert, .jsonRemove
|
|
8434
|
-
* db.table.jsonSet('data', ['key'], 'value'),
|
|
8435
|
-
* '$.name',
|
|
8436
|
-
* 'name',
|
|
8437
|
-
* );
|
|
8438
|
-
* ```
|
|
8439
|
-
*
|
|
8440
|
-
* @param type - provide a column type to have a correct result type
|
|
8441
|
-
* @param column - name of JSON column, or a result of a nested json method
|
|
8442
|
-
* @param path - special JSON path string to reference a JSON value
|
|
8443
|
-
* @param as - optional alias for the selected value
|
|
8444
|
-
* @param options - supports `vars` and `silent`, check Postgres docs of `json_path_query` for these
|
|
8445
|
-
*/
|
|
8446
|
-
jsonPathQuery(type, column, path, as, options) {
|
|
8447
|
-
const q = this.clone();
|
|
8448
|
-
const json = {
|
|
8449
|
-
__json: ["pathQuery", as, type, column, path, options]
|
|
8450
|
-
};
|
|
8451
|
-
return Object.assign(pushQueryValue(q, "select", json), json);
|
|
8452
|
-
}
|
|
8453
|
-
}
|
|
8454
8291
|
class JsonMethods {
|
|
8455
8292
|
/**
|
|
8456
8293
|
* Wraps the query in a way to select a single JSON string.
|
|
@@ -8826,7 +8663,7 @@ const resolveCallbacksInArgs = (q, args) => {
|
|
|
8826
8663
|
const qb = Object.create(q);
|
|
8827
8664
|
qb.q = getClonedQueryData(q.q);
|
|
8828
8665
|
qb.q.and = qb.q.or = qb.q.scopes = void 0;
|
|
8829
|
-
qb.q.
|
|
8666
|
+
qb.q.subQuery = 1;
|
|
8830
8667
|
args[i] = resolveSubQueryCallback(qb, arg);
|
|
8831
8668
|
}
|
|
8832
8669
|
}
|
|
@@ -11539,7 +11376,6 @@ applyMixins(QueryMethods, [
|
|
|
11539
11376
|
OnMethods,
|
|
11540
11377
|
WithMethods,
|
|
11541
11378
|
Union,
|
|
11542
|
-
JsonModifiers,
|
|
11543
11379
|
JsonMethods,
|
|
11544
11380
|
Create,
|
|
11545
11381
|
Update,
|
|
@@ -12134,5 +11970,5 @@ function copyTableData(query, arg) {
|
|
|
12134
11970
|
return q;
|
|
12135
11971
|
}
|
|
12136
11972
|
|
|
12137
|
-
export { Adapter, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods,
|
|
11973
|
+
export { Adapter, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CharColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseResult, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
12138
11974
|
//# sourceMappingURL=index.mjs.map
|