pqb 0.30.7 → 0.31.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 +272 -216
- package/dist/index.js +245 -213
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -212
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3676,15 +3676,16 @@ class AsMethods {
|
|
|
3676
3676
|
}
|
|
3677
3677
|
|
|
3678
3678
|
function queryFrom(self, arg) {
|
|
3679
|
-
var _a;
|
|
3679
|
+
var _a, _b;
|
|
3680
3680
|
const data = self.q;
|
|
3681
3681
|
if (typeof arg === "string") {
|
|
3682
3682
|
data.as || (data.as = arg);
|
|
3683
|
+
data.shape = (_a = data.withShapes) == null ? void 0 : _a[arg];
|
|
3683
3684
|
} else if (orchidCore.isExpression(arg)) {
|
|
3684
3685
|
data.as || (data.as = "t");
|
|
3685
3686
|
} else if (Array.isArray(arg)) {
|
|
3686
3687
|
const { shape } = data;
|
|
3687
|
-
const parsers = (
|
|
3688
|
+
const parsers = (_b = data.parsers) != null ? _b : data.parsers = {};
|
|
3688
3689
|
for (const item of arg) {
|
|
3689
3690
|
if (typeof item === "string") {
|
|
3690
3691
|
const withShape = data.withShapes[item];
|
|
@@ -3714,7 +3715,7 @@ function queryFromSql(self, args) {
|
|
|
3714
3715
|
data.from = sqlQueryArgsToExpression(args);
|
|
3715
3716
|
return self;
|
|
3716
3717
|
}
|
|
3717
|
-
class
|
|
3718
|
+
class FromMethods {
|
|
3718
3719
|
/**
|
|
3719
3720
|
* Set the `FROM` value, by default the table name is used.
|
|
3720
3721
|
*
|
|
@@ -4071,20 +4072,21 @@ const havingToSql = (ctx, query, quotedAs) => {
|
|
|
4071
4072
|
).join(" AND ");
|
|
4072
4073
|
};
|
|
4073
4074
|
|
|
4074
|
-
const pushWithSql = (ctx,
|
|
4075
|
-
if (!
|
|
4075
|
+
const pushWithSql = (ctx, items) => {
|
|
4076
|
+
if (!items.length)
|
|
4076
4077
|
return;
|
|
4077
4078
|
ctx.sql.push(
|
|
4078
4079
|
"WITH",
|
|
4079
|
-
|
|
4080
|
-
|
|
4080
|
+
items.map((item) => {
|
|
4081
|
+
var _a;
|
|
4081
4082
|
let inner;
|
|
4082
|
-
if (
|
|
4083
|
-
inner =
|
|
4083
|
+
if (item.q) {
|
|
4084
|
+
inner = makeSQL(item.q, ctx).text;
|
|
4084
4085
|
} else {
|
|
4085
|
-
inner =
|
|
4086
|
+
inner = item.s.toSQL(ctx, `"${item.n}"`);
|
|
4086
4087
|
}
|
|
4087
|
-
|
|
4088
|
+
const o = (_a = item.o) != null ? _a : orchidCore.emptyObject;
|
|
4089
|
+
return `${o.recursive ? "RECURSIVE " : ""}"${item.n}"${o.columns ? `(${o.columns.map((x) => `"${x}"`).join(", ")})` : ""} AS ${o.materialized ? "MATERIALIZED " : o.notMaterialized ? "NOT MATERIALIZED " : ""}(${inner})`;
|
|
4088
4090
|
}).join(", ")
|
|
4089
4091
|
);
|
|
4090
4092
|
};
|
|
@@ -4766,54 +4768,50 @@ const makeSQL = (table, options) => {
|
|
|
4766
4768
|
}
|
|
4767
4769
|
}
|
|
4768
4770
|
const quotedAs = (query.as || table.table) && `"${query.as || table.table}"`;
|
|
4769
|
-
sql.push("SELECT");
|
|
4770
|
-
if (query.distinct) {
|
|
4771
|
-
pushDistinctSql(ctx, table, query.distinct, quotedAs);
|
|
4772
|
-
}
|
|
4773
|
-
pushSelectSql(ctx, table, query, quotedAs);
|
|
4774
|
-
if (table.table || query.from) {
|
|
4775
|
-
pushFromAndAs(ctx, table, query, quotedAs);
|
|
4776
|
-
}
|
|
4777
|
-
if (query.join) {
|
|
4778
|
-
pushJoinSql(
|
|
4779
|
-
ctx,
|
|
4780
|
-
table,
|
|
4781
|
-
query,
|
|
4782
|
-
quotedAs
|
|
4783
|
-
);
|
|
4784
|
-
}
|
|
4785
|
-
if (query.and || query.or) {
|
|
4786
|
-
pushWhereStatementSql(ctx, table, query, quotedAs);
|
|
4787
|
-
}
|
|
4788
|
-
if (query.group) {
|
|
4789
|
-
const group = query.group.map(
|
|
4790
|
-
(item) => orchidCore.isExpression(item) ? item.toSQL(ctx, quotedAs) : columnToSql(ctx, table.q, table.q.shape, item, quotedAs)
|
|
4791
|
-
);
|
|
4792
|
-
sql.push(`GROUP BY ${group.join(", ")}`);
|
|
4793
|
-
}
|
|
4794
|
-
if (query.having)
|
|
4795
|
-
pushHavingSql(ctx, query, quotedAs);
|
|
4796
|
-
if (query.window) {
|
|
4797
|
-
const window = [];
|
|
4798
|
-
query.window.forEach((item) => {
|
|
4799
|
-
for (const key in item) {
|
|
4800
|
-
window.push(
|
|
4801
|
-
`"${key}" AS ${windowToSql(ctx, query, item[key], quotedAs)}`
|
|
4802
|
-
);
|
|
4803
|
-
}
|
|
4804
|
-
});
|
|
4805
|
-
sql.push(`WINDOW ${window.join(", ")}`);
|
|
4806
|
-
}
|
|
4807
4771
|
if (query.union) {
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4772
|
+
sql.push(`(${makeSQL(query.union.b, { values }).text})`);
|
|
4773
|
+
for (const u of query.union.u) {
|
|
4774
|
+
const itemSql = orchidCore.isExpression(u.a) ? u.a.toSQL(ctx, quotedAs) : makeSQL(u.a, { values }).text;
|
|
4775
|
+
sql.push(`${u.k} (${itemSql})`);
|
|
4776
|
+
}
|
|
4777
|
+
} else {
|
|
4778
|
+
sql.push("SELECT");
|
|
4779
|
+
if (query.distinct) {
|
|
4780
|
+
pushDistinctSql(ctx, table, query.distinct, quotedAs);
|
|
4781
|
+
}
|
|
4782
|
+
pushSelectSql(ctx, table, query, quotedAs);
|
|
4783
|
+
if (table.table || query.from) {
|
|
4784
|
+
pushFromAndAs(ctx, table, query, quotedAs);
|
|
4785
|
+
}
|
|
4786
|
+
if (query.join) {
|
|
4787
|
+
pushJoinSql(
|
|
4788
|
+
ctx,
|
|
4789
|
+
table,
|
|
4790
|
+
query,
|
|
4791
|
+
quotedAs
|
|
4792
|
+
);
|
|
4793
|
+
}
|
|
4794
|
+
if (query.and || query.or) {
|
|
4795
|
+
pushWhereStatementSql(ctx, table, query, quotedAs);
|
|
4796
|
+
}
|
|
4797
|
+
if (query.group) {
|
|
4798
|
+
const group = query.group.map(
|
|
4799
|
+
(item) => orchidCore.isExpression(item) ? item.toSQL(ctx, quotedAs) : columnToSql(ctx, table.q, table.q.shape, item, quotedAs)
|
|
4800
|
+
);
|
|
4801
|
+
sql.push(`GROUP BY ${group.join(", ")}`);
|
|
4802
|
+
}
|
|
4803
|
+
if (query.having)
|
|
4804
|
+
pushHavingSql(ctx, query, quotedAs);
|
|
4805
|
+
if (query.window) {
|
|
4806
|
+
const window = [];
|
|
4807
|
+
query.window.forEach((item) => {
|
|
4808
|
+
for (const key in item) {
|
|
4809
|
+
window.push(
|
|
4810
|
+
`"${key}" AS ${windowToSql(ctx, query, item[key], quotedAs)}`
|
|
4811
|
+
);
|
|
4812
|
+
}
|
|
4813
|
+
});
|
|
4814
|
+
sql.push(`WINDOW ${window.join(", ")}`);
|
|
4817
4815
|
}
|
|
4818
4816
|
}
|
|
4819
4817
|
if (query.order) {
|
|
@@ -4897,7 +4895,7 @@ const cloneQuery = (q) => {
|
|
|
4897
4895
|
if (q.window)
|
|
4898
4896
|
q.window = q.window.slice(0);
|
|
4899
4897
|
if (q.union)
|
|
4900
|
-
q.union = q.union.slice(0);
|
|
4898
|
+
q.union = { b: q.union.b, u: q.union.u.slice(0) };
|
|
4901
4899
|
if (q.order)
|
|
4902
4900
|
q.order = q.order.slice(0);
|
|
4903
4901
|
} else if (q.type === "insert") {
|
|
@@ -8295,6 +8293,11 @@ class MergeQueryMethods {
|
|
|
8295
8293
|
a[key] = a[key] ? [...a[key], ...value] : value;
|
|
8296
8294
|
} else if (mergableObjects[key]) {
|
|
8297
8295
|
a[key] = a[key] ? __spreadValues$5(__spreadValues$5({}, a[key]), value) : value;
|
|
8296
|
+
} else if (key === "union") {
|
|
8297
|
+
a[key] = a[key] ? {
|
|
8298
|
+
b: a[key].b,
|
|
8299
|
+
u: [...a[key].u, ...value.u]
|
|
8300
|
+
} : value;
|
|
8298
8301
|
} else {
|
|
8299
8302
|
a[key] = value;
|
|
8300
8303
|
}
|
|
@@ -8308,196 +8311,225 @@ class MergeQueryMethods {
|
|
|
8308
8311
|
}
|
|
8309
8312
|
}
|
|
8310
8313
|
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
|
|
8326
|
-
}
|
|
8327
|
-
|
|
8314
|
+
const _queryUnion = (base, args, k) => {
|
|
8315
|
+
const q = base.baseQuery.clone();
|
|
8316
|
+
const u = args.map(
|
|
8317
|
+
(a) => ({
|
|
8318
|
+
a: typeof a === "function" ? a(q) : a,
|
|
8319
|
+
k
|
|
8320
|
+
})
|
|
8321
|
+
);
|
|
8322
|
+
const union = q.q.union = base.q.union;
|
|
8323
|
+
if (union) {
|
|
8324
|
+
union.u.push(...u);
|
|
8325
|
+
} else {
|
|
8326
|
+
q.q.union = {
|
|
8327
|
+
b: base,
|
|
8328
|
+
u
|
|
8329
|
+
};
|
|
8330
|
+
}
|
|
8331
|
+
return q;
|
|
8328
8332
|
};
|
|
8329
|
-
|
|
8330
|
-
class With {
|
|
8333
|
+
class Union {
|
|
8331
8334
|
/**
|
|
8332
|
-
*
|
|
8335
|
+
* Creates a union query, takes one or more queries or SQL expressions.
|
|
8333
8336
|
*
|
|
8334
8337
|
* ```ts
|
|
8335
|
-
*
|
|
8336
|
-
*
|
|
8337
|
-
*
|
|
8338
|
-
*
|
|
8339
|
-
*
|
|
8340
|
-
*
|
|
8341
|
-
*
|
|
8342
|
-
*
|
|
8343
|
-
*
|
|
8344
|
-
*
|
|
8345
|
-
* // Adds RECURSIVE keyword:
|
|
8346
|
-
* recursive?: true;
|
|
8347
|
-
*
|
|
8348
|
-
* // Adds MATERIALIZED keyword:
|
|
8349
|
-
* materialized?: true;
|
|
8350
|
-
*
|
|
8351
|
-
* // Adds NOT MATERIALIZED keyword:
|
|
8352
|
-
* notMaterialized?: true;
|
|
8353
|
-
* };
|
|
8354
|
-
*
|
|
8355
|
-
* // accepts columns shape and a raw expression:
|
|
8356
|
-
* db.table.with(
|
|
8357
|
-
* 'alias',
|
|
8358
|
-
* {
|
|
8359
|
-
* id: columnTypes.integer(),
|
|
8360
|
-
* name: columnTypes.text(3, 100),
|
|
8361
|
-
* },
|
|
8362
|
-
* sql`SELECT id, name FROM "someTable"`,
|
|
8363
|
-
* );
|
|
8364
|
-
*
|
|
8365
|
-
* // accepts query:
|
|
8366
|
-
* db.table.with('alias', db.table.all());
|
|
8367
|
-
*
|
|
8368
|
-
* // accepts a callback for a query builder:
|
|
8369
|
-
* db.table.with('alias', (qb) =>
|
|
8370
|
-
* qb.select({ one: sql`1`.type((t) => t.integer()) }),
|
|
8371
|
-
* );
|
|
8372
|
-
*
|
|
8373
|
-
* // All mentioned forms can accept options as a second argument:
|
|
8374
|
-
* db.table.with(
|
|
8375
|
-
* 'alias',
|
|
8376
|
-
* {
|
|
8377
|
-
* recursive: true,
|
|
8378
|
-
* materialized: true,
|
|
8379
|
-
* },
|
|
8380
|
-
* rawOrQueryOrCallback,
|
|
8381
|
-
* );
|
|
8338
|
+
* // The first query of the union
|
|
8339
|
+
* db.one
|
|
8340
|
+
* .select('id', 'name')
|
|
8341
|
+
* // add two more queries to the union
|
|
8342
|
+
* .union(
|
|
8343
|
+
* db.two.select('id', 'name'),
|
|
8344
|
+
* (q = q.sql`SELECT id, name FROM "thirdTable"`),
|
|
8345
|
+
* )
|
|
8346
|
+
* // sub-sequent `union` is equivalent to passing multiple queries into a single `union`
|
|
8347
|
+
* .union(db.three.select('id', 'name'));
|
|
8382
8348
|
* ```
|
|
8383
8349
|
*
|
|
8384
|
-
*
|
|
8350
|
+
* `order`, `limit`, `offset` are special, it matters if you place them **before** or **after** the `union`, it also have a meaning to place them before and after.
|
|
8385
8351
|
*
|
|
8386
8352
|
* ```ts
|
|
8387
|
-
*
|
|
8388
|
-
*
|
|
8389
|
-
*
|
|
8390
|
-
* .
|
|
8391
|
-
* .
|
|
8392
|
-
*
|
|
8353
|
+
* // order, limit, offset are applied ONLY to 'one'
|
|
8354
|
+
* db.one
|
|
8355
|
+
* .order('x')
|
|
8356
|
+
* .limit(1)
|
|
8357
|
+
* .offset(1)
|
|
8358
|
+
* // 'two' also has order, limit, and offset
|
|
8359
|
+
* .unionAll(db.two.order('y').limit(2).offset(2))
|
|
8360
|
+
* // sets order, limit, offset for all records
|
|
8361
|
+
* .order('z')
|
|
8362
|
+
* .limit(3)
|
|
8363
|
+
* .offset(3);
|
|
8393
8364
|
* ```
|
|
8394
8365
|
*
|
|
8395
|
-
*
|
|
8396
|
-
*/
|
|
8397
|
-
with(...args) {
|
|
8398
|
-
const q = this.clone();
|
|
8399
|
-
let options = args.length === 3 && !orchidCore.isExpression(args[2]) || args.length === 4 ? args[1] : void 0;
|
|
8400
|
-
const last = args[args.length - 1];
|
|
8401
|
-
const query = typeof last === "function" ? last(q.queryBuilder) : last;
|
|
8402
|
-
const shape = args.length === 4 ? args[2] : orchidCore.isExpression(query) ? args[1] : query.q.shape;
|
|
8403
|
-
if ((options == null ? void 0 : options.columns) === true) {
|
|
8404
|
-
options = __spreadProps$1(__spreadValues$4({}, options), {
|
|
8405
|
-
columns: Object.keys(shape)
|
|
8406
|
-
});
|
|
8407
|
-
}
|
|
8408
|
-
pushQueryValue(q, "with", [args[0], options || orchidCore.emptyObject, query]);
|
|
8409
|
-
return setQueryObjectValue(q, "withShapes", args[0], shape);
|
|
8410
|
-
}
|
|
8411
|
-
}
|
|
8412
|
-
|
|
8413
|
-
class Union {
|
|
8414
|
-
/**
|
|
8415
|
-
* Creates a union query, taking an array or a list of callbacks, builders, or raw statements to build the union statement, with optional boolean `wrap`.
|
|
8416
|
-
* If the `wrap` parameter is true, the queries will be individually wrapped in parentheses.
|
|
8366
|
+
* Equivalent SQL:
|
|
8417
8367
|
*
|
|
8418
|
-
* ```
|
|
8419
|
-
*
|
|
8420
|
-
*
|
|
8421
|
-
*
|
|
8422
|
-
*
|
|
8423
|
-
*
|
|
8424
|
-
*
|
|
8425
|
-
* );
|
|
8368
|
+
* ```sql
|
|
8369
|
+
* -- both union parts have their own order, limit, offset
|
|
8370
|
+
* ( SELECT * FROM one ORDER x ASC LIMIT 1 OFFSET 1 )
|
|
8371
|
+
* UNION ALL
|
|
8372
|
+
* ( SELECT * FROM two ORDER y ASC LIMIT 2 OFFSET 2 )
|
|
8373
|
+
* -- order, limit, offset of the whole query
|
|
8374
|
+
* ORDER BY z ASC LIMIT 3 OFFSET 3
|
|
8426
8375
|
* ```
|
|
8427
8376
|
*
|
|
8428
|
-
*
|
|
8429
|
-
*
|
|
8377
|
+
* All the listed methods have the same signature, they are only different by SQL keyword:
|
|
8378
|
+
*
|
|
8379
|
+
* - `union` - union of all queries, performs deduplication
|
|
8380
|
+
* - `unionAll` - `union` that allows duplicated rows
|
|
8381
|
+
* - `intersect` - get only rows that are present in all queries
|
|
8382
|
+
* - `intersectAll` - `intersect` that allows duplicated rows
|
|
8383
|
+
* - `except` - get only rows that are in the first query but not in the second
|
|
8384
|
+
* - `exceptAll` - `except` that allows duplicated rows
|
|
8385
|
+
*
|
|
8386
|
+
* @param args - array of queries or SQL expressions
|
|
8430
8387
|
*/
|
|
8431
|
-
union(args
|
|
8432
|
-
return
|
|
8388
|
+
union(...args) {
|
|
8389
|
+
return _queryUnion(
|
|
8433
8390
|
this.clone(),
|
|
8434
|
-
|
|
8435
|
-
|
|
8391
|
+
args,
|
|
8392
|
+
"UNION"
|
|
8436
8393
|
);
|
|
8437
8394
|
}
|
|
8438
8395
|
/**
|
|
8439
|
-
* Same as
|
|
8396
|
+
* Same as {@link union}, but allows duplicated rows.
|
|
8440
8397
|
*
|
|
8441
|
-
* @param args - array of queries or
|
|
8442
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
8398
|
+
* @param args - array of queries or SQL expressions
|
|
8443
8399
|
*/
|
|
8444
|
-
unionAll(args
|
|
8445
|
-
return
|
|
8400
|
+
unionAll(...args) {
|
|
8401
|
+
return _queryUnion(
|
|
8446
8402
|
this.clone(),
|
|
8447
|
-
|
|
8448
|
-
|
|
8403
|
+
args,
|
|
8404
|
+
"UNION ALL"
|
|
8449
8405
|
);
|
|
8450
8406
|
}
|
|
8451
8407
|
/**
|
|
8452
|
-
* Same as
|
|
8408
|
+
* Same as {@link union}, but uses a `INTERSECT` SQL keyword instead
|
|
8453
8409
|
*
|
|
8454
|
-
* @param args - array of queries or
|
|
8455
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
8410
|
+
* @param args - array of queries or SQL expressions
|
|
8456
8411
|
*/
|
|
8457
|
-
intersect(args
|
|
8458
|
-
return
|
|
8412
|
+
intersect(...args) {
|
|
8413
|
+
return _queryUnion(
|
|
8459
8414
|
this.clone(),
|
|
8460
|
-
|
|
8461
|
-
|
|
8415
|
+
args,
|
|
8416
|
+
"INTERSECT"
|
|
8462
8417
|
);
|
|
8463
8418
|
}
|
|
8464
8419
|
/**
|
|
8465
|
-
* Same as
|
|
8420
|
+
* Same as {@link intersect}, but allows duplicated rows.
|
|
8466
8421
|
*
|
|
8467
|
-
* @param args - array of queries or
|
|
8468
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
8422
|
+
* @param args - array of queries or SQL expressions
|
|
8469
8423
|
*/
|
|
8470
|
-
intersectAll(args
|
|
8471
|
-
return
|
|
8424
|
+
intersectAll(...args) {
|
|
8425
|
+
return _queryUnion(
|
|
8472
8426
|
this.clone(),
|
|
8473
|
-
|
|
8474
|
-
|
|
8427
|
+
args,
|
|
8428
|
+
"INTERSECT ALL"
|
|
8475
8429
|
);
|
|
8476
8430
|
}
|
|
8477
8431
|
/**
|
|
8478
|
-
* Same as
|
|
8432
|
+
* Same as {@link union}, but uses an `EXCEPT` SQL keyword instead
|
|
8479
8433
|
*
|
|
8480
|
-
* @param args - array of queries or
|
|
8481
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
8434
|
+
* @param args - array of queries or SQL expressions
|
|
8482
8435
|
*/
|
|
8483
|
-
except(args
|
|
8484
|
-
return
|
|
8436
|
+
except(...args) {
|
|
8437
|
+
return _queryUnion(
|
|
8485
8438
|
this.clone(),
|
|
8486
|
-
|
|
8487
|
-
|
|
8439
|
+
args,
|
|
8440
|
+
"EXCEPT"
|
|
8488
8441
|
);
|
|
8489
8442
|
}
|
|
8490
8443
|
/**
|
|
8491
|
-
* Same as
|
|
8444
|
+
* Same as {@link except}, but allows duplicated rows.
|
|
8492
8445
|
*
|
|
8493
|
-
* @param args - array of queries or
|
|
8494
|
-
* @param wrap - provide `true` if you want the queries to be wrapped into parentheses
|
|
8446
|
+
* @param args - array of queries or SQL expressions
|
|
8495
8447
|
*/
|
|
8496
|
-
exceptAll(args
|
|
8497
|
-
return
|
|
8448
|
+
exceptAll(...args) {
|
|
8449
|
+
return _queryUnion(
|
|
8498
8450
|
this.clone(),
|
|
8499
|
-
|
|
8500
|
-
|
|
8451
|
+
args,
|
|
8452
|
+
"EXCEPT ALL"
|
|
8453
|
+
);
|
|
8454
|
+
}
|
|
8455
|
+
}
|
|
8456
|
+
|
|
8457
|
+
var __defProp$4 = Object.defineProperty;
|
|
8458
|
+
var __defProps$1 = Object.defineProperties;
|
|
8459
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
8460
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
8461
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
8462
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
8463
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8464
|
+
var __spreadValues$4 = (a, b) => {
|
|
8465
|
+
for (var prop in b || (b = {}))
|
|
8466
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
8467
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
8468
|
+
if (__getOwnPropSymbols$4)
|
|
8469
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
8470
|
+
if (__propIsEnum$4.call(b, prop))
|
|
8471
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
8472
|
+
}
|
|
8473
|
+
return a;
|
|
8474
|
+
};
|
|
8475
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
8476
|
+
class WithMethods {
|
|
8477
|
+
with(name, second, third) {
|
|
8478
|
+
const q = this.clone();
|
|
8479
|
+
let [options, queryArg] = third ? [second, third] : [void 0, second];
|
|
8480
|
+
let query;
|
|
8481
|
+
if (typeof queryArg === "function") {
|
|
8482
|
+
const arg = q.queryBuilder.clone();
|
|
8483
|
+
arg.q.withShapes = q.q.withShapes;
|
|
8484
|
+
query = queryArg(arg);
|
|
8485
|
+
} else {
|
|
8486
|
+
query = queryArg;
|
|
8487
|
+
}
|
|
8488
|
+
if ((options == null ? void 0 : options.columns) === true) {
|
|
8489
|
+
options = __spreadProps$1(__spreadValues$4({}, options), {
|
|
8490
|
+
columns: Object.keys(query.shape)
|
|
8491
|
+
});
|
|
8492
|
+
}
|
|
8493
|
+
pushQueryValue(q, "with", { n: name, o: options, q: query });
|
|
8494
|
+
const shape = getShapeFromSelect(query, true);
|
|
8495
|
+
return setQueryObjectValue(q, "withShapes", name, shape);
|
|
8496
|
+
}
|
|
8497
|
+
withRecursive(name, ...args) {
|
|
8498
|
+
var _a, _b, _c;
|
|
8499
|
+
const q = this.clone();
|
|
8500
|
+
let [options, baseFn, recursiveFn] = args.length === 2 ? [{}, args[0], args[1]] : args;
|
|
8501
|
+
const arg = q.queryBuilder.clone();
|
|
8502
|
+
arg.q.withShapes = q.q.withShapes;
|
|
8503
|
+
let query = typeof baseFn === "function" ? baseFn(arg) : baseFn;
|
|
8504
|
+
const shape = ((_b = (_a = arg.q).withShapes) != null ? _b : _a.withShapes = {})[name] = getShapeFromSelect(
|
|
8505
|
+
query,
|
|
8506
|
+
true
|
|
8507
|
+
);
|
|
8508
|
+
const recursive = recursiveFn(arg);
|
|
8509
|
+
query = _queryUnion(query, [recursive], (_c = options.union) != null ? _c : "UNION ALL");
|
|
8510
|
+
options.recursive = true;
|
|
8511
|
+
if (options.columns === true) {
|
|
8512
|
+
options = __spreadProps$1(__spreadValues$4({}, options), {
|
|
8513
|
+
columns: Object.keys(shape)
|
|
8514
|
+
});
|
|
8515
|
+
}
|
|
8516
|
+
pushQueryValue(q, "with", { n: name, o: options, q: query });
|
|
8517
|
+
return setQueryObjectValue(q, "withShapes", name, shape);
|
|
8518
|
+
}
|
|
8519
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8520
|
+
withSql(name, ...args) {
|
|
8521
|
+
const q = this.clone();
|
|
8522
|
+
const [options, shape, sql] = args.length === 2 ? [void 0, args[0], args[1]] : args;
|
|
8523
|
+
pushQueryValue(q, "with", {
|
|
8524
|
+
n: name,
|
|
8525
|
+
o: options,
|
|
8526
|
+
s: sql(q)
|
|
8527
|
+
});
|
|
8528
|
+
return setQueryObjectValue(
|
|
8529
|
+
q,
|
|
8530
|
+
"withShapes",
|
|
8531
|
+
name,
|
|
8532
|
+
shape(this.columnTypes)
|
|
8501
8533
|
);
|
|
8502
8534
|
}
|
|
8503
8535
|
}
|
|
@@ -9331,11 +9363,10 @@ const _queryUpdate = (query, arg) => {
|
|
|
9331
9363
|
"q",
|
|
9332
9364
|
"withShapes"
|
|
9333
9365
|
);
|
|
9334
|
-
pushQueryValue(query, "with",
|
|
9335
|
-
as,
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
]);
|
|
9366
|
+
pushQueryValue(query, "with", {
|
|
9367
|
+
n: as,
|
|
9368
|
+
q: value
|
|
9369
|
+
});
|
|
9339
9370
|
set[key] = new RawSQL(`(SELECT * FROM "${as}")`);
|
|
9340
9371
|
}
|
|
9341
9372
|
} else {
|
|
@@ -11296,10 +11327,10 @@ orchidCore.applyMixins(QueryMethods, [
|
|
|
11296
11327
|
AsMethods,
|
|
11297
11328
|
AggregateMethods,
|
|
11298
11329
|
Select,
|
|
11299
|
-
|
|
11330
|
+
FromMethods,
|
|
11300
11331
|
Join,
|
|
11301
11332
|
OnMethods,
|
|
11302
|
-
|
|
11333
|
+
WithMethods,
|
|
11303
11334
|
Union,
|
|
11304
11335
|
JsonModifiers,
|
|
11305
11336
|
JsonMethods,
|
|
@@ -11933,7 +11964,7 @@ exports.EnumColumn = EnumColumn;
|
|
|
11933
11964
|
exports.ExpressionMethods = ExpressionMethods;
|
|
11934
11965
|
exports.FnExpression = FnExpression;
|
|
11935
11966
|
exports.For = For;
|
|
11936
|
-
exports.
|
|
11967
|
+
exports.FromMethods = FromMethods;
|
|
11937
11968
|
exports.Having = Having;
|
|
11938
11969
|
exports.InetColumn = InetColumn;
|
|
11939
11970
|
exports.IntegerBaseColumn = IntegerBaseColumn;
|
|
@@ -12000,7 +12031,7 @@ exports.Update = Update;
|
|
|
12000
12031
|
exports.VarCharColumn = VarCharColumn;
|
|
12001
12032
|
exports.VirtualColumn = VirtualColumn;
|
|
12002
12033
|
exports.Where = Where;
|
|
12003
|
-
exports.
|
|
12034
|
+
exports.WithMethods = WithMethods;
|
|
12004
12035
|
exports.XMLColumn = XMLColumn;
|
|
12005
12036
|
exports._initQueryBuilder = _initQueryBuilder;
|
|
12006
12037
|
exports._queryAfterSaveCommit = _queryAfterSaveCommit;
|
|
@@ -12048,6 +12079,7 @@ exports._queryRows = _queryRows;
|
|
|
12048
12079
|
exports._querySelect = _querySelect;
|
|
12049
12080
|
exports._queryTake = _queryTake;
|
|
12050
12081
|
exports._queryTakeOptional = _queryTakeOptional;
|
|
12082
|
+
exports._queryUnion = _queryUnion;
|
|
12051
12083
|
exports._queryUpdate = _queryUpdate;
|
|
12052
12084
|
exports._queryUpdateOrThrow = _queryUpdateOrThrow;
|
|
12053
12085
|
exports._queryUpdateRaw = _queryUpdateRaw;
|