pqb 0.18.33 → 0.18.34

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 CHANGED
@@ -591,6 +591,73 @@ type DbResult<ColumnTypes> = Db<string, Record<string, never>, EmptyObject, Colu
591
591
  adapter: Adapter;
592
592
  close: Adapter['close'];
593
593
  };
594
+ /**
595
+ * For the case of using the query builder as a standalone tool, use `createDb` from `pqb` package.
596
+ *
597
+ * As `Orchid ORM` focuses on ORM usage, docs examples mostly demonstrates how to work with ORM-defined tables,
598
+ * but everything that's not related to table relations should also work with `pqb` query builder on its own.
599
+ *
600
+ * It is accepting the same options as `orchidORM` + options of `createBaseTable`:
601
+ *
602
+ * ```ts
603
+ * import { createDb } from 'orchid-orm';
604
+ *
605
+ * const db = createDb({
606
+ * // db connection options
607
+ * databaseURL: process.env.DATABASE_URL,
608
+ * log: true,
609
+ *
610
+ * // columns in db are in snake case:
611
+ * snakeCase: true,
612
+ *
613
+ * // override default SQL for timestamp, see `nowSQL` above
614
+ * nowSQL: `now() AT TIME ZONE 'UTC'`,
615
+ *
616
+ * // override column types:
617
+ * columnTypes: (t) => ({
618
+ * // by default timestamp is returned as a string, override to a number
619
+ * timestamp: () => t.timestamp().asNumber(),
620
+ * }),
621
+ * });
622
+ * ```
623
+ *
624
+ * After `db` is defined, construct queryable tables in such way:
625
+ *
626
+ * ```ts
627
+ * export const User = db('user', (t) => ({
628
+ * id: t.identity().primaryKey(),
629
+ * name: t.text(3, 100),
630
+ * password: t.text(8, 200),
631
+ * age: t.integer().nullable(),
632
+ * ...t.timestamps(),
633
+ * }));
634
+ * ```
635
+ *
636
+ * Now the `User` can be used for making type-safe queries:
637
+ *
638
+ * ```ts
639
+ * const users = await User.select('id', 'name') // only known columns are allowed
640
+ * .where({ age: { gte: 20 } }) // gte is available only on the numeric field, and the only number is allowed
641
+ * .order({ createdAt: 'DESC' }) // type safe as well
642
+ * .limit(10);
643
+ *
644
+ * // users array has a proper type of Array<{ id: number, name: string }>
645
+ * ```
646
+ *
647
+ * The optional third argument is for table options:
648
+ *
649
+ * ```ts
650
+ * const Table = db('table', (t) => ({ ...columns }), {
651
+ * // provide this value if the table belongs to a specific database schema:
652
+ * schema: 'customTableSchema',
653
+ * // override `log` option of `createDb`:
654
+ * log: true, // boolean or object described `createdDb` section
655
+ * logger: { ... }, // override logger
656
+ * noPrimaryKey: 'ignore', // override noPrimaryKey
657
+ * snakeCase: true, // override snakeCase
658
+ * })
659
+ * ```
660
+ */
594
661
  declare const createDb: <ColumnTypes extends Record<string, orchid_core.AnyColumnTypeCreator> = DefaultColumnTypes>({ log, logger, columnTypes: ctOrFn, snakeCase, nowSQL, ...options }: DbOptions<ColumnTypes>) => DbResult<ColumnTypes>;
595
662
 
