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