pqb 0.38.6 → 0.38.8
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 +260 -90
- package/dist/index.js +28 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7387,6 +7387,8 @@ class Create {
|
|
|
7387
7387
|
* Each column may accept a specific value, a raw SQL, or a query that returns a single value.
|
|
7388
7388
|
*
|
|
7389
7389
|
* ```ts
|
|
7390
|
+
* import { sql } from './baseTable';
|
|
7391
|
+
*
|
|
7390
7392
|
* const oneRecord = await db.table.create({
|
|
7391
7393
|
* name: 'John',
|
|
7392
7394
|
* password: '1234',
|
|
@@ -7398,7 +7400,7 @@ class Create {
|
|
|
7398
7400
|
*
|
|
7399
7401
|
* await db.table.create({
|
|
7400
7402
|
* // raw SQL
|
|
7401
|
-
* column1: (
|
|
7403
|
+
* column1: () => sql`'John' || ' ' || 'Doe'`,
|
|
7402
7404
|
*
|
|
7403
7405
|
* // query that returns a single value
|
|
7404
7406
|
* // returning multiple values will result in Postgres error
|
|
@@ -7872,7 +7874,7 @@ class OnConflictQueryBuilder {
|
|
|
7872
7874
|
*
|
|
7873
7875
|
* If the table has columns with **dynamic** default values, such values will be applied as well.
|
|
7874
7876
|
*
|
|
7875
|
-
* 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.
|
|
7876
7878
|
*
|
|
7877
7879
|
* ```ts
|
|
7878
7880
|
* // merge the full data
|
|
@@ -8113,7 +8115,9 @@ class Having {
|
|
|
8113
8115
|
* Arguments of the aggregate function and of the comparison can be raw SQL:
|
|
8114
8116
|
*
|
|
8115
8117
|
* ```ts
|
|
8116
|
-
*
|
|
8118
|
+
* import { sql } from './baseTable';
|
|
8119
|
+
*
|
|
8120
|
+
* db.table.having((q) => q.count(sql('coalesce(one, two)')).gte(sql`2 + 2`));
|
|
8117
8121
|
* ```
|
|
8118
8122
|
*
|
|
8119
8123
|
* @param args - raw SQL template string or one or multiple callbacks returning a boolean expression
|
|
@@ -9211,13 +9215,15 @@ class Union {
|
|
|
9211
9215
|
* Creates a union query, takes one or more queries or SQL expressions.
|
|
9212
9216
|
*
|
|
9213
9217
|
* ```ts
|
|
9218
|
+
* import { sql } from './baseTable';
|
|
9219
|
+
*
|
|
9214
9220
|
* // The first query of the union
|
|
9215
9221
|
* db.one
|
|
9216
9222
|
* .select('id', 'name')
|
|
9217
9223
|
* // add two more queries to the union
|
|
9218
9224
|
* .union(
|
|
9219
9225
|
* db.two.select('id', 'name'),
|
|
9220
|
-
* (q =
|
|
9226
|
+
* (q = sql`SELECT id, name FROM "thirdTable"`),
|
|
9221
9227
|
* )
|
|
9222
9228
|
* // sub-sequent `union` is equivalent to passing multiple queries into a single `union`
|
|
9223
9229
|
* .union(db.three.select('id', 'name'));
|
|
@@ -9526,6 +9532,8 @@ class Where {
|
|
|
9526
9532
|
* Constructing `WHERE` conditions:
|
|
9527
9533
|
*
|
|
9528
9534
|
* ```ts
|
|
9535
|
+
* import { sql } from './baseTable'
|
|
9536
|
+
*
|
|
9529
9537
|
* db.table.where({
|
|
9530
9538
|
* // column of the current table
|
|
9531
9539
|
* name: 'John',
|
|
@@ -9542,8 +9550,8 @@ class Where {
|
|
|
9542
9550
|
* // where column equals to raw SQL
|
|
9543
9551
|
* // import `sql` from your `BaseTable`
|
|
9544
9552
|
* column: sql`sql expression`,
|
|
9545
|
-
* // or use `(q) =>
|
|
9546
|
-
* column2: (q) =>
|
|
9553
|
+
* // or use `(q) => sql` for the same
|
|
9554
|
+
* column2: (q) => sql`sql expression`,
|
|
9547
9555
|
*
|
|
9548
9556
|
* // reference other columns in such a way:
|
|
9549
9557
|
* firstName: (q) => q.ref('lastName'),
|
|
@@ -10368,6 +10376,8 @@ class Update {
|
|
|
10368
10376
|
* and [jsonRemove](/guide/advanced-queries.html#jsonremove) for a JSON column (see `jsonColumn` below).
|
|
10369
10377
|
*
|
|
10370
10378
|
* ```ts
|
|
10379
|
+
* import { sql } from './baseTable';
|
|
10380
|
+
*
|
|
10371
10381
|
* // returns number of updated records by default
|
|
10372
10382
|
* const updatedCount = await db.table
|
|
10373
10383
|
* .where({ name: 'old name' })
|
|
@@ -10393,7 +10403,7 @@ class Update {
|
|
|
10393
10403
|
* column1: 123,
|
|
10394
10404
|
*
|
|
10395
10405
|
* // use raw SQL to update the column
|
|
10396
|
-
* column2: (
|
|
10406
|
+
* column2: () => sql`2 + 2`,
|
|
10397
10407
|
*
|
|
10398
10408
|
* // use query that returns a single value
|
|
10399
10409
|
* // returning multiple values will result in Postgres error
|
|
@@ -11405,11 +11415,13 @@ class ExpressionMethods {
|
|
|
11405
11415
|
* Only for referencing a column in the query's table. For referencing joined table's columns, see [ref](#ref).
|
|
11406
11416
|
*
|
|
11407
11417
|
* ```ts
|
|
11418
|
+
* import { sql } from './baseTable';
|
|
11419
|
+
*
|
|
11408
11420
|
* await db.table.select({
|
|
11409
11421
|
* // select `("table"."id" = 1 OR "table"."name" = 'name') AS "one"`,
|
|
11410
11422
|
* // returns a boolean
|
|
11411
11423
|
* one: (q) =>
|
|
11412
|
-
*
|
|
11424
|
+
* sql<boolean>`${q.column('id')} = ${1} OR ${q.column('name')} = ${'name'}`,
|
|
11413
11425
|
*
|
|
11414
11426
|
* // selects the same as above, but by building a query
|
|
11415
11427
|
* two: (q) => q.column('id').equals(1).or(q.column('name').equals('name')),
|
|
@@ -11430,11 +11442,13 @@ class ExpressionMethods {
|
|
|
11430
11442
|
* and other dynamically defined columns.
|
|
11431
11443
|
*
|
|
11432
11444
|
* ```ts
|
|
11445
|
+
* import { sql } from './baseTable';
|
|
11446
|
+
*
|
|
11433
11447
|
* await db.table.join('otherTable').select({
|
|
11434
11448
|
* // select `("otherTable"."id" = 1 OR "otherTable"."name" = 'name') AS "one"`,
|
|
11435
11449
|
* // returns a boolean
|
|
11436
11450
|
* one: (q) =>
|
|
11437
|
-
*
|
|
11451
|
+
* sql<boolean>`${q.ref('otherTable.id')} = ${1} OR ${q.ref(
|
|
11438
11452
|
* 'otherTable.name',
|
|
11439
11453
|
* )} = ${'name'}`,
|
|
11440
11454
|
*
|
|
@@ -12657,6 +12671,11 @@ const createDb = (_a) => {
|
|
|
12657
12671
|
for (const name of Object.getOwnPropertyNames(Db.prototype)) {
|
|
12658
12672
|
db[name] = Db.prototype[name];
|
|
12659
12673
|
}
|
|
12674
|
+
db.sql = (...args) => {
|
|
12675
|
+
const sql = raw(...args);
|
|
12676
|
+
sql.columnTypes = ct;
|
|
12677
|
+
return sql;
|
|
12678
|
+
};
|
|
12660
12679
|
return db;
|
|
12661
12680
|
};
|
|
12662
12681
|
const _initQueryBuilder = (adapter, columnTypes, transactionStorage, commonOptions, options) => {
|