pqb 0.38.5 → 0.38.7
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 +274 -97
- package/dist/index.js +62 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1097,9 +1097,9 @@ class NumberAsStringBaseColumn extends ColumnType {
|
|
|
1097
1097
|
this.operators = Operators.number;
|
|
1098
1098
|
}
|
|
1099
1099
|
}
|
|
1100
|
-
class DecimalColumn extends
|
|
1100
|
+
class DecimalColumn extends NumberAsStringBaseColumn {
|
|
1101
1101
|
constructor(schema, numericPrecision, numericScale) {
|
|
1102
|
-
super(schema
|
|
1102
|
+
super(schema);
|
|
1103
1103
|
this.operators = Operators.number;
|
|
1104
1104
|
this.dataType = "numeric";
|
|
1105
1105
|
this.data.numericPrecision = numericPrecision;
|
|
@@ -4571,25 +4571,29 @@ class SelectItemExpression extends orchidCore.Expression {
|
|
|
4571
4571
|
}
|
|
4572
4572
|
}
|
|
4573
4573
|
|
|
4574
|
-
const
|
|
4574
|
+
const _getSelectableColumn = (q, arg) => {
|
|
4575
4575
|
var _a, _b;
|
|
4576
|
+
let type = q.q.shape[arg];
|
|
4577
|
+
if (!type) {
|
|
4578
|
+
const index = arg.indexOf(".");
|
|
4579
|
+
if (index !== -1) {
|
|
4580
|
+
const table = arg.slice(0, index);
|
|
4581
|
+
const column = arg.slice(index + 1);
|
|
4582
|
+
if (table === (q.q.as || q.table)) {
|
|
4583
|
+
type = q.shape[column];
|
|
4584
|
+
} else {
|
|
4585
|
+
type = (_b = (_a = q.q.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
|
|
4586
|
+
}
|
|
4587
|
+
}
|
|
4588
|
+
}
|
|
4589
|
+
return type;
|
|
4590
|
+
};
|
|
4591
|
+
const _get = (query, returnType, arg) => {
|
|
4576
4592
|
const q = query.q;
|
|
4577
4593
|
q.returnType = returnType;
|
|
4578
4594
|
let type;
|
|
4579
4595
|
if (typeof arg === "string") {
|
|
4580
|
-
type =
|
|
4581
|
-
if (!type) {
|
|
4582
|
-
const index = arg.indexOf(".");
|
|
4583
|
-
if (index !== -1) {
|
|
4584
|
-
const table = arg.slice(0, index);
|
|
4585
|
-
const column = arg.slice(index + 1);
|
|
4586
|
-
if (table === (q.as || query.table)) {
|
|
4587
|
-
type = q.shape[column];
|
|
4588
|
-
} else {
|
|
4589
|
-
type = (_b = (_a = q.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
|
|
4590
|
-
}
|
|
4591
|
-
}
|
|
4592
|
-
}
|
|
4596
|
+
type = _getSelectableColumn(query, arg);
|
|
4593
4597
|
q.getColumn = type;
|
|
4594
4598
|
const selected = setParserForSelectedString(
|
|
4595
4599
|
query,
|
|
@@ -6552,6 +6556,13 @@ const nullableInt = new IntegerColumn(defaultSchemaConfig);
|
|
|
6552
6556
|
nullableInt.parseItem = nullableInt.parseFn = (input) => input === null ? null : parseInt(input);
|
|
6553
6557
|
const nullableFloat = new RealColumn(defaultSchemaConfig);
|
|
6554
6558
|
nullableFloat.parseItem = nullableFloat.parseFn = (input) => input === null ? null : parseFloat(input);
|
|
6559
|
+
const stringAsNumber = new NumberAsStringBaseColumn(
|
|
6560
|
+
defaultSchemaConfig
|
|
6561
|
+
);
|
|
6562
|
+
const numericResultColumn = (q, arg) => {
|
|
6563
|
+
const type = typeof arg === "string" ? _getSelectableColumn(q, arg) : arg.result.value;
|
|
6564
|
+
return type instanceof NumberBaseColumn ? nullableFloat : stringAsNumber;
|
|
6565
|
+
};
|
|
6555
6566
|
class AggregateMethods {
|
|
6556
6567
|
/**
|
|
6557
6568
|
* Use `exists()` to check if there is at least one record-matching condition.
|
|
@@ -6622,7 +6633,7 @@ class AggregateMethods {
|
|
|
6622
6633
|
min(arg, options) {
|
|
6623
6634
|
return makeFnExpression(
|
|
6624
6635
|
this,
|
|
6625
|
-
|
|
6636
|
+
numericResultColumn(this, arg),
|
|
6626
6637
|
"min",
|
|
6627
6638
|
[arg],
|
|
6628
6639
|
options
|
|
@@ -6652,7 +6663,7 @@ class AggregateMethods {
|
|
|
6652
6663
|
max(arg, options) {
|
|
6653
6664
|
return makeFnExpression(
|
|
6654
6665
|
this,
|
|
6655
|
-
|
|
6666
|
+
numericResultColumn(this, arg),
|
|
6656
6667
|
"max",
|
|
6657
6668
|
[arg],
|
|
6658
6669
|
options
|
|
@@ -6681,7 +6692,7 @@ class AggregateMethods {
|
|
|
6681
6692
|
sum(arg, options) {
|
|
6682
6693
|
return makeFnExpression(
|
|
6683
6694
|
this,
|
|
6684
|
-
|
|
6695
|
+
numericResultColumn(this, arg),
|
|
6685
6696
|
"sum",
|
|
6686
6697
|
[arg],
|
|
6687
6698
|
options
|
|
@@ -6707,7 +6718,7 @@ class AggregateMethods {
|
|
|
6707
6718
|
avg(arg, options) {
|
|
6708
6719
|
return makeFnExpression(
|
|
6709
6720
|
this,
|
|
6710
|
-
|
|
6721
|
+
numericResultColumn(this, arg),
|
|
6711
6722
|
"avg",
|
|
6712
6723
|
[arg],
|
|
6713
6724
|
options
|
|
@@ -6736,7 +6747,7 @@ class AggregateMethods {
|
|
|
6736
6747
|
bitAnd(arg, options) {
|
|
6737
6748
|
return makeFnExpression(
|
|
6738
6749
|
this,
|
|
6739
|
-
|
|
6750
|
+
numericResultColumn(this, arg),
|
|
6740
6751
|
"bit_and",
|
|
6741
6752
|
[arg],
|
|
6742
6753
|
options
|
|
@@ -6762,7 +6773,7 @@ class AggregateMethods {
|
|
|
6762
6773
|
bitOr(arg, options) {
|
|
6763
6774
|
return makeFnExpression(
|
|
6764
6775
|
this,
|
|
6765
|
-
|
|
6776
|
+
numericResultColumn(this, arg),
|
|
6766
6777
|
"bit_or",
|
|
6767
6778
|
[arg],
|
|
6768
6779
|
options
|
|
@@ -7376,6 +7387,8 @@ class Create {
|
|
|
7376
7387
|
* Each column may accept a specific value, a raw SQL, or a query that returns a single value.
|
|
7377
7388
|
*
|
|
7378
7389
|
* ```ts
|
|
7390
|
+
* import { sql } from './baseTable';
|
|
7391
|
+
*
|
|
7379
7392
|
* const oneRecord = await db.table.create({
|
|
7380
7393
|
* name: 'John',
|
|
7381
7394
|
* password: '1234',
|
|
@@ -7387,7 +7400,7 @@ class Create {
|
|
|
7387
7400
|
*
|
|
7388
7401
|
* await db.table.create({
|
|
7389
7402
|
* // raw SQL
|
|
7390
|
-
* column1: (
|
|
7403
|
+
* column1: () => sql`'John' || ' ' || 'Doe'`,
|
|
7391
7404
|
*
|
|
7392
7405
|
* // query that returns a single value
|
|
7393
7406
|
* // returning multiple values will result in Postgres error
|
|
@@ -7861,7 +7874,7 @@ class OnConflictQueryBuilder {
|
|
|
7861
7874
|
*
|
|
7862
7875
|
* If the table has columns with **dynamic** default values, such values will be applied as well.
|
|
7863
7876
|
*
|
|
7864
|
-
* You can exclude certain columns from being merged by passing the `
|
|
7877
|
+
* You can exclude certain columns from being merged by passing the `except` option.
|
|
7865
7878
|
*
|
|
7866
7879
|
* ```ts
|
|
7867
7880
|
* // merge the full data
|
|
@@ -8102,7 +8115,9 @@ class Having {
|
|
|
8102
8115
|
* Arguments of the aggregate function and of the comparison can be raw SQL:
|
|
8103
8116
|
*
|
|
8104
8117
|
* ```ts
|
|
8105
|
-
*
|
|
8118
|
+
* import { sql } from './baseTable';
|
|
8119
|
+
*
|
|
8120
|
+
* db.table.having((q) => q.count(sql('coalesce(one, two)')).gte(sql`2 + 2`));
|
|
8106
8121
|
* ```
|
|
8107
8122
|
*
|
|
8108
8123
|
* @param args - raw SQL template string or one or multiple callbacks returning a boolean expression
|
|
@@ -9200,13 +9215,15 @@ class Union {
|
|
|
9200
9215
|
* Creates a union query, takes one or more queries or SQL expressions.
|
|
9201
9216
|
*
|
|
9202
9217
|
* ```ts
|
|
9218
|
+
* import { sql } from './baseTable';
|
|
9219
|
+
*
|
|
9203
9220
|
* // The first query of the union
|
|
9204
9221
|
* db.one
|
|
9205
9222
|
* .select('id', 'name')
|
|
9206
9223
|
* // add two more queries to the union
|
|
9207
9224
|
* .union(
|
|
9208
9225
|
* db.two.select('id', 'name'),
|
|
9209
|
-
* (q =
|
|
9226
|
+
* (q = sql`SELECT id, name FROM "thirdTable"`),
|
|
9210
9227
|
* )
|
|
9211
9228
|
* // sub-sequent `union` is equivalent to passing multiple queries into a single `union`
|
|
9212
9229
|
* .union(db.three.select('id', 'name'));
|
|
@@ -9515,6 +9532,8 @@ class Where {
|
|
|
9515
9532
|
* Constructing `WHERE` conditions:
|
|
9516
9533
|
*
|
|
9517
9534
|
* ```ts
|
|
9535
|
+
* import { sql } from './baseTable'
|
|
9536
|
+
*
|
|
9518
9537
|
* db.table.where({
|
|
9519
9538
|
* // column of the current table
|
|
9520
9539
|
* name: 'John',
|
|
@@ -9531,8 +9550,8 @@ class Where {
|
|
|
9531
9550
|
* // where column equals to raw SQL
|
|
9532
9551
|
* // import `sql` from your `BaseTable`
|
|
9533
9552
|
* column: sql`sql expression`,
|
|
9534
|
-
* // or use `(q) =>
|
|
9535
|
-
* column2: (q) =>
|
|
9553
|
+
* // or use `(q) => sql` for the same
|
|
9554
|
+
* column2: (q) => sql`sql expression`,
|
|
9536
9555
|
*
|
|
9537
9556
|
* // reference other columns in such a way:
|
|
9538
9557
|
* firstName: (q) => q.ref('lastName'),
|
|
@@ -10357,6 +10376,8 @@ class Update {
|
|
|
10357
10376
|
* and [jsonRemove](/guide/advanced-queries.html#jsonremove) for a JSON column (see `jsonColumn` below).
|
|
10358
10377
|
*
|
|
10359
10378
|
* ```ts
|
|
10379
|
+
* import { sql } from './baseTable';
|
|
10380
|
+
*
|
|
10360
10381
|
* // returns number of updated records by default
|
|
10361
10382
|
* const updatedCount = await db.table
|
|
10362
10383
|
* .where({ name: 'old name' })
|
|
@@ -10382,7 +10403,7 @@ class Update {
|
|
|
10382
10403
|
* column1: 123,
|
|
10383
10404
|
*
|
|
10384
10405
|
* // use raw SQL to update the column
|
|
10385
|
-
* column2: (
|
|
10406
|
+
* column2: () => sql`2 + 2`,
|
|
10386
10407
|
*
|
|
10387
10408
|
* // use query that returns a single value
|
|
10388
10409
|
* // returning multiple values will result in Postgres error
|
|
@@ -11394,11 +11415,13 @@ class ExpressionMethods {
|
|
|
11394
11415
|
* Only for referencing a column in the query's table. For referencing joined table's columns, see [ref](#ref).
|
|
11395
11416
|
*
|
|
11396
11417
|
* ```ts
|
|
11418
|
+
* import { sql } from './baseTable';
|
|
11419
|
+
*
|
|
11397
11420
|
* await db.table.select({
|
|
11398
11421
|
* // select `("table"."id" = 1 OR "table"."name" = 'name') AS "one"`,
|
|
11399
11422
|
* // returns a boolean
|
|
11400
11423
|
* one: (q) =>
|
|
11401
|
-
*
|
|
11424
|
+
* sql<boolean>`${q.column('id')} = ${1} OR ${q.column('name')} = ${'name'}`,
|
|
11402
11425
|
*
|
|
11403
11426
|
* // selects the same as above, but by building a query
|
|
11404
11427
|
* two: (q) => q.column('id').equals(1).or(q.column('name').equals('name')),
|
|
@@ -11419,11 +11442,13 @@ class ExpressionMethods {
|
|
|
11419
11442
|
* and other dynamically defined columns.
|
|
11420
11443
|
*
|
|
11421
11444
|
* ```ts
|
|
11445
|
+
* import { sql } from './baseTable';
|
|
11446
|
+
*
|
|
11422
11447
|
* await db.table.join('otherTable').select({
|
|
11423
11448
|
* // select `("otherTable"."id" = 1 OR "otherTable"."name" = 'name') AS "one"`,
|
|
11424
11449
|
* // returns a boolean
|
|
11425
11450
|
* one: (q) =>
|
|
11426
|
-
*
|
|
11451
|
+
* sql<boolean>`${q.ref('otherTable.id')} = ${1} OR ${q.ref(
|
|
11427
11452
|
* 'otherTable.name',
|
|
11428
11453
|
* )} = ${'name'}`,
|
|
11429
11454
|
*
|
|
@@ -12646,6 +12671,11 @@ const createDb = (_a) => {
|
|
|
12646
12671
|
for (const name of Object.getOwnPropertyNames(Db.prototype)) {
|
|
12647
12672
|
db[name] = Db.prototype[name];
|
|
12648
12673
|
}
|
|
12674
|
+
db.sql = (...args) => {
|
|
12675
|
+
const sql = raw(...args);
|
|
12676
|
+
sql.columnTypes = ct;
|
|
12677
|
+
return sql;
|
|
12678
|
+
};
|
|
12649
12679
|
return db;
|
|
12650
12680
|
};
|
|
12651
12681
|
const _initQueryBuilder = (adapter, columnTypes, transactionStorage, commonOptions, options) => {
|
|
@@ -12903,6 +12933,7 @@ exports.VirtualColumn = VirtualColumn;
|
|
|
12903
12933
|
exports.Where = Where;
|
|
12904
12934
|
exports.WithMethods = WithMethods;
|
|
12905
12935
|
exports.XMLColumn = XMLColumn;
|
|
12936
|
+
exports._getSelectableColumn = _getSelectableColumn;
|
|
12906
12937
|
exports._initQueryBuilder = _initQueryBuilder;
|
|
12907
12938
|
exports._queryAfterSaveCommit = _queryAfterSaveCommit;
|
|
12908
12939
|
exports._queryAll = _queryAll;
|