@warlock.js/cascade 4.0.135 → 4.0.137
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/cjs/context/database-transaction-context.d.ts +4 -0
- package/cjs/context/database-transaction-context.d.ts.map +1 -1
- package/cjs/context/database-transaction-context.js +6 -0
- package/cjs/context/database-transaction-context.js.map +1 -1
- package/cjs/contracts/database-driver.contract.d.ts +106 -4
- package/cjs/contracts/database-driver.contract.d.ts.map +1 -1
- package/cjs/contracts/migration-driver.contract.d.ts +49 -1
- package/cjs/contracts/migration-driver.contract.d.ts.map +1 -1
- package/cjs/contracts/query-builder.contract.d.ts +76 -4
- package/cjs/contracts/query-builder.contract.d.ts.map +1 -1
- package/cjs/data-source/data-source.d.ts +40 -1
- package/cjs/data-source/data-source.d.ts.map +1 -1
- package/cjs/data-source/data-source.js +6 -0
- package/cjs/data-source/data-source.js.map +1 -1
- package/cjs/database-dirty-tracker.d.ts +21 -22
- package/cjs/database-dirty-tracker.d.ts.map +1 -1
- package/cjs/database-dirty-tracker.js +14 -17
- package/cjs/database-dirty-tracker.js.map +1 -1
- package/cjs/drivers/mongodb/mongodb-driver.d.ts +29 -1
- package/cjs/drivers/mongodb/mongodb-driver.d.ts.map +1 -1
- package/cjs/drivers/mongodb/mongodb-driver.js +116 -4
- package/cjs/drivers/mongodb/mongodb-driver.js.map +1 -1
- package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts +22 -1
- package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts.map +1 -1
- package/cjs/drivers/mongodb/mongodb-migration-driver.js +27 -0
- package/cjs/drivers/mongodb/mongodb-migration-driver.js.map +1 -1
- package/cjs/drivers/mongodb/mongodb-query-builder.d.ts +41 -9
- package/cjs/drivers/mongodb/mongodb-query-builder.d.ts.map +1 -1
- package/cjs/drivers/mongodb/mongodb-query-builder.js +60 -18
- package/cjs/drivers/mongodb/mongodb-query-builder.js.map +1 -1
- package/cjs/drivers/mongodb/types.d.ts +1 -1
- package/cjs/drivers/mongodb/types.d.ts.map +1 -1
- package/cjs/drivers/postgres/postgres-dialect.d.ts +1 -0
- package/cjs/drivers/postgres/postgres-dialect.d.ts.map +1 -1
- package/cjs/drivers/postgres/postgres-dialect.js +24 -1
- package/cjs/drivers/postgres/postgres-dialect.js.map +1 -1
- package/cjs/drivers/postgres/postgres-driver.d.ts +24 -3
- package/cjs/drivers/postgres/postgres-driver.d.ts.map +1 -1
- package/cjs/drivers/postgres/postgres-driver.js +101 -8
- package/cjs/drivers/postgres/postgres-driver.js.map +1 -1
- package/cjs/drivers/postgres/postgres-migration-driver.d.ts +30 -1
- package/cjs/drivers/postgres/postgres-migration-driver.d.ts.map +1 -1
- package/cjs/drivers/postgres/postgres-migration-driver.js +61 -2
- package/cjs/drivers/postgres/postgres-migration-driver.js.map +1 -1
- package/cjs/drivers/postgres/postgres-query-builder.d.ts +152 -722
- package/cjs/drivers/postgres/postgres-query-builder.d.ts.map +1 -1
- package/cjs/drivers/postgres/postgres-query-builder.js +592 -1459
- package/cjs/drivers/postgres/postgres-query-builder.js.map +1 -1
- package/cjs/drivers/postgres/postgres-query-parser.d.ts +34 -14
- package/cjs/drivers/postgres/postgres-query-parser.d.ts.map +1 -1
- package/cjs/drivers/postgres/postgres-query-parser.js +197 -39
- package/cjs/drivers/postgres/postgres-query-parser.js.map +1 -1
- package/cjs/drivers/sql/sql-dialect.contract.d.ts +1 -0
- package/cjs/drivers/sql/sql-dialect.contract.d.ts.map +1 -1
- package/cjs/errors/transaction-rollback.error.d.ts +20 -0
- package/cjs/errors/transaction-rollback.error.d.ts.map +1 -0
- package/cjs/errors/transaction-rollback.error.js +27 -0
- package/cjs/errors/transaction-rollback.error.js.map +1 -0
- package/cjs/events/model-events.d.ts +1 -1
- package/cjs/events/model-events.d.ts.map +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +1 -1
- package/cjs/migration/column-builder.d.ts +4 -0
- package/cjs/migration/column-builder.d.ts.map +1 -1
- package/cjs/migration/column-builder.js +23 -6
- package/cjs/migration/column-builder.js.map +1 -1
- package/cjs/migration/migration-runner.d.ts.map +1 -1
- package/cjs/migration/migration-runner.js +137 -23
- package/cjs/migration/migration-runner.js.map +1 -1
- package/cjs/migration/migration.d.ts +209 -35
- package/cjs/migration/migration.d.ts.map +1 -1
- package/cjs/migration/migration.js +192 -27
- package/cjs/migration/migration.js.map +1 -1
- package/cjs/model/methods/accessor-methods.d.ts +13 -0
- package/cjs/model/methods/accessor-methods.d.ts.map +1 -0
- package/cjs/model/methods/accessor-methods.js +51 -0
- package/cjs/model/methods/accessor-methods.js.map +1 -0
- package/cjs/model/methods/delete-methods.d.ts +10 -0
- package/cjs/model/methods/delete-methods.d.ts.map +1 -0
- package/cjs/model/methods/delete-methods.js +10 -0
- package/cjs/model/methods/delete-methods.js.map +1 -0
- package/cjs/model/methods/dirty-methods.d.ts +10 -0
- package/cjs/model/methods/dirty-methods.d.ts.map +1 -0
- package/cjs/model/methods/dirty-methods.js +15 -0
- package/cjs/model/methods/dirty-methods.js.map +1 -0
- package/cjs/model/methods/hydration-methods.d.ts +10 -0
- package/cjs/model/methods/hydration-methods.d.ts.map +1 -0
- package/cjs/model/methods/hydration-methods.js +57 -0
- package/cjs/model/methods/hydration-methods.js.map +1 -0
- package/cjs/model/methods/instance-event-methods.d.ts +7 -0
- package/cjs/model/methods/instance-event-methods.d.ts.map +1 -0
- package/cjs/model/methods/instance-event-methods.js +15 -0
- package/cjs/model/methods/instance-event-methods.js.map +1 -0
- package/cjs/model/methods/meta-methods.d.ts +7 -0
- package/cjs/model/methods/meta-methods.d.ts.map +1 -0
- package/cjs/model/methods/meta-methods.js +78 -0
- package/cjs/model/methods/meta-methods.js.map +1 -0
- package/cjs/model/methods/query-methods.d.ts +24 -0
- package/cjs/model/methods/query-methods.d.ts.map +1 -0
- package/cjs/model/methods/query-methods.js +161 -0
- package/cjs/model/methods/query-methods.js.map +1 -0
- package/cjs/model/methods/restore-methods.d.ts +10 -0
- package/cjs/model/methods/restore-methods.d.ts.map +1 -0
- package/cjs/model/methods/restore-methods.js +13 -0
- package/cjs/model/methods/restore-methods.js.map +1 -0
- package/cjs/model/methods/scope-methods.d.ts +7 -0
- package/cjs/model/methods/scope-methods.d.ts.map +1 -0
- package/cjs/model/methods/scope-methods.js +15 -0
- package/cjs/model/methods/scope-methods.js.map +1 -0
- package/cjs/model/methods/serialization-methods.d.ts +3 -0
- package/cjs/model/methods/serialization-methods.d.ts.map +1 -0
- package/cjs/model/methods/serialization-methods.js +27 -0
- package/cjs/model/methods/serialization-methods.js.map +1 -0
- package/cjs/model/methods/static-event-methods.d.ts +9 -0
- package/cjs/model/methods/static-event-methods.d.ts.map +1 -0
- package/cjs/model/methods/static-event-methods.js +29 -0
- package/cjs/model/methods/static-event-methods.js.map +1 -0
- package/cjs/model/methods/write-methods.d.ts +10 -0
- package/cjs/model/methods/write-methods.d.ts.map +1 -0
- package/cjs/model/methods/write-methods.js +52 -0
- package/cjs/model/methods/write-methods.js.map +1 -0
- package/cjs/model/model.d.ts +89 -58
- package/cjs/model/model.d.ts.map +1 -1
- package/cjs/model/model.js +166 -424
- package/cjs/model/model.js.map +1 -1
- package/cjs/model/model.types.d.ts +44 -0
- package/cjs/model/model.types.d.ts.map +1 -0
- package/cjs/model/register-model.d.ts +3 -3
- package/cjs/model/register-model.d.ts.map +1 -1
- package/cjs/query-builder/query-builder.d.ts +556 -0
- package/cjs/query-builder/query-builder.d.ts.map +1 -0
- package/cjs/query-builder/query-builder.js +1070 -0
- package/cjs/query-builder/query-builder.js.map +1 -0
- package/cjs/relations/helpers.d.ts.map +1 -1
- package/cjs/relations/helpers.js +4 -0
- package/cjs/relations/helpers.js.map +1 -1
- package/cjs/relations/index.d.ts +2 -0
- package/cjs/relations/index.d.ts.map +1 -1
- package/cjs/relations/relation-hydrator.d.ts +68 -0
- package/cjs/relations/relation-hydrator.d.ts.map +1 -0
- package/cjs/relations/relation-hydrator.js +81 -0
- package/cjs/relations/relation-hydrator.js.map +1 -0
- package/cjs/relations/relation-loader.js +1 -1
- package/cjs/relations/relation-loader.js.map +1 -1
- package/cjs/relations/types.d.ts +26 -0
- package/cjs/relations/types.d.ts.map +1 -1
- package/cjs/sql-database-dirty-tracker.d.ts +13 -0
- package/cjs/sql-database-dirty-tracker.d.ts.map +1 -0
- package/cjs/sql-database-dirty-tracker.js +14 -0
- package/cjs/sql-database-dirty-tracker.js.map +1 -0
- package/cjs/types.d.ts +59 -0
- package/cjs/types.d.ts.map +1 -1
- package/cjs/utils/connect-to-database.d.ts +50 -1
- package/cjs/utils/connect-to-database.d.ts.map +1 -1
- package/cjs/utils/connect-to-database.js +14 -1
- package/cjs/utils/connect-to-database.js.map +1 -1
- package/cjs/utils/database-writer.utils.d.ts +1 -1
- package/cjs/utils/database-writer.utils.d.ts.map +1 -1
- package/cjs/utils/is-valid-date-value.d.ts +5 -0
- package/cjs/utils/is-valid-date-value.d.ts.map +1 -0
- package/cjs/utils/is-valid-date-value.js +25 -0
- package/cjs/utils/is-valid-date-value.js.map +1 -0
- package/cjs/utils/once-connected.d.ts.map +1 -1
- package/cjs/utils/once-connected.js +4 -5
- package/cjs/utils/once-connected.js.map +1 -1
- package/cjs/writer/database-writer.d.ts.map +1 -1
- package/cjs/writer/database-writer.js +7 -6
- package/cjs/writer/database-writer.js.map +1 -1
- package/esm/context/database-transaction-context.d.ts +4 -0
- package/esm/context/database-transaction-context.d.ts.map +1 -1
- package/esm/context/database-transaction-context.js +6 -0
- package/esm/context/database-transaction-context.js.map +1 -1
- package/esm/contracts/database-driver.contract.d.ts +106 -4
- package/esm/contracts/database-driver.contract.d.ts.map +1 -1
- package/esm/contracts/migration-driver.contract.d.ts +49 -1
- package/esm/contracts/migration-driver.contract.d.ts.map +1 -1
- package/esm/contracts/query-builder.contract.d.ts +76 -4
- package/esm/contracts/query-builder.contract.d.ts.map +1 -1
- package/esm/data-source/data-source.d.ts +40 -1
- package/esm/data-source/data-source.d.ts.map +1 -1
- package/esm/data-source/data-source.js +6 -0
- package/esm/data-source/data-source.js.map +1 -1
- package/esm/database-dirty-tracker.d.ts +21 -22
- package/esm/database-dirty-tracker.d.ts.map +1 -1
- package/esm/database-dirty-tracker.js +14 -17
- package/esm/database-dirty-tracker.js.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.d.ts +29 -1
- package/esm/drivers/mongodb/mongodb-driver.d.ts.map +1 -1
- package/esm/drivers/mongodb/mongodb-driver.js +116 -4
- package/esm/drivers/mongodb/mongodb-driver.js.map +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.ts +22 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.ts.map +1 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.js +27 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.js.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.ts +41 -9
- package/esm/drivers/mongodb/mongodb-query-builder.d.ts.map +1 -1
- package/esm/drivers/mongodb/mongodb-query-builder.js +60 -18
- package/esm/drivers/mongodb/mongodb-query-builder.js.map +1 -1
- package/esm/drivers/mongodb/types.d.ts +1 -1
- package/esm/drivers/mongodb/types.d.ts.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.d.ts +1 -0
- package/esm/drivers/postgres/postgres-dialect.d.ts.map +1 -1
- package/esm/drivers/postgres/postgres-dialect.js +24 -1
- package/esm/drivers/postgres/postgres-dialect.js.map +1 -1
- package/esm/drivers/postgres/postgres-driver.d.ts +24 -3
- package/esm/drivers/postgres/postgres-driver.d.ts.map +1 -1
- package/esm/drivers/postgres/postgres-driver.js +101 -8
- package/esm/drivers/postgres/postgres-driver.js.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.ts +30 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.ts.map +1 -1
- package/esm/drivers/postgres/postgres-migration-driver.js +61 -2
- package/esm/drivers/postgres/postgres-migration-driver.js.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.d.ts +152 -722
- package/esm/drivers/postgres/postgres-query-builder.d.ts.map +1 -1
- package/esm/drivers/postgres/postgres-query-builder.js +592 -1459
- package/esm/drivers/postgres/postgres-query-builder.js.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.d.ts +34 -14
- package/esm/drivers/postgres/postgres-query-parser.d.ts.map +1 -1
- package/esm/drivers/postgres/postgres-query-parser.js +197 -39
- package/esm/drivers/postgres/postgres-query-parser.js.map +1 -1
- package/esm/drivers/sql/sql-dialect.contract.d.ts +1 -0
- package/esm/drivers/sql/sql-dialect.contract.d.ts.map +1 -1
- package/esm/errors/transaction-rollback.error.d.ts +20 -0
- package/esm/errors/transaction-rollback.error.d.ts.map +1 -0
- package/esm/errors/transaction-rollback.error.js +27 -0
- package/esm/errors/transaction-rollback.error.js.map +1 -0
- package/esm/events/model-events.d.ts +1 -1
- package/esm/events/model-events.d.ts.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/migration/column-builder.d.ts +4 -0
- package/esm/migration/column-builder.d.ts.map +1 -1
- package/esm/migration/column-builder.js +23 -6
- package/esm/migration/column-builder.js.map +1 -1
- package/esm/migration/migration-runner.d.ts.map +1 -1
- package/esm/migration/migration-runner.js +137 -23
- package/esm/migration/migration-runner.js.map +1 -1
- package/esm/migration/migration.d.ts +209 -35
- package/esm/migration/migration.d.ts.map +1 -1
- package/esm/migration/migration.js +192 -27
- package/esm/migration/migration.js.map +1 -1
- package/esm/model/methods/accessor-methods.d.ts +13 -0
- package/esm/model/methods/accessor-methods.d.ts.map +1 -0
- package/esm/model/methods/accessor-methods.js +51 -0
- package/esm/model/methods/accessor-methods.js.map +1 -0
- package/esm/model/methods/delete-methods.d.ts +10 -0
- package/esm/model/methods/delete-methods.d.ts.map +1 -0
- package/esm/model/methods/delete-methods.js +10 -0
- package/esm/model/methods/delete-methods.js.map +1 -0
- package/esm/model/methods/dirty-methods.d.ts +10 -0
- package/esm/model/methods/dirty-methods.d.ts.map +1 -0
- package/esm/model/methods/dirty-methods.js +15 -0
- package/esm/model/methods/dirty-methods.js.map +1 -0
- package/esm/model/methods/hydration-methods.d.ts +10 -0
- package/esm/model/methods/hydration-methods.d.ts.map +1 -0
- package/esm/model/methods/hydration-methods.js +57 -0
- package/esm/model/methods/hydration-methods.js.map +1 -0
- package/esm/model/methods/instance-event-methods.d.ts +7 -0
- package/esm/model/methods/instance-event-methods.d.ts.map +1 -0
- package/esm/model/methods/instance-event-methods.js +15 -0
- package/esm/model/methods/instance-event-methods.js.map +1 -0
- package/esm/model/methods/meta-methods.d.ts +7 -0
- package/esm/model/methods/meta-methods.d.ts.map +1 -0
- package/esm/model/methods/meta-methods.js +78 -0
- package/esm/model/methods/meta-methods.js.map +1 -0
- package/esm/model/methods/query-methods.d.ts +24 -0
- package/esm/model/methods/query-methods.d.ts.map +1 -0
- package/esm/model/methods/query-methods.js +161 -0
- package/esm/model/methods/query-methods.js.map +1 -0
- package/esm/model/methods/restore-methods.d.ts +10 -0
- package/esm/model/methods/restore-methods.d.ts.map +1 -0
- package/esm/model/methods/restore-methods.js +13 -0
- package/esm/model/methods/restore-methods.js.map +1 -0
- package/esm/model/methods/scope-methods.d.ts +7 -0
- package/esm/model/methods/scope-methods.d.ts.map +1 -0
- package/esm/model/methods/scope-methods.js +15 -0
- package/esm/model/methods/scope-methods.js.map +1 -0
- package/esm/model/methods/serialization-methods.d.ts +3 -0
- package/esm/model/methods/serialization-methods.d.ts.map +1 -0
- package/esm/model/methods/serialization-methods.js +27 -0
- package/esm/model/methods/serialization-methods.js.map +1 -0
- package/esm/model/methods/static-event-methods.d.ts +9 -0
- package/esm/model/methods/static-event-methods.d.ts.map +1 -0
- package/esm/model/methods/static-event-methods.js +29 -0
- package/esm/model/methods/static-event-methods.js.map +1 -0
- package/esm/model/methods/write-methods.d.ts +10 -0
- package/esm/model/methods/write-methods.d.ts.map +1 -0
- package/esm/model/methods/write-methods.js +52 -0
- package/esm/model/methods/write-methods.js.map +1 -0
- package/esm/model/model.d.ts +89 -58
- package/esm/model/model.d.ts.map +1 -1
- package/esm/model/model.js +166 -424
- package/esm/model/model.js.map +1 -1
- package/esm/model/model.types.d.ts +44 -0
- package/esm/model/model.types.d.ts.map +1 -0
- package/esm/model/register-model.d.ts +3 -3
- package/esm/model/register-model.d.ts.map +1 -1
- package/esm/query-builder/query-builder.d.ts +556 -0
- package/esm/query-builder/query-builder.d.ts.map +1 -0
- package/esm/query-builder/query-builder.js +1070 -0
- package/esm/query-builder/query-builder.js.map +1 -0
- package/esm/relations/helpers.d.ts.map +1 -1
- package/esm/relations/helpers.js +4 -0
- package/esm/relations/helpers.js.map +1 -1
- package/esm/relations/index.d.ts +2 -0
- package/esm/relations/index.d.ts.map +1 -1
- package/esm/relations/relation-hydrator.d.ts +68 -0
- package/esm/relations/relation-hydrator.d.ts.map +1 -0
- package/esm/relations/relation-hydrator.js +81 -0
- package/esm/relations/relation-hydrator.js.map +1 -0
- package/esm/relations/relation-loader.js +1 -1
- package/esm/relations/relation-loader.js.map +1 -1
- package/esm/relations/types.d.ts +26 -0
- package/esm/relations/types.d.ts.map +1 -1
- package/esm/sql-database-dirty-tracker.d.ts +13 -0
- package/esm/sql-database-dirty-tracker.d.ts.map +1 -0
- package/esm/sql-database-dirty-tracker.js +14 -0
- package/esm/sql-database-dirty-tracker.js.map +1 -0
- package/esm/types.d.ts +59 -0
- package/esm/types.d.ts.map +1 -1
- package/esm/utils/connect-to-database.d.ts +50 -1
- package/esm/utils/connect-to-database.d.ts.map +1 -1
- package/esm/utils/connect-to-database.js +14 -1
- package/esm/utils/connect-to-database.js.map +1 -1
- package/esm/utils/database-writer.utils.d.ts +1 -1
- package/esm/utils/database-writer.utils.d.ts.map +1 -1
- package/esm/utils/is-valid-date-value.d.ts +5 -0
- package/esm/utils/is-valid-date-value.d.ts.map +1 -0
- package/esm/utils/is-valid-date-value.js +25 -0
- package/esm/utils/is-valid-date-value.js.map +1 -0
- package/esm/utils/once-connected.d.ts.map +1 -1
- package/esm/utils/once-connected.js +4 -5
- package/esm/utils/once-connected.js.map +1 -1
- package/esm/writer/database-writer.d.ts.map +1 -1
- package/esm/writer/database-writer.js +7 -6
- package/esm/writer/database-writer.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,824 +1,254 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* PostgreSQL Query Builder
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* parameter handling and type safety.
|
|
4
|
+
* Extends the pure QueryBuilder base with PostgreSQL-specific execution,
|
|
5
|
+
* SQL generation, relation hydration, and scope management.
|
|
7
6
|
*
|
|
8
7
|
* @module cascade/drivers/postgres
|
|
9
8
|
*/
|
|
10
9
|
import type { GenericObject } from "@mongez/reinforcements";
|
|
11
|
-
import type { ChunkCallback, CursorPaginationOptions, CursorPaginationResult,
|
|
10
|
+
import type { ChunkCallback, CursorPaginationOptions, CursorPaginationResult, DriverQuery, PaginationOptions, PaginationResult, QueryBuilderContract } from "../../contracts/query-builder.contract";
|
|
12
11
|
import type { DataSource } from "../../data-source/data-source";
|
|
13
|
-
import
|
|
14
|
-
|
|
12
|
+
import { QueryBuilder, type Op } from "../../query-builder/query-builder";
|
|
13
|
+
type JoinRelationConfig = {
|
|
14
|
+
alias: string;
|
|
15
|
+
type: "belongsTo" | "hasOne" | "hasMany";
|
|
16
|
+
model?: unknown;
|
|
17
|
+
localKey?: string;
|
|
18
|
+
foreignKey?: string;
|
|
19
|
+
ownerKey?: string;
|
|
20
|
+
parentPath?: string | null;
|
|
21
|
+
relationName?: string;
|
|
22
|
+
parentModel?: unknown;
|
|
23
|
+
select?: string[];
|
|
24
|
+
/** Operations recorded by a joinWith constraint callback. */
|
|
25
|
+
constraintOps?: Op[];
|
|
26
|
+
};
|
|
15
27
|
/**
|
|
16
28
|
* PostgreSQL Query Builder.
|
|
17
29
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* for SQL generation.
|
|
30
|
+
* Collects query operations (via the base class) and delegates SQL generation
|
|
31
|
+
* to `PostgresQueryParser`. Owns execution, hydration, and relation loading.
|
|
21
32
|
*
|
|
22
33
|
* @example
|
|
23
34
|
* ```typescript
|
|
24
|
-
* const users = await
|
|
25
|
-
* .select([
|
|
26
|
-
* .where(
|
|
27
|
-
* .
|
|
28
|
-
* .orderBy('createdAt', 'desc')
|
|
35
|
+
* const users = await User.query()
|
|
36
|
+
* .select(["id", "name", "email"])
|
|
37
|
+
* .where("status", "active")
|
|
38
|
+
* .orderBy("createdAt", "desc")
|
|
29
39
|
* .limit(10)
|
|
30
40
|
* .get();
|
|
31
41
|
* ```
|
|
32
42
|
*/
|
|
33
|
-
export declare class PostgresQueryBuilder<T = unknown> implements QueryBuilderContract<T> {
|
|
43
|
+
export declare class PostgresQueryBuilder<T = unknown> extends QueryBuilder<T> implements QueryBuilderContract<T> {
|
|
34
44
|
readonly table: string;
|
|
35
|
-
/**
|
|
36
|
-
* Collected operations to be parsed into SQL.
|
|
37
|
-
*/
|
|
38
|
-
operations: PostgresParserOperation[];
|
|
39
|
-
/**
|
|
40
|
-
* Data source instance.
|
|
41
|
-
*/
|
|
45
|
+
/** Data source backing this builder. */
|
|
42
46
|
readonly dataSource: DataSource;
|
|
43
|
-
/**
|
|
44
|
-
* Hydrate callback for transforming results.
|
|
45
|
-
*/
|
|
47
|
+
/** Hydration callback for transforming result rows into model instances. */
|
|
46
48
|
hydrateCallback?: (data: unknown, index: number) => unknown;
|
|
47
|
-
/**
|
|
48
|
-
* Callback invoked before query execution.
|
|
49
|
-
*/
|
|
49
|
+
/** Invoked before query execution. */
|
|
50
50
|
private fetchingCallback?;
|
|
51
|
-
/**
|
|
52
|
-
* Callback invoked after records fetched but before hydration.
|
|
53
|
-
*/
|
|
51
|
+
/** Invoked after fetch but before hydration. */
|
|
54
52
|
private hydratingCallback?;
|
|
55
|
-
/**
|
|
56
|
-
* Callback invoked after records fetched and hydrated.
|
|
57
|
-
*/
|
|
53
|
+
/** Invoked after fetch and hydration. */
|
|
58
54
|
private fetchedCallback?;
|
|
59
55
|
/**
|
|
60
|
-
*
|
|
56
|
+
* Map of relations registered via `joinWith()`.
|
|
57
|
+
* Keyed by dot-notation path (e.g. "organizationAiModel.aiModel").
|
|
61
58
|
*/
|
|
62
|
-
|
|
59
|
+
joinRelations: Map<string, JoinRelationConfig>;
|
|
63
60
|
/**
|
|
64
|
-
* Available local scopes.
|
|
65
|
-
*/
|
|
66
|
-
availableLocalScopes?: Map<string, LocalScopeCallback>;
|
|
67
|
-
/**
|
|
68
|
-
* Disabled global scope names.
|
|
69
|
-
*/
|
|
70
|
-
disabledGlobalScopes: Set<string>;
|
|
71
|
-
/**
|
|
72
|
-
* Whether scopes have been applied.
|
|
73
|
-
*/
|
|
74
|
-
scopesApplied: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* Create a new query builder.
|
|
77
|
-
*
|
|
78
61
|
* @param table - Target table name
|
|
79
|
-
* @param dataSource - Optional data source
|
|
62
|
+
* @param dataSource - Optional (uses default data source from registry if omitted)
|
|
80
63
|
*/
|
|
81
64
|
constructor(table: string, dataSource?: DataSource);
|
|
82
|
-
/**
|
|
83
|
-
* Get the PostgreSQL driver instance.
|
|
84
|
-
*/
|
|
85
65
|
private get driver();
|
|
66
|
+
clone(): this;
|
|
86
67
|
/**
|
|
87
|
-
*
|
|
68
|
+
* Native-query escape hatch. Passes `operations[]` to the callback for
|
|
69
|
+
* direct manipulation. Use sparingly — only when fluent API is insufficient.
|
|
88
70
|
*
|
|
89
|
-
* @
|
|
90
|
-
*
|
|
71
|
+
* @example
|
|
72
|
+
* q.raw(ops => ops.push({ type: "whereRaw", data: { expression: "1=1" } }))
|
|
91
73
|
*/
|
|
92
|
-
|
|
74
|
+
raw(callback: (operations: Op[]) => void): this;
|
|
93
75
|
/**
|
|
94
|
-
*
|
|
76
|
+
* Record a DISTINCT flag AND auto-select the field(s).
|
|
77
|
+
* In PostgreSQL, DISTINCT ON (col) requires the col to appear in SELECT.
|
|
95
78
|
*
|
|
96
|
-
* @
|
|
79
|
+
* @example
|
|
80
|
+
* q.distinctValues("category") // SELECT category … DISTINCT ON (category)
|
|
81
|
+
* q.distinctValues(["category", "status"]) // both fields in DISTINCT ON and SELECT
|
|
97
82
|
*/
|
|
98
|
-
|
|
83
|
+
distinctValues(fields?: string | string[]): this;
|
|
99
84
|
/**
|
|
100
|
-
*
|
|
85
|
+
* Nearest-neighbour vector similarity search via pgvector cosine distance.
|
|
101
86
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*
|
|
87
|
+
* Adds two operations atomically:
|
|
88
|
+
* 1. `selectRaw` → `1 - (column <=> $n::vector) AS <alias>`
|
|
89
|
+
* Makes the similarity score available on every returned row.
|
|
90
|
+
* 2. `orderByRaw` → `column <=> $n::vector`
|
|
91
|
+
* Tells the PostgreSQL query planner to use the IVFFlat/HNSW vector index.
|
|
92
|
+
* Using the alias in ORDER BY would bypass the index — the raw expression is required.
|
|
108
93
|
*
|
|
109
|
-
* @
|
|
110
|
-
*
|
|
111
|
-
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const results = await Vector.query()
|
|
97
|
+
* .where({ organization_id: "org-123", content_type: "summary" })
|
|
98
|
+
* .nearestTo("embedding", queryEmbedding)
|
|
99
|
+
* .limit(5)
|
|
100
|
+
* .get<VectorRow & { score: number }>();
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
nearestTo(column: string, embedding: number[], alias?: string): this;
|
|
104
|
+
/** Set a hydration callback that transforms each result row. */
|
|
105
|
+
hydrate(callback: (data: unknown, index: number) => unknown): this;
|
|
106
|
+
/** Register a callback invoked before query execution. */
|
|
112
107
|
onFetching(callback: (query: this) => void | Promise<void>): () => void;
|
|
113
|
-
/**
|
|
114
|
-
* Register callback invoked after fetch but before hydration.
|
|
115
|
-
*
|
|
116
|
-
* @param callback - Callback function
|
|
117
|
-
* @returns Unsubscribe function
|
|
118
|
-
*/
|
|
108
|
+
/** Register a callback invoked after fetch but before hydration. */
|
|
119
109
|
onHydrating(callback: (records: unknown[], context: unknown) => void | Promise<void>): () => void;
|
|
120
|
-
/**
|
|
121
|
-
* Register callback invoked after fetch and hydration.
|
|
122
|
-
*
|
|
123
|
-
* @param callback - Callback function
|
|
124
|
-
* @returns Unsubscribe function
|
|
125
|
-
*/
|
|
110
|
+
/** Register a callback invoked after fetch and hydration. */
|
|
126
111
|
onFetched(callback: (records: unknown[], context: unknown) => void | Promise<void>): () => void;
|
|
127
|
-
/**
|
|
128
|
-
* Disable one or more global scopes for this query.
|
|
129
|
-
*
|
|
130
|
-
* @param scopeNames - Scope names to disable
|
|
131
|
-
* @returns This builder for chaining
|
|
132
|
-
*/
|
|
133
|
-
withoutGlobalScope(...scopeNames: string[]): this;
|
|
134
|
-
/**
|
|
135
|
-
* Disable all global scopes for this query.
|
|
136
|
-
*
|
|
137
|
-
* @returns This builder for chaining
|
|
138
|
-
*/
|
|
139
|
-
withoutGlobalScopes(): this;
|
|
140
|
-
/**
|
|
141
|
-
* Apply a local scope to this query.
|
|
142
|
-
*
|
|
143
|
-
* @param scopeName - Name of the local scope
|
|
144
|
-
* @returns This builder for chaining
|
|
145
|
-
*/
|
|
146
|
-
scope(scopeName: string): this;
|
|
147
|
-
/**
|
|
148
|
-
* Apply pending global scopes before query execution.
|
|
149
|
-
*/
|
|
112
|
+
/** Apply pending global scopes to the operations list. */
|
|
150
113
|
private applyPendingScopes;
|
|
151
|
-
/**
|
|
152
|
-
* Add a WHERE clause to filter records.
|
|
153
|
-
*/
|
|
154
|
-
where(field: string, value: unknown): this;
|
|
155
|
-
where(field: string, operator: WhereOperator, value: unknown): this;
|
|
156
|
-
where(conditions: WhereObject): this;
|
|
157
|
-
where(callback: WhereCallback<T>): this;
|
|
158
|
-
/**
|
|
159
|
-
* Add an OR WHERE clause.
|
|
160
|
-
*/
|
|
161
|
-
orWhere(field: string, value: unknown): this;
|
|
162
|
-
orWhere(field: string, operator: WhereOperator, value: unknown): this;
|
|
163
|
-
orWhere(conditions: WhereObject): this;
|
|
164
|
-
orWhere(callback: WhereCallback<T>): this;
|
|
165
|
-
/**
|
|
166
|
-
* Add a raw WHERE clause.
|
|
167
|
-
*/
|
|
168
|
-
whereRaw(expression: RawExpression, bindings?: unknown[]): this;
|
|
169
|
-
/**
|
|
170
|
-
* Add a raw OR WHERE clause.
|
|
171
|
-
*/
|
|
172
|
-
orWhereRaw(expression: RawExpression, bindings?: unknown[]): this;
|
|
173
|
-
/**
|
|
174
|
-
* Compare two columns.
|
|
175
|
-
*/
|
|
176
|
-
whereColumn(first: string, operator: WhereOperator, second: string): this;
|
|
177
|
-
/**
|
|
178
|
-
* Compare two columns with OR.
|
|
179
|
-
*/
|
|
180
|
-
orWhereColumn(first: string, operator: WhereOperator, second: string): this;
|
|
181
|
-
/**
|
|
182
|
-
* Compare multiple column pairs.
|
|
183
|
-
*/
|
|
184
|
-
whereColumns(comparisons: Array<[left: string, operator: WhereOperator, right: string]>): this;
|
|
185
|
-
/**
|
|
186
|
-
* Check if field is between two columns.
|
|
187
|
-
*/
|
|
188
|
-
whereBetweenColumns(field: string, lowerColumn: string, upperColumn: string): this;
|
|
189
|
-
/**
|
|
190
|
-
* Filter by date (ignoring time).
|
|
191
|
-
*/
|
|
192
|
-
whereDate(field: string, value: Date | string): this;
|
|
193
|
-
/**
|
|
194
|
-
* Alias for whereDate.
|
|
195
|
-
*/
|
|
196
|
-
whereDateEquals(field: string, value: Date | string): this;
|
|
197
|
-
/**
|
|
198
|
-
* Filter for dates before a value.
|
|
199
|
-
*/
|
|
200
|
-
whereDateBefore(field: string, value: Date | string): this;
|
|
201
|
-
/**
|
|
202
|
-
* Filter for dates after a value.
|
|
203
|
-
*/
|
|
204
|
-
whereDateAfter(field: string, value: Date | string): this;
|
|
205
|
-
/**
|
|
206
|
-
* Filter by time.
|
|
207
|
-
*/
|
|
208
|
-
whereTime(field: string, value: string): this;
|
|
209
|
-
/**
|
|
210
|
-
* Filter by day of month.
|
|
211
|
-
*/
|
|
212
|
-
whereDay(field: string, value: number): this;
|
|
213
|
-
/**
|
|
214
|
-
* Filter by month.
|
|
215
|
-
*/
|
|
216
|
-
whereMonth(field: string, value: number): this;
|
|
217
|
-
/**
|
|
218
|
-
* Filter by year.
|
|
219
|
-
*/
|
|
220
|
-
whereYear(field: string, value: number): this;
|
|
221
|
-
/**
|
|
222
|
-
* Check if JSON contains value.
|
|
223
|
-
*/
|
|
224
|
-
whereJsonContains(path: string, value: unknown): this;
|
|
225
|
-
/**
|
|
226
|
-
* Check if JSON doesn't contain value.
|
|
227
|
-
*/
|
|
228
|
-
whereJsonDoesntContain(path: string, value: unknown): this;
|
|
229
|
-
/**
|
|
230
|
-
* Check if JSON contains key.
|
|
231
|
-
*/
|
|
232
|
-
whereJsonContainsKey(path: string): this;
|
|
233
|
-
/**
|
|
234
|
-
* Check JSON array/string length.
|
|
235
|
-
*/
|
|
236
|
-
whereJsonLength(path: string, operator: WhereOperator, value: number): this;
|
|
237
|
-
/**
|
|
238
|
-
* Check if JSON is array.
|
|
239
|
-
*/
|
|
240
|
-
whereJsonIsArray(path: string): this;
|
|
241
|
-
/**
|
|
242
|
-
* Check if JSON is object.
|
|
243
|
-
*/
|
|
244
|
-
whereJsonIsObject(path: string): this;
|
|
245
|
-
/**
|
|
246
|
-
* Check array length.
|
|
247
|
-
*/
|
|
248
|
-
whereArrayLength(field: string, operator: WhereOperator, value: number): this;
|
|
249
|
-
/**
|
|
250
|
-
* Filter by ID.
|
|
251
|
-
*/
|
|
252
|
-
whereId(value: string | number): this;
|
|
253
|
-
/**
|
|
254
|
-
* Filter by multiple IDs.
|
|
255
|
-
*/
|
|
256
|
-
whereIds(values: Array<string | number>): this;
|
|
257
|
-
/**
|
|
258
|
-
* Filter by UUID.
|
|
259
|
-
*/
|
|
260
|
-
whereUuid(value: string): this;
|
|
261
|
-
/**
|
|
262
|
-
* Filter by ULID.
|
|
263
|
-
*/
|
|
264
|
-
whereUlid(value: string): this;
|
|
265
|
-
/**
|
|
266
|
-
* Full-text search.
|
|
267
|
-
*/
|
|
268
|
-
whereFullText(fields: string | string[], query: string): this;
|
|
269
|
-
/**
|
|
270
|
-
* Full-text search with OR.
|
|
271
|
-
*/
|
|
272
|
-
orWhereFullText(fields: string | string[], query: string): this;
|
|
273
|
-
/**
|
|
274
|
-
* Alias for whereFullText.
|
|
275
|
-
*/
|
|
276
|
-
whereSearch(field: string, query: string): this;
|
|
277
|
-
/**
|
|
278
|
-
* Negate conditions.
|
|
279
|
-
*/
|
|
280
|
-
whereNot(callback: WhereCallback<T>): this;
|
|
281
|
-
/**
|
|
282
|
-
* Negate conditions with OR.
|
|
283
|
-
*/
|
|
284
|
-
orWhereNot(callback: WhereCallback<T>): this;
|
|
285
|
-
/**
|
|
286
|
-
* Filter by value in array.
|
|
287
|
-
*/
|
|
288
|
-
whereIn(field: string, values: unknown[]): this;
|
|
289
|
-
/**
|
|
290
|
-
* Filter by value not in array.
|
|
291
|
-
*/
|
|
292
|
-
whereNotIn(field: string, values: unknown[]): this;
|
|
293
|
-
/**
|
|
294
|
-
* Filter by NULL value.
|
|
295
|
-
*/
|
|
296
|
-
whereNull(field: string): this;
|
|
297
|
-
/**
|
|
298
|
-
* Filter by NOT NULL value.
|
|
299
|
-
*/
|
|
300
|
-
whereNotNull(field: string): this;
|
|
301
|
-
/**
|
|
302
|
-
* Filter by range (inclusive).
|
|
303
|
-
*/
|
|
304
|
-
whereBetween(field: string, range: [unknown, unknown]): this;
|
|
305
|
-
/**
|
|
306
|
-
* Filter by not in range.
|
|
307
|
-
*/
|
|
308
|
-
whereNotBetween(field: string, range: [unknown, unknown]): this;
|
|
309
|
-
/**
|
|
310
|
-
* Filter by LIKE pattern (case-insensitive).
|
|
311
|
-
*/
|
|
312
|
-
whereLike(field: string, pattern: RegExp | string): this;
|
|
313
|
-
/**
|
|
314
|
-
* Filter by NOT LIKE pattern.
|
|
315
|
-
*/
|
|
316
|
-
whereNotLike(field: string, pattern: RegExp | string): this;
|
|
317
|
-
/**
|
|
318
|
-
* Filter by prefix.
|
|
319
|
-
*/
|
|
320
|
-
whereStartsWith(field: string, value: string | number): this;
|
|
321
|
-
/**
|
|
322
|
-
* Filter by not starting with prefix.
|
|
323
|
-
*/
|
|
324
|
-
whereNotStartsWith(field: string, value: string | number): this;
|
|
325
|
-
/**
|
|
326
|
-
* Filter by suffix.
|
|
327
|
-
*/
|
|
328
|
-
whereEndsWith(field: string, value: string | number): this;
|
|
329
|
-
/**
|
|
330
|
-
* Filter by not ending with suffix.
|
|
331
|
-
*/
|
|
332
|
-
whereNotEndsWith(field: string, value: string | number): this;
|
|
333
|
-
/**
|
|
334
|
-
* Filter by date range.
|
|
335
|
-
*/
|
|
336
|
-
whereDateBetween(field: string, range: [Date, Date]): this;
|
|
337
|
-
/**
|
|
338
|
-
* Filter by not in date range.
|
|
339
|
-
*/
|
|
340
|
-
whereDateNotBetween(field: string, range: [Date, Date]): this;
|
|
341
|
-
/**
|
|
342
|
-
* Check if field/subquery exists.
|
|
343
|
-
*/
|
|
344
|
-
whereExists(field: string): this;
|
|
345
|
-
whereExists(callback: WhereCallback<T>): this;
|
|
346
|
-
/**
|
|
347
|
-
* Check if field/subquery doesn't exist.
|
|
348
|
-
*/
|
|
349
|
-
whereNotExists(field: string): this;
|
|
350
|
-
whereNotExists(callback: WhereCallback<T>): this;
|
|
351
|
-
/**
|
|
352
|
-
* Check array size.
|
|
353
|
-
*/
|
|
354
|
-
whereSize(field: string, size: number): this;
|
|
355
|
-
whereSize(field: string, operator: WhereOperator, size: number): this;
|
|
356
|
-
/**
|
|
357
|
-
* Perform a full-text search.
|
|
358
|
-
*/
|
|
359
|
-
textSearch(query: string, filters?: WhereObject): this;
|
|
360
|
-
/**
|
|
361
|
-
* Constrain an array field to contain the given value.
|
|
362
|
-
*/
|
|
114
|
+
/** Array field contains a value (or object with key). */
|
|
363
115
|
whereArrayContains(field: string, value: unknown, key?: string): this;
|
|
364
|
-
/**
|
|
365
|
-
* Constrain an array field to not contain the given value.
|
|
366
|
-
*/
|
|
116
|
+
/** Array field does NOT contain a value (or object with key). */
|
|
367
117
|
whereArrayNotContains(field: string, value: unknown, key?: string): this;
|
|
368
|
-
/**
|
|
369
|
-
* Constrain an array field to contain the value OR be empty.
|
|
370
|
-
*/
|
|
118
|
+
/** Array field contains value OR is empty. */
|
|
371
119
|
whereArrayHasOrEmpty(field: string, value: unknown, key?: string): this;
|
|
372
|
-
/**
|
|
373
|
-
* Constrain an array field to not contain the value OR be empty.
|
|
374
|
-
*/
|
|
120
|
+
/** Array field does NOT contain value OR is empty. */
|
|
375
121
|
whereArrayNotHaveOrEmpty(field: string, value: unknown, key?: string): this;
|
|
376
122
|
/**
|
|
377
|
-
*
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
*
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
*
|
|
388
|
-
|
|
389
|
-
rightJoin(table: string, localField: string, foreignField: string): this;
|
|
390
|
-
rightJoin(options: JoinOptions): this;
|
|
391
|
-
/**
|
|
392
|
-
* Add an INNER JOIN clause.
|
|
393
|
-
*/
|
|
394
|
-
innerJoin(table: string, localField: string, foreignField: string): this;
|
|
395
|
-
innerJoin(options: JoinOptions): this;
|
|
396
|
-
/**
|
|
397
|
-
* Add a FULL OUTER JOIN clause.
|
|
398
|
-
*/
|
|
399
|
-
fullJoin(table: string, localField: string, foreignField: string): this;
|
|
400
|
-
fullJoin(options: JoinOptions): this;
|
|
401
|
-
/**
|
|
402
|
-
* Add a CROSS JOIN clause.
|
|
403
|
-
*/
|
|
404
|
-
crossJoin(table: string): this;
|
|
405
|
-
/**
|
|
406
|
-
* Add a raw JOIN clause.
|
|
407
|
-
*/
|
|
408
|
-
joinRaw(expression: RawExpression, bindings?: unknown[]): this;
|
|
409
|
-
/**
|
|
410
|
-
* Select specific columns.
|
|
411
|
-
*/
|
|
412
|
-
select(fields: string[]): this;
|
|
413
|
-
select(fields: Record<string, 0 | 1 | boolean>): this;
|
|
414
|
-
select(...fields: Array<string | string[]>): this;
|
|
415
|
-
/**
|
|
416
|
-
* Select a field with alias.
|
|
417
|
-
*/
|
|
418
|
-
selectAs(field: string, alias: string): this;
|
|
419
|
-
/**
|
|
420
|
-
* Select raw expression.
|
|
421
|
-
*/
|
|
422
|
-
selectRaw(expression: RawExpression, bindings?: unknown[]): this;
|
|
423
|
-
/**
|
|
424
|
-
* Select multiple raw expressions.
|
|
425
|
-
*/
|
|
426
|
-
selectRawMany(definitions: Array<{
|
|
427
|
-
alias: string;
|
|
428
|
-
expression: RawExpression;
|
|
429
|
-
bindings?: unknown[];
|
|
430
|
-
}>): this;
|
|
431
|
-
/**
|
|
432
|
-
* Select subquery.
|
|
433
|
-
*/
|
|
434
|
-
selectSub(expression: RawExpression, alias: string): this;
|
|
435
|
-
/**
|
|
436
|
-
* Add subquery to existing selection.
|
|
437
|
-
*/
|
|
438
|
-
addSelectSub(expression: RawExpression, alias: string): this;
|
|
439
|
-
/**
|
|
440
|
-
* Select aggregate value.
|
|
441
|
-
*/
|
|
442
|
-
selectAggregate(field: string, aggregate: "sum" | "avg" | "min" | "max" | "count" | "first" | "last", alias: string): this;
|
|
443
|
-
/**
|
|
444
|
-
* Select existence check.
|
|
445
|
-
*/
|
|
446
|
-
selectExists(field: string, alias: string): this;
|
|
447
|
-
/**
|
|
448
|
-
* Select count.
|
|
449
|
-
*/
|
|
450
|
-
selectCount(field: string, alias: string): this;
|
|
451
|
-
/**
|
|
452
|
-
* Select CASE expression.
|
|
453
|
-
*/
|
|
454
|
-
selectCase(cases: Array<{
|
|
455
|
-
when: RawExpression;
|
|
456
|
-
then: RawExpression | unknown;
|
|
457
|
-
}>, otherwise: RawExpression | unknown, alias: string): this;
|
|
458
|
-
/**
|
|
459
|
-
* Select conditional (IF/ELSE).
|
|
460
|
-
*/
|
|
461
|
-
selectWhen(condition: RawExpression, thenValue: RawExpression | unknown, elseValue: RawExpression | unknown, alias: string): this;
|
|
462
|
-
/**
|
|
463
|
-
* Direct projection manipulation.
|
|
464
|
-
*/
|
|
465
|
-
selectDriverProjection(callback: (projection: Record<string, unknown>) => void): this;
|
|
466
|
-
/**
|
|
467
|
-
* Select JSON path.
|
|
468
|
-
*/
|
|
469
|
-
selectJson(path: string, alias?: string): this;
|
|
470
|
-
/**
|
|
471
|
-
* Select JSON path with raw expression.
|
|
472
|
-
*/
|
|
473
|
-
selectJsonRaw(path: string, expression: RawExpression, alias: string): this;
|
|
474
|
-
/**
|
|
475
|
-
* Exclude JSON path.
|
|
476
|
-
*/
|
|
477
|
-
deselectJson(path: string): this;
|
|
478
|
-
/**
|
|
479
|
-
* Concatenate fields.
|
|
480
|
-
*/
|
|
481
|
-
selectConcat(fields: Array<string | RawExpression>, alias: string): this;
|
|
482
|
-
/**
|
|
483
|
-
* Coalesce values.
|
|
484
|
-
*/
|
|
485
|
-
selectCoalesce(fields: Array<string | RawExpression>, alias: string): this;
|
|
486
|
-
/**
|
|
487
|
-
* Window function.
|
|
488
|
-
*/
|
|
489
|
-
selectWindow(spec: RawExpression): this;
|
|
490
|
-
/**
|
|
491
|
-
* Exclude columns from projection.
|
|
492
|
-
*/
|
|
493
|
-
deselect(fields: string[]): this;
|
|
494
|
-
/**
|
|
495
|
-
* Clear selection.
|
|
496
|
-
*/
|
|
497
|
-
clearSelect(): this;
|
|
498
|
-
/**
|
|
499
|
-
* Select all columns.
|
|
500
|
-
*/
|
|
501
|
-
selectAll(): this;
|
|
502
|
-
/**
|
|
503
|
-
* Restore default projection.
|
|
504
|
-
*/
|
|
505
|
-
selectDefault(): this;
|
|
506
|
-
/**
|
|
507
|
-
* Select distinct values.
|
|
508
|
-
*/
|
|
509
|
-
distinctValues(fields?: string | string[]): this;
|
|
510
|
-
/**
|
|
511
|
-
* Add additional select fields.
|
|
512
|
-
*/
|
|
513
|
-
addSelect(fields: string[]): this;
|
|
514
|
-
/**
|
|
515
|
-
* Order results.
|
|
516
|
-
*/
|
|
517
|
-
orderBy(field: string, direction?: OrderDirection): this;
|
|
518
|
-
orderBy(fields: Record<string, OrderDirection>): this;
|
|
519
|
-
/**
|
|
520
|
-
* Order descending.
|
|
521
|
-
*/
|
|
522
|
-
orderByDesc(field: string): this;
|
|
523
|
-
/**
|
|
524
|
-
* Order with raw expression.
|
|
525
|
-
*/
|
|
526
|
-
orderByRaw(expression: RawExpression, bindings?: unknown[]): this;
|
|
527
|
-
/**
|
|
528
|
-
* Order randomly.
|
|
529
|
-
*/
|
|
530
|
-
orderByRandom(limit: number): this;
|
|
531
|
-
/**
|
|
532
|
-
* Get latest records.
|
|
533
|
-
*/
|
|
534
|
-
latest(column?: string): Promise<T[]>;
|
|
535
|
-
/**
|
|
536
|
-
* Get oldest records.
|
|
537
|
-
*/
|
|
538
|
-
oldest(column?: string): this;
|
|
539
|
-
/**
|
|
540
|
-
* Limit results.
|
|
541
|
-
*/
|
|
542
|
-
limit(value: number): this;
|
|
543
|
-
/**
|
|
544
|
-
* Skip results.
|
|
545
|
-
*/
|
|
546
|
-
skip(value: number): this;
|
|
547
|
-
/**
|
|
548
|
-
* Offset results.
|
|
549
|
-
*/
|
|
550
|
-
offset(value: number): this;
|
|
551
|
-
/**
|
|
552
|
-
* Take first N results.
|
|
553
|
-
*/
|
|
554
|
-
take(value: number): this;
|
|
555
|
-
/**
|
|
556
|
-
* Apply cursor pagination hints.
|
|
557
|
-
*/
|
|
558
|
-
cursor(after?: unknown, before?: unknown): this;
|
|
559
|
-
/**
|
|
560
|
-
* Group results.
|
|
561
|
-
*/
|
|
562
|
-
groupBy(input: GroupByInput): this;
|
|
563
|
-
/**
|
|
564
|
-
* Raw GROUP BY.
|
|
565
|
-
*/
|
|
566
|
-
groupByRaw(expression: RawExpression, bindings?: unknown[]): this;
|
|
567
|
-
/**
|
|
568
|
-
* HAVING clause.
|
|
569
|
-
*/
|
|
570
|
-
having(field: string, value: unknown): this;
|
|
571
|
-
having(field: string, operator: WhereOperator, value: unknown): this;
|
|
572
|
-
having(condition: HavingInput): this;
|
|
573
|
-
/**
|
|
574
|
-
* Raw HAVING clause.
|
|
123
|
+
* Load relations via SQL JOINs (single query) with optional per-relation constraints.
|
|
124
|
+
*
|
|
125
|
+
* Supports:
|
|
126
|
+
* - `joinWith("author")` / `joinWith(["author", "category"])`
|
|
127
|
+
* - `joinWith({ actions: q => q.where("status", "pending").limit(5) })`
|
|
128
|
+
* - `joinWith({ organizationAiModel: "id,name", actions: q => q.orderBy("sort_order") })`
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ChatMessage.joinWith({
|
|
132
|
+
* actions: q => q.where("status", "pending").orderBy("sort_order", "asc").limit(5),
|
|
133
|
+
* organizationAiModel: "id,createdAt",
|
|
134
|
+
* })
|
|
575
135
|
*/
|
|
576
|
-
|
|
136
|
+
joinWith(...args: unknown[]): this;
|
|
137
|
+
/** Run a joinWith constraint callback against a sub-QB and capture its operations. */
|
|
138
|
+
private _resolveConstraintOps;
|
|
577
139
|
/**
|
|
578
|
-
* Execute query and
|
|
140
|
+
* Execute the query and return all matching rows.
|
|
579
141
|
*/
|
|
580
142
|
get<TResult = T>(): Promise<TResult[]>;
|
|
581
|
-
/**
|
|
582
|
-
* Apply JOIN operations for joinWith() relations.
|
|
583
|
-
*/
|
|
584
|
-
private applyJoinRelations;
|
|
585
|
-
/**
|
|
586
|
-
* Extract joined relation data from raw records.
|
|
587
|
-
* Returns a map of record index to relation data.
|
|
588
|
-
*/
|
|
589
|
-
private extractJoinedRelationData;
|
|
590
|
-
/**
|
|
591
|
-
* Attach joined relations to hydrated models.
|
|
592
|
-
*/
|
|
593
|
-
private attachJoinedRelations;
|
|
594
|
-
/**
|
|
595
|
-
* Get first result.
|
|
596
|
-
*/
|
|
143
|
+
/** Get first result. */
|
|
597
144
|
first<TResult = T>(): Promise<TResult | null>;
|
|
598
|
-
/**
|
|
599
|
-
* Get last result.
|
|
600
|
-
*/
|
|
145
|
+
/** Get last result (by id desc). */
|
|
601
146
|
last<TResult = T>(): Promise<TResult | null>;
|
|
602
|
-
/**
|
|
603
|
-
* Get random results.
|
|
604
|
-
*/
|
|
147
|
+
/** Get random results. */
|
|
605
148
|
random<TResult = T>(limit?: number): Promise<TResult[]>;
|
|
606
|
-
/**
|
|
607
|
-
* Get first or throw.
|
|
608
|
-
*/
|
|
149
|
+
/** Get first or throw. */
|
|
609
150
|
firstOrFail<TResult = T>(): Promise<TResult>;
|
|
610
|
-
/**
|
|
611
|
-
* Get first or call callback.
|
|
612
|
-
*/
|
|
151
|
+
/** Get first or call callback. */
|
|
613
152
|
firstOr<TResult = T>(callback: () => TResult | Promise<TResult>): Promise<TResult>;
|
|
614
|
-
/**
|
|
615
|
-
* Get first or return default.
|
|
616
|
-
*/
|
|
153
|
+
/** Get first or return null. */
|
|
617
154
|
firstOrNull<TResult = T>(): Promise<TResult | null>;
|
|
618
|
-
/**
|
|
619
|
-
* Get first or create new.
|
|
620
|
-
*/
|
|
155
|
+
/** Get first or return default. */
|
|
621
156
|
firstOrNew<TResult = T>(defaults: GenericObject): Promise<TResult>;
|
|
622
|
-
/**
|
|
623
|
-
* Find by ID.
|
|
624
|
-
*/
|
|
157
|
+
/** Find by primary key. */
|
|
625
158
|
find<TResult = T>(id: number | string): Promise<TResult | null>;
|
|
626
|
-
/**
|
|
627
|
-
* Count results.
|
|
628
|
-
*/
|
|
159
|
+
/** Count matching rows. */
|
|
629
160
|
count(): Promise<number>;
|
|
630
|
-
/**
|
|
631
|
-
* Sum of field values.
|
|
632
|
-
*/
|
|
161
|
+
/** SUM a numeric field. */
|
|
633
162
|
sum(field: string): Promise<number>;
|
|
634
|
-
/**
|
|
635
|
-
* Average of field values.
|
|
636
|
-
*/
|
|
163
|
+
/** AVG of a numeric field. */
|
|
637
164
|
avg(field: string): Promise<number>;
|
|
638
|
-
/**
|
|
639
|
-
* Minimum field value.
|
|
640
|
-
*/
|
|
165
|
+
/** MIN of a numeric field. */
|
|
641
166
|
min(field: string): Promise<number>;
|
|
642
|
-
/**
|
|
643
|
-
* Maximum field value.
|
|
644
|
-
*/
|
|
167
|
+
/** MAX of a numeric field. */
|
|
645
168
|
max(field: string): Promise<number>;
|
|
646
|
-
/**
|
|
647
|
-
* Get distinct values.
|
|
648
|
-
*/
|
|
169
|
+
/** Get distinct values for a field. */
|
|
649
170
|
distinct<TResult = unknown>(field: string): Promise<TResult[]>;
|
|
650
|
-
/**
|
|
651
|
-
* Get array of values for field.
|
|
652
|
-
*/
|
|
171
|
+
/** Get array of all values for a single field. */
|
|
653
172
|
pluck(field: string): Promise<unknown[]>;
|
|
654
|
-
/**
|
|
655
|
-
* Get single scalar value.
|
|
656
|
-
*/
|
|
173
|
+
/** Get a single scalar value. */
|
|
657
174
|
value<TResult = unknown>(field: string): Promise<TResult | null>;
|
|
658
|
-
/**
|
|
659
|
-
* Check if records exist.
|
|
660
|
-
*/
|
|
175
|
+
/** Check whether any matching rows exist. */
|
|
661
176
|
exists(): Promise<boolean>;
|
|
662
|
-
/**
|
|
663
|
-
* Check if no records exist.
|
|
664
|
-
*/
|
|
177
|
+
/** Check whether NO matching rows exist. */
|
|
665
178
|
notExists(): Promise<boolean>;
|
|
666
|
-
/**
|
|
667
|
-
* Count distinct values.
|
|
668
|
-
*/
|
|
179
|
+
/** COUNT DISTINCT a field. */
|
|
669
180
|
countDistinct(field: string): Promise<number>;
|
|
670
|
-
/**
|
|
671
|
-
|
|
672
|
-
|
|
181
|
+
/** Get latest records ordered by a column. */
|
|
182
|
+
latest(column?: string): Promise<T[]>;
|
|
183
|
+
/** Increment a numeric field. Returns new value. */
|
|
673
184
|
increment(field: string, amount?: number): Promise<number>;
|
|
674
|
-
/**
|
|
675
|
-
* Decrement field value.
|
|
676
|
-
*/
|
|
185
|
+
/** Decrement a numeric field. Returns new value. */
|
|
677
186
|
decrement(field: string, amount?: number): Promise<number>;
|
|
678
|
-
/**
|
|
679
|
-
* Increment for all matching.
|
|
680
|
-
*/
|
|
187
|
+
/** Increment a field for all matching rows. Returns affected row count. */
|
|
681
188
|
incrementMany(field: string, amount?: number): Promise<number>;
|
|
682
|
-
/**
|
|
683
|
-
* Decrement for all matching.
|
|
684
|
-
*/
|
|
189
|
+
/** Decrement a field for all matching rows. Returns affected row count. */
|
|
685
190
|
decrementMany(field: string, amount?: number): Promise<number>;
|
|
686
191
|
/**
|
|
687
|
-
* Process results in chunks.
|
|
192
|
+
* Process results in memory-efficient chunks.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* await User.query().chunk(100, async (rows, idx) => { ... })
|
|
688
196
|
*/
|
|
689
197
|
chunk(size: number, callback: ChunkCallback<T>): Promise<void>;
|
|
690
|
-
/**
|
|
691
|
-
* Page-based pagination.
|
|
692
|
-
*/
|
|
198
|
+
/** Page-based pagination. */
|
|
693
199
|
paginate(options?: PaginationOptions): Promise<PaginationResult<T>>;
|
|
694
200
|
/**
|
|
695
|
-
*
|
|
201
|
+
* Set cursor pagination hints fluently.
|
|
202
|
+
* The recorded values are picked up by `cursorPaginate()` when no explicit
|
|
203
|
+
* options are passed.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* User.query().cursor(lastId).cursorPaginate({ limit: 20 })
|
|
696
207
|
*/
|
|
208
|
+
cursor(after?: unknown, before?: unknown): this;
|
|
209
|
+
/** Cursor-based pagination. */
|
|
697
210
|
cursorPaginate(options?: CursorPaginationOptions): Promise<CursorPaginationResult<T>>;
|
|
698
|
-
/**
|
|
699
|
-
* Delete matching records.
|
|
700
|
-
*/
|
|
211
|
+
/** Delete matching rows. Returns deleted count. */
|
|
701
212
|
delete(): Promise<number>;
|
|
702
|
-
/**
|
|
703
|
-
* Delete first matching record.
|
|
704
|
-
*/
|
|
213
|
+
/** Delete the first matching row. */
|
|
705
214
|
deleteOne(): Promise<number>;
|
|
706
|
-
/**
|
|
707
|
-
* Update matching records.
|
|
708
|
-
*/
|
|
215
|
+
/** Update matching rows. */
|
|
709
216
|
update(fields: Record<string, unknown>): Promise<number>;
|
|
710
|
-
/**
|
|
711
|
-
* Unset fields from matching records.
|
|
712
|
-
*/
|
|
217
|
+
/** Unset fields from matching rows. */
|
|
713
218
|
unset(...fields: string[]): Promise<number>;
|
|
714
|
-
/**
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
parse(): {
|
|
718
|
-
sql: string;
|
|
719
|
-
params: unknown[];
|
|
720
|
-
};
|
|
721
|
-
/**
|
|
722
|
-
* Get formatted SQL string.
|
|
723
|
-
*/
|
|
219
|
+
/** Return the SQL + bindings without executing. */
|
|
220
|
+
parse(): DriverQuery;
|
|
221
|
+
/** Formatted SQL string (for logging/debugging). */
|
|
724
222
|
pretty(): string;
|
|
725
|
-
/**
|
|
726
|
-
* Get query execution plan.
|
|
727
|
-
*/
|
|
223
|
+
/** Run EXPLAIN ANALYZE on the query. */
|
|
728
224
|
explain(): Promise<unknown>;
|
|
729
|
-
/**
|
|
730
|
-
* Add driver-specific raw modifications to the query.
|
|
731
|
-
*/
|
|
732
|
-
raw(builder: (native: unknown) => unknown): this;
|
|
733
|
-
/**
|
|
734
|
-
* Extend the query builder with driver-specific extensions.
|
|
735
|
-
*/
|
|
225
|
+
/** Extend the builder with a driver-specific extension. */
|
|
736
226
|
extend<R>(extension: string, ..._args: unknown[]): R;
|
|
227
|
+
/** Pluck scalar values for a single field (alias for pluck). */
|
|
228
|
+
pluckOne<TResult = unknown>(field: string): Promise<TResult[]>;
|
|
737
229
|
/**
|
|
738
|
-
*
|
|
739
|
-
|
|
740
|
-
tap(callback: (builder: this) => void): this;
|
|
741
|
-
/**
|
|
742
|
-
* Conditionally apply query modifications.
|
|
743
|
-
*/
|
|
744
|
-
when<V>(condition: V | boolean, callback: (builder: this, value: V) => void, otherwise?: (builder: this) => void): this;
|
|
745
|
-
/**
|
|
746
|
-
* Build WHERE clause from current operations.
|
|
747
|
-
*/
|
|
748
|
-
private buildFilter;
|
|
749
|
-
/**
|
|
750
|
-
* Relations to eagerly load.
|
|
230
|
+
* Before `get()` runs the parser, consume any joinWith ops recorded by the base
|
|
231
|
+
* class and expand them into the joinRelations Map.
|
|
751
232
|
*/
|
|
752
|
-
|
|
233
|
+
private _processJoinWithOps;
|
|
753
234
|
/**
|
|
754
|
-
*
|
|
235
|
+
* Translate each entry in `joinRelations` into actual JOIN + selectRelatedColumns operations.
|
|
755
236
|
*/
|
|
756
|
-
|
|
757
|
-
/**
|
|
758
|
-
* Relations to load via JOIN (single query).
|
|
759
|
-
*/
|
|
760
|
-
joinRelations: Map<string, {
|
|
761
|
-
alias: string;
|
|
762
|
-
type: "belongsTo" | "hasOne" | "hasMany";
|
|
763
|
-
}>;
|
|
764
|
-
/**
|
|
765
|
-
* Relation definitions from the model.
|
|
766
|
-
*/
|
|
767
|
-
relationDefinitions?: Record<string, any>;
|
|
768
|
-
/**
|
|
769
|
-
* Model class reference.
|
|
770
|
-
*/
|
|
771
|
-
modelClass?: any;
|
|
772
|
-
/**
|
|
773
|
-
* Load relations using database JOINs in a single query.
|
|
774
|
-
*
|
|
775
|
-
* Unlike `with()` which uses separate queries, `joinWith()` uses
|
|
776
|
-
* LEFT JOIN to fetch related data in a single query.
|
|
777
|
-
*
|
|
778
|
-
* @param relations - Relation names to load via JOIN
|
|
779
|
-
* @returns This builder for chaining
|
|
780
|
-
*/
|
|
781
|
-
joinWith(...relations: string[]): this;
|
|
782
|
-
/**
|
|
783
|
-
* Eagerly load one or more relations.
|
|
784
|
-
*
|
|
785
|
-
* Supported patterns:
|
|
786
|
-
* - `with("posts")` - Load relation
|
|
787
|
-
* - `with("posts", "comments")` - Load multiple relations
|
|
788
|
-
* - `with("posts", callback)` - Load relation with constraint
|
|
789
|
-
* - `with({ posts: true, comments: callback })` - Object configuration
|
|
790
|
-
*
|
|
791
|
-
* @param args - Relation name(s), callbacks, or configuration object
|
|
792
|
-
*/
|
|
793
|
-
with(...args: (string | Record<string, boolean | ((query: QueryBuilderContract) => void)> | ((query: QueryBuilderContract) => void))[]): this;
|
|
794
|
-
/**
|
|
795
|
-
* Add a count of related models as a virtual field.
|
|
796
|
-
* @param relations - Relation name(s) to count
|
|
797
|
-
*/
|
|
798
|
-
withCount(...relations: string[]): this;
|
|
799
|
-
/**
|
|
800
|
-
* Filter results to only those that have related models.
|
|
801
|
-
* @param relation - Relation name
|
|
802
|
-
* @param operator - Optional comparison operator
|
|
803
|
-
* @param count - Optional count to compare against
|
|
804
|
-
*/
|
|
805
|
-
has(relation: string, operator?: string, count?: number): this;
|
|
237
|
+
private applyJoinRelations;
|
|
806
238
|
/**
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
* @param callback - Callback to define conditions
|
|
239
|
+
* Extract per-relation data from raw DB rows (before hydration).
|
|
240
|
+
* Returns a Map of row index → nested relation data tree.
|
|
810
241
|
*/
|
|
811
|
-
|
|
242
|
+
private extractJoinedRelationData;
|
|
812
243
|
/**
|
|
813
|
-
*
|
|
814
|
-
* @param relation - Relation name
|
|
244
|
+
* Attach extracted relation data to hydrated model instances.
|
|
815
245
|
*/
|
|
816
|
-
|
|
246
|
+
private attachJoinedRelations;
|
|
817
247
|
/**
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
* @param callback - Callback to define conditions
|
|
248
|
+
* Build a WHERE-only SQL fragment from `where*` operations on the current builder.
|
|
249
|
+
* Used by DELETE / UPDATE / increment paths.
|
|
821
250
|
*/
|
|
822
|
-
|
|
251
|
+
private buildFilter;
|
|
823
252
|
}
|
|
253
|
+
export {};
|
|
824
254
|
//# sourceMappingURL=postgres-query-builder.d.ts.map
|