596
663
  type ToSQLCtx = {
@@ -1891,7 +1958,7 @@ declare class QueryGet {
1891
1958
  * It will throw `NotFoundError` when not found.
1892
1959
  *
1893
1960
  * ```ts
1894
- * import { NumberColumn } from 'pqb';
1961
+ * import { NumberColumn } from 'orchid-orm';
1895
1962
  *
1896
1963
  * const firstName: string = await db.table.get('name');
1897
1964
  *
@@ -3754,7 +3821,7 @@ declare abstract class JsonModifiers extends QueryBase {
3754
3821
  * Selects a value from JSON data using a JSON path.
3755
3822
  *
3756
3823
  * ```ts
3757
- * import { columnTypes } from 'pqb';
3824
+ * import { columnTypes } from 'orchid-orm';
3758
3825
  *
3759
3826
  * db.table.jsonPathQuery(
3760
3827
  * columnTypes.text(3, 100), // type of the value
@@ -4001,7 +4068,7 @@ declare class With {
4001
4068
  * Add Common Table Expression (CTE) to the query.
4002
4069
  *
4003
4070
  * ```ts
4004
- * import { columnTypes } from 'pqb';
4071
+ * import { columnTypes } from 'orchid-orm';
4005
4072
  * import { NumberColumn } from './number';
4006
4073
  *
4007
4074
  * // .with optionally accepts such options:
@@ -4345,7 +4412,7 @@ declare class Update {
4345
4412
  * To make sure that at least one row was updated use `updateOrThrow`:
4346
4413
  *
4347
4414
  * ```ts
4348
- * import { NotFoundError } from 'pqb';
4415
+ * import { NotFoundError } from 'orchid-orm';
4349
4416
  *
4350
4417
  * try {
4351
4418
  * // updatedCount is guaranteed to be greater than 0
@@ -5635,6 +5702,20 @@ declare class QueryMethods<ColumnTypes> {
5635
5702
  * await selectFollowing(db.user.select('id', 'name'), currentUser);
5636
5703
  * ```
5637
5704
  *
5705
+ * To get the result type of query helper, use `QueryHelperResult` type:
5706
+ *
5707
+ * ```ts
5708
+ * import { QueryHelperResult } from 'orchid-orm';
5709
+ *
5710
+ * const selectHelper = db.table.makeHelper((q) => q.select('id', 'name'));
5711
+ *
5712
+ * // This type is identical to `db.table.select('id', 'name')`
5713
+ * type SelectQuery = QueryHelperResult<typeof selectHelper>;
5714
+ *
5715
+ * // Await to get result, the type is `{ id: number, name: string }[]`
5716
+ * type Result = Awaited<QueryHelperResult<typeof selectHelper>>;
5717
+ * ```
5718
+ *
5638
5719
  * @param fn - helper function
5639
5720
  */
5640
5721
  makeHelper<T extends Query, Args extends unknown[], Result>(this: T, fn: (q: T, ...args: Args) => Result): QueryHelper<T, Args, Result>;
package/dist/index.js CHANGED
@@ -6185,7 +6185,7 @@ class QueryGet {
6185
6185
  * It will throw `NotFoundError` when not found.
6186
6186
  *
6187
6187
  * ```ts
6188
- * import { NumberColumn } from 'pqb';
6188
+ * import { NumberColumn } from 'orchid-orm';
6189
6189
  *
6190
6190
  * const firstName: string = await db.table.get('name');
6191
6191
  *
@@ -7469,7 +7469,7 @@ class JsonModifiers extends QueryBase {
7469
7469
  * Selects a value from JSON data using a JSON path.
7470
7470
  *
7471
7471
  * ```ts
7472
- * import { columnTypes } from 'pqb';
7472
+ * import { columnTypes } from 'orchid-orm';
7473
7473
  *
7474
7474
  * db.table.jsonPathQuery(
7475
7475
  * columnTypes.text(3, 100), // type of the value
@@ -8056,7 +8056,7 @@ class With {
8056
8056
  * Add Common Table Expression (CTE) to the query.
8057
8057
  *
8058
8058
  * ```ts
8059
- * import { columnTypes } from 'pqb';
8059
+ * import { columnTypes } from 'orchid-orm';
8060
8060
  * import { NumberColumn } from './number';
8061
8061
  *
8062
8062
  * // .with optionally accepts such options:
@@ -8561,7 +8561,7 @@ class Update {
8561
8561
  * To make sure that at least one row was updated use `updateOrThrow`:
8562
8562
  *
8563
8563
  * ```ts
8564
- * import { NotFoundError } from 'pqb';
8564
+ * import { NotFoundError } from 'orchid-orm';
8565
8565
  *
8566
8566
  * try {
8567
8567
  * // updatedCount is guaranteed to be greater than 0
@@ -9897,6 +9897,20 @@ class QueryMethods {
9897
9897
  * await selectFollowing(db.user.select('id', 'name'), currentUser);
9898
9898
  * ```
9899
9899
  *
9900
+ * To get the result type of query helper, use `QueryHelperResult` type:
9901
+ *
9902
+ * ```ts
9903
+ * import { QueryHelperResult } from 'orchid-orm';
9904
+ *
9905
+ * const selectHelper = db.table.makeHelper((q) => q.select('id', 'name'));
9906
+ *
9907
+ * // This type is identical to `db.table.select('id', 'name')`
9908
+ * type SelectQuery = QueryHelperResult<typeof selectHelper>;
9909
+ *
9910
+ * // Await to get result, the type is `{ id: number, name: string }[]`
9911
+ * type Result = Awaited<QueryHelperResult<typeof selectHelper>>;
9912
+ * ```
9913
+ *
9900
9914
  * @param fn - helper function
9901
9915
  */
9902
9916
  makeHelper(fn) {