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