@warlock.js/cascade 4.0.174 → 4.1.1
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/README.md +6 -5
- package/bin/cascadejs +3 -0
- package/esm/cli/commands/migrate-export-sql.mjs +48 -0
- package/esm/cli/commands/migrate-export-sql.mjs.map +1 -0
- package/esm/cli/commands/migrate-list.mjs +26 -0
- package/esm/cli/commands/migrate-list.mjs.map +1 -0
- package/esm/cli/commands/migrate-rollback.mjs +50 -0
- package/esm/cli/commands/migrate-rollback.mjs.map +1 -0
- package/esm/cli/commands/migrate.mjs +65 -0
- package/esm/cli/commands/migrate.mjs.map +1 -0
- package/esm/cli/connection-from-env.mjs +181 -0
- package/esm/cli/connection-from-env.mjs.map +1 -0
- package/esm/cli/index.mjs +31 -0
- package/esm/cli/index.mjs.map +1 -0
- package/esm/cli/load-migrations.mjs +78 -0
- package/esm/cli/load-migrations.mjs.map +1 -0
- package/esm/cli/printers.mjs +57 -0
- package/esm/cli/printers.mjs.map +1 -0
- package/esm/cli/setup-logger.mjs +30 -0
- package/esm/cli/setup-logger.mjs.map +1 -0
- package/esm/cli/with-cli-connection.mjs +39 -0
- package/esm/cli/with-cli-connection.mjs.map +1 -0
- package/esm/cli.d.mts +1 -0
- package/esm/cli.mjs +26 -0
- package/esm/cli.mjs.map +1 -0
- package/esm/context/database-data-source-context.d.mts +32 -0
- package/esm/context/database-data-source-context.d.mts.map +1 -0
- package/esm/context/database-data-source-context.mjs +35 -0
- package/esm/context/database-data-source-context.mjs.map +1 -0
- package/esm/context/database-transaction-context.d.mts +38 -0
- package/esm/context/database-transaction-context.d.mts.map +1 -0
- package/esm/context/database-transaction-context.mjs +47 -0
- package/esm/context/database-transaction-context.mjs.map +1 -0
- package/esm/contracts/database-driver.contract.d.mts +443 -0
- package/esm/contracts/database-driver.contract.d.mts.map +1 -0
- package/esm/contracts/database-id-generator.contract.d.mts +109 -0
- package/esm/contracts/database-id-generator.contract.d.mts.map +1 -0
- package/esm/contracts/database-remover.contract.d.mts +108 -0
- package/esm/contracts/database-remover.contract.d.mts.map +1 -0
- package/esm/contracts/database-restorer.contract.d.mts +145 -0
- package/esm/contracts/database-restorer.contract.d.mts.map +1 -0
- package/esm/contracts/database-writer.contract.d.mts +123 -0
- package/esm/contracts/database-writer.contract.d.mts.map +1 -0
- package/esm/contracts/driver-blueprint.contract.d.mts +52 -0
- package/esm/contracts/driver-blueprint.contract.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +9 -0
- package/esm/contracts/migration-driver.contract.d.mts +476 -0
- package/esm/contracts/migration-driver.contract.d.mts.map +1 -0
- package/esm/contracts/query-builder.contract.d.mts +1663 -0
- package/esm/contracts/query-builder.contract.d.mts.map +1 -0
- package/esm/contracts/sync-adapter.contract.d.mts +49 -0
- package/esm/contracts/sync-adapter.contract.d.mts.map +1 -0
- package/esm/data-source/data-source-registry.d.mts +111 -0
- package/esm/data-source/data-source-registry.d.mts.map +1 -0
- package/esm/data-source/data-source-registry.mjs +142 -0
- package/esm/data-source/data-source-registry.mjs.map +1 -0
- package/esm/data-source/data-source.d.mts +160 -0
- package/esm/data-source/data-source.d.mts.map +1 -0
- package/esm/data-source/data-source.mjs +87 -0
- package/esm/data-source/data-source.mjs.map +1 -0
- package/esm/database-dirty-tracker.d.mts +254 -0
- package/esm/database-dirty-tracker.d.mts.map +1 -0
- package/esm/database-dirty-tracker.mjs +356 -0
- package/esm/database-dirty-tracker.mjs.map +1 -0
- package/esm/drivers/mongodb/mongodb-blueprint.mjs +54 -0
- package/esm/drivers/mongodb/mongodb-blueprint.mjs.map +1 -0
- package/esm/drivers/mongodb/mongodb-driver.d.mts +334 -0
- package/esm/drivers/mongodb/mongodb-driver.d.mts.map +1 -0
- package/esm/drivers/mongodb/mongodb-driver.mjs +716 -0
- package/esm/drivers/mongodb/mongodb-driver.mjs.map +1 -0
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts +120 -0
- package/esm/drivers/mongodb/mongodb-id-generator.d.mts.map +1 -0
- package/esm/drivers/mongodb/mongodb-id-generator.mjs +141 -0
- package/esm/drivers/mongodb/mongodb-id-generator.mjs.map +1 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts +322 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.d.mts.map +1 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.mjs +531 -0
- package/esm/drivers/mongodb/mongodb-migration-driver.mjs.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts +1117 -0
- package/esm/drivers/mongodb/mongodb-query-builder.d.mts.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-builder.mjs +1828 -0
- package/esm/drivers/mongodb/mongodb-query-builder.mjs.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts +230 -0
- package/esm/drivers/mongodb/mongodb-query-operations.d.mts.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-operations.mjs +275 -0
- package/esm/drivers/mongodb/mongodb-query-operations.mjs.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts +263 -0
- package/esm/drivers/mongodb/mongodb-query-parser.d.mts.map +1 -0
- package/esm/drivers/mongodb/mongodb-query-parser.mjs +965 -0
- package/esm/drivers/mongodb/mongodb-query-parser.mjs.map +1 -0
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts +78 -0
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.mts.map +1 -0
- package/esm/drivers/mongodb/mongodb-sync-adapter.mjs +118 -0
- package/esm/drivers/mongodb/mongodb-sync-adapter.mjs.map +1 -0
- package/esm/drivers/mongodb/types.d.mts +43 -0
- package/esm/drivers/mongodb/types.d.mts.map +1 -0
- package/esm/drivers/postgres/index.d.mts +8 -0
- package/esm/drivers/postgres/index.mjs +9 -0
- package/esm/drivers/postgres/postgres-blueprint.d.mts +60 -0
- package/esm/drivers/postgres/postgres-blueprint.d.mts.map +1 -0
- package/esm/drivers/postgres/postgres-blueprint.mjs +105 -0
- package/esm/drivers/postgres/postgres-blueprint.mjs.map +1 -0
- package/esm/drivers/postgres/postgres-dialect.d.mts +144 -0
- package/esm/drivers/postgres/postgres-dialect.d.mts.map +1 -0
- package/esm/drivers/postgres/postgres-dialect.mjs +227 -0
- package/esm/drivers/postgres/postgres-dialect.mjs.map +1 -0
- package/esm/drivers/postgres/postgres-driver.d.mts +424 -0
- package/esm/drivers/postgres/postgres-driver.d.mts.map +1 -0
- package/esm/drivers/postgres/postgres-driver.mjs +845 -0
- package/esm/drivers/postgres/postgres-driver.mjs.map +1 -0
- package/esm/drivers/postgres/postgres-migration-driver.d.mts +393 -0
- package/esm/drivers/postgres/postgres-migration-driver.d.mts.map +1 -0
- package/esm/drivers/postgres/postgres-migration-driver.mjs +760 -0
- package/esm/drivers/postgres/postgres-migration-driver.mjs.map +1 -0
- package/esm/drivers/postgres/postgres-query-builder.d.mts +399 -0
- package/esm/drivers/postgres/postgres-query-builder.d.mts.map +1 -0
- package/esm/drivers/postgres/postgres-query-builder.mjs +1105 -0
- package/esm/drivers/postgres/postgres-query-builder.mjs.map +1 -0
- package/esm/drivers/postgres/postgres-query-parser.d.mts +351 -0
- package/esm/drivers/postgres/postgres-query-parser.d.mts.map +1 -0
- package/esm/drivers/postgres/postgres-query-parser.mjs +796 -0
- package/esm/drivers/postgres/postgres-query-parser.mjs.map +1 -0
- package/esm/drivers/postgres/postgres-sql-serializer.mjs +260 -0
- package/esm/drivers/postgres/postgres-sql-serializer.mjs.map +1 -0
- package/esm/drivers/postgres/postgres-sync-adapter.d.mts +79 -0
- package/esm/drivers/postgres/postgres-sync-adapter.d.mts.map +1 -0
- package/esm/drivers/postgres/postgres-sync-adapter.mjs +162 -0
- package/esm/drivers/postgres/postgres-sync-adapter.mjs.map +1 -0
- package/esm/drivers/postgres/types.d.mts +105 -0
- package/esm/drivers/postgres/types.d.mts.map +1 -0
- package/esm/drivers/sql/sql-dialect.contract.d.mts +221 -0
- package/esm/drivers/sql/sql-dialect.contract.d.mts.map +1 -0
- package/esm/drivers/sql/sql-types.d.mts +150 -0
- package/esm/drivers/sql/sql-types.d.mts.map +1 -0
- package/esm/errors/missing-data-source.error.d.mts +25 -0
- package/esm/errors/missing-data-source.error.d.mts.map +1 -0
- package/esm/errors/missing-data-source.error.mjs +31 -0
- package/esm/errors/missing-data-source.error.mjs.map +1 -0
- package/esm/errors/transaction-rollback.error.d.mts +23 -0
- package/esm/errors/transaction-rollback.error.d.mts.map +1 -0
- package/esm/errors/transaction-rollback.error.mjs +29 -0
- package/esm/errors/transaction-rollback.error.mjs.map +1 -0
- package/esm/events/model-events.d.mts +234 -0
- package/esm/events/model-events.d.mts.map +1 -0
- package/esm/events/model-events.mjs +254 -0
- package/esm/events/model-events.mjs.map +1 -0
- package/esm/expressions/aggregate-expressions.d.mts +224 -0
- package/esm/expressions/aggregate-expressions.d.mts.map +1 -0
- package/esm/expressions/aggregate-expressions.mjs +232 -0
- package/esm/expressions/aggregate-expressions.mjs.map +1 -0
- package/esm/index.d.mts +67 -0
- package/esm/index.mjs +53 -0
- package/esm/migration/column-builder.d.mts +420 -0
- package/esm/migration/column-builder.d.mts.map +1 -0
- package/esm/migration/column-builder.mjs +532 -0
- package/esm/migration/column-builder.mjs.map +1 -0
- package/esm/migration/column-helpers.d.mts +280 -0
- package/esm/migration/column-helpers.d.mts.map +1 -0
- package/esm/migration/column-helpers.mjs +376 -0
- package/esm/migration/column-helpers.mjs.map +1 -0
- package/esm/migration/foreign-key-builder.d.mts +106 -0
- package/esm/migration/foreign-key-builder.d.mts.map +1 -0
- package/esm/migration/foreign-key-builder.mjs +126 -0
- package/esm/migration/foreign-key-builder.mjs.map +1 -0
- package/esm/migration/index.d.mts +6 -0
- package/esm/migration/index.mjs +7 -0
- package/esm/migration/migration-runner.d.mts +279 -0
- package/esm/migration/migration-runner.d.mts.map +1 -0
- package/esm/migration/migration-runner.mjs +662 -0
- package/esm/migration/migration-runner.mjs.map +1 -0
- package/esm/migration/migration.d.mts +2035 -0
- package/esm/migration/migration.d.mts.map +1 -0
- package/esm/migration/migration.mjs +2083 -0
- package/esm/migration/migration.mjs.map +1 -0
- package/esm/migration/sql-grammar.mjs +115 -0
- package/esm/migration/sql-grammar.mjs.map +1 -0
- package/esm/migration/sql-serializer.d.mts +26 -0
- package/esm/migration/sql-serializer.d.mts.map +1 -0
- package/esm/migration/sql-serializer.mjs +26 -0
- package/esm/migration/sql-serializer.mjs.map +1 -0
- package/esm/migration/types.d.mts +136 -0
- package/esm/migration/types.d.mts.map +1 -0
- package/esm/model/methods/accessor-methods.mjs +54 -0
- package/esm/model/methods/accessor-methods.mjs.map +1 -0
- package/esm/model/methods/delete-methods.mjs +16 -0
- package/esm/model/methods/delete-methods.mjs.map +1 -0
- package/esm/model/methods/dirty-methods.mjs +20 -0
- package/esm/model/methods/dirty-methods.mjs.map +1 -0
- package/esm/model/methods/hydration-methods.mjs +51 -0
- package/esm/model/methods/hydration-methods.mjs.map +1 -0
- package/esm/model/methods/instance-event-methods.mjs +22 -0
- package/esm/model/methods/instance-event-methods.mjs.map +1 -0
- package/esm/model/methods/meta-methods.mjs +36 -0
- package/esm/model/methods/meta-methods.mjs.map +1 -0
- package/esm/model/methods/pivot-methods.mjs +48 -0
- package/esm/model/methods/pivot-methods.mjs.map +1 -0
- package/esm/model/methods/query-methods.mjs +121 -0
- package/esm/model/methods/query-methods.mjs.map +1 -0
- package/esm/model/methods/restore-methods.mjs +16 -0
- package/esm/model/methods/restore-methods.mjs.map +1 -0
- package/esm/model/methods/scope-methods.mjs +20 -0
- package/esm/model/methods/scope-methods.mjs.map +1 -0
- package/esm/model/methods/serialization-methods.mjs +20 -0
- package/esm/model/methods/serialization-methods.mjs.map +1 -0
- package/esm/model/methods/static-event-methods.mjs +37 -0
- package/esm/model/methods/static-event-methods.mjs.map +1 -0
- package/esm/model/methods/write-methods.mjs +69 -0
- package/esm/model/methods/write-methods.mjs.map +1 -0
- package/esm/model/model.d.mts +1778 -0
- package/esm/model/model.d.mts.map +1 -0
- package/esm/model/model.mjs +1762 -0
- package/esm/model/model.mjs.map +1 -0
- package/esm/model/model.types.d.mts +47 -0
- package/esm/model/model.types.d.mts.map +1 -0
- package/esm/model/register-model.d.mts +140 -0
- package/esm/model/register-model.d.mts.map +1 -0
- package/esm/model/register-model.mjs +175 -0
- package/esm/model/register-model.mjs.map +1 -0
- package/esm/model/relation-decorators.d.mts +88 -0
- package/esm/model/relation-decorators.d.mts.map +1 -0
- package/esm/model/relation-decorators.mjs +191 -0
- package/esm/model/relation-decorators.mjs.map +1 -0
- package/esm/operations/database.d.mts +46 -0
- package/esm/operations/database.d.mts.map +1 -0
- package/esm/operations/database.mjs +40 -0
- package/esm/operations/database.mjs.map +1 -0
- package/esm/operations/index.d.mts +2 -0
- package/esm/operations/index.mjs +4 -0
- package/esm/operations/migrations.d.mts +71 -0
- package/esm/operations/migrations.d.mts.map +1 -0
- package/esm/operations/migrations.mjs +70 -0
- package/esm/operations/migrations.mjs.map +1 -0
- package/esm/query-builder/query-builder.d.mts +564 -0
- package/esm/query-builder/query-builder.d.mts.map +1 -0
- package/esm/query-builder/query-builder.mjs +1097 -0
- package/esm/query-builder/query-builder.mjs.map +1 -0
- package/esm/relations/index.d.mts +4 -0
- package/esm/relations/index.mjs +5 -0
- package/esm/relations/key-conventions.mjs +119 -0
- package/esm/relations/key-conventions.mjs.map +1 -0
- package/esm/relations/pivot-operations.d.mts +155 -0
- package/esm/relations/pivot-operations.d.mts.map +1 -0
- package/esm/relations/pivot-operations.mjs +232 -0
- package/esm/relations/pivot-operations.mjs.map +1 -0
- package/esm/relations/relation-hydrator.d.mts +55 -0
- package/esm/relations/relation-hydrator.d.mts.map +1 -0
- package/esm/relations/relation-hydrator.mjs +52 -0
- package/esm/relations/relation-hydrator.mjs.map +1 -0
- package/esm/relations/relation-loader.d.mts +190 -0
- package/esm/relations/relation-loader.d.mts.map +1 -0
- package/esm/relations/relation-loader.mjs +416 -0
- package/esm/relations/relation-loader.mjs.map +1 -0
- package/esm/relations/types.d.mts +317 -0
- package/esm/relations/types.d.mts.map +1 -0
- package/esm/remover/database-remover.d.mts +104 -0
- package/esm/remover/database-remover.d.mts.map +1 -0
- package/esm/remover/database-remover.mjs +174 -0
- package/esm/remover/database-remover.mjs.map +1 -0
- package/esm/restorer/database-restorer.d.mts +135 -0
- package/esm/restorer/database-restorer.d.mts.map +1 -0
- package/esm/restorer/database-restorer.mjs +316 -0
- package/esm/restorer/database-restorer.mjs.map +1 -0
- package/esm/sql-database-dirty-tracker.d.mts +17 -0
- package/esm/sql-database-dirty-tracker.d.mts.map +1 -0
- package/esm/sql-database-dirty-tracker.mjs +20 -0
- package/esm/sql-database-dirty-tracker.mjs.map +1 -0
- package/esm/sync/model-events.mjs +46 -0
- package/esm/sync/model-events.mjs.map +1 -0
- package/esm/sync/model-sync-operation.d.mts +159 -0
- package/esm/sync/model-sync-operation.d.mts.map +1 -0
- package/esm/sync/model-sync-operation.mjs +257 -0
- package/esm/sync/model-sync-operation.mjs.map +1 -0
- package/esm/sync/model-sync.d.mts +126 -0
- package/esm/sync/model-sync.d.mts.map +1 -0
- package/esm/sync/model-sync.mjs +157 -0
- package/esm/sync/model-sync.mjs.map +1 -0
- package/esm/sync/sync-context.d.mts +69 -0
- package/esm/sync/sync-context.d.mts.map +1 -0
- package/esm/sync/sync-context.mjs +95 -0
- package/esm/sync/sync-context.mjs.map +1 -0
- package/esm/sync/sync-manager.d.mts +213 -0
- package/esm/sync/sync-manager.d.mts.map +1 -0
- package/esm/sync/sync-manager.mjs +597 -0
- package/esm/sync/sync-manager.mjs.map +1 -0
- package/esm/sync/types.d.mts +215 -0
- package/esm/sync/types.d.mts.map +1 -0
- package/esm/types.d.mts +423 -0
- package/esm/types.d.mts.map +1 -0
- package/esm/utils/connect-to-database.d.mts +328 -0
- package/esm/utils/connect-to-database.d.mts.map +1 -0
- package/esm/utils/connect-to-database.mjs +130 -0
- package/esm/utils/connect-to-database.mjs.map +1 -0
- package/esm/utils/database-writer.utils.d.mts +18 -0
- package/esm/utils/database-writer.utils.d.mts.map +1 -0
- package/esm/utils/database-writer.utils.mjs +25 -0
- package/esm/utils/database-writer.utils.mjs.map +1 -0
- package/esm/utils/define-model.d.mts +185 -0
- package/esm/utils/define-model.d.mts.map +1 -0
- package/esm/utils/define-model.mjs +105 -0
- package/esm/utils/define-model.mjs.map +1 -0
- package/esm/utils/is-valid-date-value.mjs +22 -0
- package/esm/utils/is-valid-date-value.mjs.map +1 -0
- package/esm/utils/once-connected.d.mts +150 -0
- package/esm/utils/once-connected.d.mts.map +1 -0
- package/esm/utils/once-connected.mjs +203 -0
- package/esm/utils/once-connected.mjs.map +1 -0
- package/esm/validation/database-seal-plugins.d.mts +1 -0
- package/esm/validation/database-seal-plugins.mjs +11 -0
- package/esm/validation/database-seal-plugins.mjs.map +1 -0
- package/esm/validation/database-writer-validation-error.d.mts +101 -0
- package/esm/validation/database-writer-validation-error.d.mts.map +1 -0
- package/esm/validation/database-writer-validation-error.mjs +153 -0
- package/esm/validation/database-writer-validation-error.mjs.map +1 -0
- package/esm/validation/index.d.mts +2 -0
- package/esm/validation/index.mjs +4 -0
- package/esm/validation/mutators/embed-mutator.mjs +26 -0
- package/esm/validation/mutators/embed-mutator.mjs.map +1 -0
- package/esm/validation/plugins/database-rules-plugin.d.mts +28 -0
- package/esm/validation/plugins/database-rules-plugin.d.mts.map +1 -0
- package/esm/validation/plugins/database-rules-plugin.mjs +43 -0
- package/esm/validation/plugins/database-rules-plugin.mjs.map +1 -0
- package/esm/validation/plugins/embed-validator-plugin.d.mts +17 -0
- package/esm/validation/plugins/embed-validator-plugin.d.mts.map +1 -0
- package/esm/validation/plugins/embed-validator-plugin.mjs +20 -0
- package/esm/validation/plugins/embed-validator-plugin.mjs.map +1 -0
- package/esm/validation/rules/database-model-rule.mjs +32 -0
- package/esm/validation/rules/database-model-rule.mjs.map +1 -0
- package/esm/validation/rules/exists-rule.mjs +29 -0
- package/esm/validation/rules/exists-rule.mjs.map +1 -0
- package/esm/validation/rules/unique-rule.mjs +43 -0
- package/esm/validation/rules/unique-rule.mjs.map +1 -0
- package/esm/validation/transformers/embed-model-transformer.mjs +17 -0
- package/esm/validation/transformers/embed-model-transformer.mjs.map +1 -0
- package/esm/validation/types.d.mts +43 -0
- package/esm/validation/types.d.mts.map +1 -0
- package/esm/validation/validators/embed-validator.d.mts +25 -0
- package/esm/validation/validators/embed-validator.d.mts.map +1 -0
- package/esm/validation/validators/embed-validator.mjs +42 -0
- package/esm/validation/validators/embed-validator.mjs.map +1 -0
- package/esm/writer/database-writer.d.mts +178 -0
- package/esm/writer/database-writer.d.mts.map +1 -0
- package/esm/writer/database-writer.mjs +317 -0
- package/esm/writer/database-writer.mjs.map +1 -0
- package/llms-full.txt +2027 -0
- package/llms.txt +23 -0
- package/package.json +60 -51
- package/skills/README.md +65 -0
- package/skills/aggregate-data/SKILL.md +102 -0
- package/skills/cascade-basics/SKILL.md +93 -0
- package/skills/configure-delete-strategy/SKILL.md +126 -0
- package/skills/define-model/SKILL.md +170 -0
- package/skills/define-relations/SKILL.md +171 -0
- package/skills/manage-data-sources/SKILL.md +140 -0
- package/skills/manage-transactions/SKILL.md +118 -0
- package/skills/paginate-results/SKILL.md +122 -0
- package/skills/perform-atomic-ops/SKILL.md +98 -0
- package/skills/query-data/SKILL.md +168 -0
- package/skills/run-cascade-cli/SKILL.md +125 -0
- package/skills/search-by-vector/SKILL.md +127 -0
- package/skills/subscribe-to-model-events/SKILL.md +148 -0
- package/skills/track-changes/SKILL.md +109 -0
- package/skills/write-migration/SKILL.md +144 -0
- package/cjs/context/database-data-source-context.d.ts +0 -29
- package/cjs/context/database-data-source-context.d.ts.map +0 -1
- package/cjs/context/database-data-source-context.js +0 -28
- package/cjs/context/database-data-source-context.js.map +0 -1
- package/cjs/context/database-transaction-context.d.ts +0 -35
- package/cjs/context/database-transaction-context.d.ts.map +0 -1
- package/cjs/context/database-transaction-context.js +0 -40
- package/cjs/context/database-transaction-context.js.map +0 -1
- package/cjs/contracts/database-driver.contract.d.ts +0 -450
- package/cjs/contracts/database-driver.contract.d.ts.map +0 -1
- package/cjs/contracts/database-id-generator.contract.d.ts +0 -109
- package/cjs/contracts/database-id-generator.contract.d.ts.map +0 -1
- package/cjs/contracts/database-remover.contract.d.ts +0 -104
- package/cjs/contracts/database-remover.contract.d.ts.map +0 -1
- package/cjs/contracts/database-restorer.contract.d.ts +0 -143
- package/cjs/contracts/database-restorer.contract.d.ts.map +0 -1
- package/cjs/contracts/database-writer.contract.d.ts +0 -119
- package/cjs/contracts/database-writer.contract.d.ts.map +0 -1
- package/cjs/contracts/driver-blueprint.contract.d.ts +0 -49
- package/cjs/contracts/driver-blueprint.contract.d.ts.map +0 -1
- package/cjs/contracts/index.d.ts +0 -10
- package/cjs/contracts/index.d.ts.map +0 -1
- package/cjs/contracts/migration-driver.contract.d.ts +0 -522
- package/cjs/contracts/migration-driver.contract.d.ts.map +0 -1
- package/cjs/contracts/query-builder.contract.d.ts +0 -1609
- package/cjs/contracts/query-builder.contract.d.ts.map +0 -1
- package/cjs/contracts/sync-adapter.contract.d.ts +0 -58
- package/cjs/contracts/sync-adapter.contract.d.ts.map +0 -1
- package/cjs/data-source/data-source-registry.d.ts +0 -108
- package/cjs/data-source/data-source-registry.d.ts.map +0 -1
- package/cjs/data-source/data-source-registry.js +0 -145
- package/cjs/data-source/data-source-registry.js.map +0 -1
- package/cjs/data-source/data-source.d.ts +0 -147
- package/cjs/data-source/data-source.d.ts.map +0 -1
- package/cjs/data-source/data-source.js +0 -83
- package/cjs/data-source/data-source.js.map +0 -1
- package/cjs/database-dirty-tracker.d.ts +0 -252
- package/cjs/database-dirty-tracker.d.ts.map +0 -1
- package/cjs/database-dirty-tracker.js +0 -386
- package/cjs/database-dirty-tracker.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-blueprint.d.ts +0 -30
- package/cjs/drivers/mongodb/mongodb-blueprint.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-blueprint.js +0 -51
- package/cjs/drivers/mongodb/mongodb-blueprint.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-driver.d.ts +0 -325
- package/cjs/drivers/mongodb/mongodb-driver.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-driver.js +0 -845
- package/cjs/drivers/mongodb/mongodb-driver.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-id-generator.d.ts +0 -116
- package/cjs/drivers/mongodb/mongodb-id-generator.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-id-generator.js +0 -149
- package/cjs/drivers/mongodb/mongodb-id-generator.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts +0 -317
- package/cjs/drivers/mongodb/mongodb-migration-driver.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-migration-driver.js +0 -666
- package/cjs/drivers/mongodb/mongodb-migration-driver.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-builder.d.ts +0 -1122
- package/cjs/drivers/mongodb/mongodb-query-builder.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-builder.js +0 -1988
- package/cjs/drivers/mongodb/mongodb-query-builder.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-operations.d.ts +0 -226
- package/cjs/drivers/mongodb/mongodb-query-operations.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-operations.js +0 -270
- package/cjs/drivers/mongodb/mongodb-query-operations.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-parser.d.ts +0 -262
- package/cjs/drivers/mongodb/mongodb-query-parser.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-query-parser.js +0 -1351
- package/cjs/drivers/mongodb/mongodb-query-parser.js.map +0 -1
- package/cjs/drivers/mongodb/mongodb-sync-adapter.d.ts +0 -79
- package/cjs/drivers/mongodb/mongodb-sync-adapter.d.ts.map +0 -1
- package/cjs/drivers/mongodb/mongodb-sync-adapter.js +0 -146
- package/cjs/drivers/mongodb/mongodb-sync-adapter.js.map +0 -1
- package/cjs/drivers/mongodb/types.d.ts +0 -43
- package/cjs/drivers/mongodb/types.d.ts.map +0 -1
- package/cjs/drivers/postgres/index.d.ts +0 -16
- package/cjs/drivers/postgres/index.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-blueprint.d.ts +0 -64
- package/cjs/drivers/postgres/postgres-blueprint.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-blueprint.js +0 -121
- package/cjs/drivers/postgres/postgres-blueprint.js.map +0 -1
- package/cjs/drivers/postgres/postgres-dialect.d.ts +0 -136
- package/cjs/drivers/postgres/postgres-dialect.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-dialect.js +0 -268
- package/cjs/drivers/postgres/postgres-dialect.js.map +0 -1
- package/cjs/drivers/postgres/postgres-driver.d.ts +0 -432
- package/cjs/drivers/postgres/postgres-driver.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-driver.js +0 -1008
- package/cjs/drivers/postgres/postgres-driver.js.map +0 -1
- package/cjs/drivers/postgres/postgres-migration-driver.d.ts +0 -397
- package/cjs/drivers/postgres/postgres-migration-driver.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-migration-driver.js +0 -900
- package/cjs/drivers/postgres/postgres-migration-driver.js.map +0 -1
- package/cjs/drivers/postgres/postgres-query-builder.d.ts +0 -254
- package/cjs/drivers/postgres/postgres-query-builder.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-query-builder.js +0 -933
- package/cjs/drivers/postgres/postgres-query-builder.js.map +0 -1
- package/cjs/drivers/postgres/postgres-query-parser.d.ts +0 -328
- package/cjs/drivers/postgres/postgres-query-parser.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-query-parser.js +0 -868
- package/cjs/drivers/postgres/postgres-query-parser.js.map +0 -1
- package/cjs/drivers/postgres/postgres-sql-serializer.d.ts +0 -37
- package/cjs/drivers/postgres/postgres-sql-serializer.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-sql-serializer.js +0 -400
- package/cjs/drivers/postgres/postgres-sql-serializer.js.map +0 -1
- package/cjs/drivers/postgres/postgres-sync-adapter.d.ts +0 -83
- package/cjs/drivers/postgres/postgres-sync-adapter.d.ts.map +0 -1
- package/cjs/drivers/postgres/postgres-sync-adapter.js +0 -204
- package/cjs/drivers/postgres/postgres-sync-adapter.js.map +0 -1
- package/cjs/drivers/postgres/types.d.ts +0 -144
- package/cjs/drivers/postgres/types.d.ts.map +0 -1
- package/cjs/drivers/sql/index.d.ts +0 -10
- package/cjs/drivers/sql/index.d.ts.map +0 -1
- package/cjs/drivers/sql/sql-dialect.contract.d.ts +0 -204
- package/cjs/drivers/sql/sql-dialect.contract.d.ts.map +0 -1
- package/cjs/drivers/sql/sql-types.d.ts +0 -202
- package/cjs/drivers/sql/sql-types.d.ts.map +0 -1
- package/cjs/errors/missing-data-source.error.d.ts +0 -22
- package/cjs/errors/missing-data-source.error.d.ts.map +0 -1
- package/cjs/errors/missing-data-source.error.js +0 -29
- package/cjs/errors/missing-data-source.error.js.map +0 -1
- package/cjs/errors/transaction-rollback.error.d.ts +0 -20
- package/cjs/errors/transaction-rollback.error.d.ts.map +0 -1
- package/cjs/errors/transaction-rollback.error.js +0 -27
- package/cjs/errors/transaction-rollback.error.js.map +0 -1
- package/cjs/events/model-events.d.ts +0 -231
- package/cjs/events/model-events.d.ts.map +0 -1
- package/cjs/events/model-events.js +0 -259
- package/cjs/events/model-events.js.map +0 -1
- package/cjs/expressions/aggregate-expressions.d.ts +0 -215
- package/cjs/expressions/aggregate-expressions.d.ts.map +0 -1
- package/cjs/expressions/aggregate-expressions.js +0 -221
- package/cjs/expressions/aggregate-expressions.js.map +0 -1
- package/cjs/expressions/index.d.ts +0 -2
- package/cjs/expressions/index.d.ts.map +0 -1
- package/cjs/index.d.ts +0 -45
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/migration/column-builder.d.ts +0 -417
- package/cjs/migration/column-builder.d.ts.map +0 -1
- package/cjs/migration/column-builder.js +0 -586
- package/cjs/migration/column-builder.js.map +0 -1
- package/cjs/migration/column-helpers.d.ts +0 -275
- package/cjs/migration/column-helpers.d.ts.map +0 -1
- package/cjs/migration/column-helpers.js +0 -389
- package/cjs/migration/column-helpers.js.map +0 -1
- package/cjs/migration/foreign-key-builder.d.ts +0 -103
- package/cjs/migration/foreign-key-builder.d.ts.map +0 -1
- package/cjs/migration/foreign-key-builder.js +0 -121
- package/cjs/migration/foreign-key-builder.js.map +0 -1
- package/cjs/migration/index.d.ts +0 -7
- package/cjs/migration/index.d.ts.map +0 -1
- package/cjs/migration/migration-runner.d.ts +0 -278
- package/cjs/migration/migration-runner.d.ts.map +0 -1
- package/cjs/migration/migration-runner.js +0 -815
- package/cjs/migration/migration-runner.js.map +0 -1
- package/cjs/migration/migration.d.ts +0 -1988
- package/cjs/migration/migration.d.ts.map +0 -1
- package/cjs/migration/migration.js +0 -2162
- package/cjs/migration/migration.js.map +0 -1
- package/cjs/migration/sql-grammar.d.ts +0 -61
- package/cjs/migration/sql-grammar.d.ts.map +0 -1
- package/cjs/migration/sql-grammar.js +0 -164
- package/cjs/migration/sql-grammar.js.map +0 -1
- package/cjs/migration/sql-serializer.d.ts +0 -22
- package/cjs/migration/sql-serializer.d.ts.map +0 -1
- package/cjs/migration/sql-serializer.js +0 -26
- package/cjs/migration/sql-serializer.js.map +0 -1
- package/cjs/migration/types.d.ts +0 -155
- package/cjs/migration/types.d.ts.map +0 -1
- package/cjs/model/methods/accessor-methods.d.ts +0 -13
- package/cjs/model/methods/accessor-methods.d.ts.map +0 -1
- package/cjs/model/methods/accessor-methods.js +0 -51
- package/cjs/model/methods/accessor-methods.js.map +0 -1
- package/cjs/model/methods/delete-methods.d.ts +0 -10
- package/cjs/model/methods/delete-methods.d.ts.map +0 -1
- package/cjs/model/methods/delete-methods.js +0 -10
- package/cjs/model/methods/delete-methods.js.map +0 -1
- package/cjs/model/methods/dirty-methods.d.ts +0 -10
- package/cjs/model/methods/dirty-methods.d.ts.map +0 -1
- package/cjs/model/methods/dirty-methods.js +0 -15
- package/cjs/model/methods/dirty-methods.js.map +0 -1
- package/cjs/model/methods/hydration-methods.d.ts +0 -10
- package/cjs/model/methods/hydration-methods.d.ts.map +0 -1
- package/cjs/model/methods/hydration-methods.js +0 -57
- package/cjs/model/methods/hydration-methods.js.map +0 -1
- package/cjs/model/methods/instance-event-methods.d.ts +0 -7
- package/cjs/model/methods/instance-event-methods.d.ts.map +0 -1
- package/cjs/model/methods/instance-event-methods.js +0 -15
- package/cjs/model/methods/instance-event-methods.js.map +0 -1
- package/cjs/model/methods/meta-methods.d.ts +0 -7
- package/cjs/model/methods/meta-methods.d.ts.map +0 -1
- package/cjs/model/methods/meta-methods.js +0 -78
- package/cjs/model/methods/meta-methods.js.map +0 -1
- package/cjs/model/methods/query-methods.d.ts +0 -24
- package/cjs/model/methods/query-methods.d.ts.map +0 -1
- package/cjs/model/methods/query-methods.js +0 -164
- package/cjs/model/methods/query-methods.js.map +0 -1
- package/cjs/model/methods/restore-methods.d.ts +0 -10
- package/cjs/model/methods/restore-methods.d.ts.map +0 -1
- package/cjs/model/methods/restore-methods.js +0 -13
- package/cjs/model/methods/restore-methods.js.map +0 -1
- package/cjs/model/methods/scope-methods.d.ts +0 -7
- package/cjs/model/methods/scope-methods.d.ts.map +0 -1
- package/cjs/model/methods/scope-methods.js +0 -15
- package/cjs/model/methods/scope-methods.js.map +0 -1
- package/cjs/model/methods/serialization-methods.d.ts +0 -3
- package/cjs/model/methods/serialization-methods.d.ts.map +0 -1
- package/cjs/model/methods/serialization-methods.js +0 -27
- package/cjs/model/methods/serialization-methods.js.map +0 -1
- package/cjs/model/methods/static-event-methods.d.ts +0 -9
- package/cjs/model/methods/static-event-methods.d.ts.map +0 -1
- package/cjs/model/methods/static-event-methods.js +0 -29
- package/cjs/model/methods/static-event-methods.js.map +0 -1
- package/cjs/model/methods/write-methods.d.ts +0 -10
- package/cjs/model/methods/write-methods.d.ts.map +0 -1
- package/cjs/model/methods/write-methods.js +0 -52
- package/cjs/model/methods/write-methods.js.map +0 -1
- package/cjs/model/model.d.ts +0 -1647
- package/cjs/model/model.d.ts.map +0 -1
- package/cjs/model/model.js +0 -1657
- package/cjs/model/model.js.map +0 -1
- package/cjs/model/model.types.d.ts +0 -44
- package/cjs/model/model.types.d.ts.map +0 -1
- package/cjs/model/register-model.d.ts +0 -81
- package/cjs/model/register-model.d.ts.map +0 -1
- package/cjs/model/register-model.js +0 -94
- package/cjs/model/register-model.js.map +0 -1
- package/cjs/query-builder/query-builder.d.ts +0 -556
- package/cjs/query-builder/query-builder.d.ts.map +0 -1
- package/cjs/query-builder/query-builder.js +0 -1070
- package/cjs/query-builder/query-builder.js.map +0 -1
- package/cjs/relations/helpers.d.ts +0 -156
- package/cjs/relations/helpers.d.ts.map +0 -1
- package/cjs/relations/helpers.js +0 -202
- package/cjs/relations/helpers.js.map +0 -1
- package/cjs/relations/index.d.ts +0 -35
- package/cjs/relations/index.d.ts.map +0 -1
- package/cjs/relations/pivot-operations.d.ts +0 -160
- package/cjs/relations/pivot-operations.d.ts.map +0 -1
- package/cjs/relations/pivot-operations.js +0 -293
- package/cjs/relations/pivot-operations.js.map +0 -1
- package/cjs/relations/relation-hydrator.d.ts +0 -68
- package/cjs/relations/relation-hydrator.d.ts.map +0 -1
- package/cjs/relations/relation-hydrator.js +0 -81
- package/cjs/relations/relation-hydrator.js.map +0 -1
- package/cjs/relations/relation-loader.d.ts +0 -194
- package/cjs/relations/relation-loader.d.ts.map +0 -1
- package/cjs/relations/relation-loader.js +0 -466
- package/cjs/relations/relation-loader.js.map +0 -1
- package/cjs/relations/types.d.ts +0 -306
- package/cjs/relations/types.d.ts.map +0 -1
- package/cjs/remover/database-remover.d.ts +0 -100
- package/cjs/remover/database-remover.d.ts.map +0 -1
- package/cjs/remover/database-remover.js +0 -214
- package/cjs/remover/database-remover.js.map +0 -1
- package/cjs/restorer/database-restorer.d.ts +0 -131
- package/cjs/restorer/database-restorer.d.ts.map +0 -1
- package/cjs/restorer/database-restorer.js +0 -434
- package/cjs/restorer/database-restorer.js.map +0 -1
- package/cjs/sql-database-dirty-tracker.d.ts +0 -13
- package/cjs/sql-database-dirty-tracker.d.ts.map +0 -1
- package/cjs/sql-database-dirty-tracker.js +0 -14
- package/cjs/sql-database-dirty-tracker.js.map +0 -1
- package/cjs/sync/index.d.ts +0 -12
- package/cjs/sync/index.d.ts.map +0 -1
- package/cjs/sync/model-events.d.ts +0 -62
- package/cjs/sync/model-events.d.ts.map +0 -1
- package/cjs/sync/model-events.js +0 -49
- package/cjs/sync/model-events.js.map +0 -1
- package/cjs/sync/model-sync-operation.d.ts +0 -163
- package/cjs/sync/model-sync-operation.d.ts.map +0 -1
- package/cjs/sync/model-sync-operation.js +0 -292
- package/cjs/sync/model-sync-operation.js.map +0 -1
- package/cjs/sync/model-sync.d.ts +0 -130
- package/cjs/sync/model-sync.d.ts.map +0 -1
- package/cjs/sync/model-sync.js +0 -178
- package/cjs/sync/model-sync.js.map +0 -1
- package/cjs/sync/sync-context.d.ts +0 -70
- package/cjs/sync/sync-context.d.ts.map +0 -1
- package/cjs/sync/sync-context.js +0 -101
- package/cjs/sync/sync-context.js.map +0 -1
- package/cjs/sync/sync-manager.d.ts +0 -213
- package/cjs/sync/sync-manager.d.ts.map +0 -1
- package/cjs/sync/sync-manager.js +0 -689
- package/cjs/sync/sync-manager.js.map +0 -1
- package/cjs/sync/types.d.ts +0 -289
- package/cjs/sync/types.d.ts.map +0 -1
- package/cjs/test-migrations/test-enhanced-features.migration.d.ts +0 -15
- package/cjs/test-migrations/test-enhanced-features.migration.d.ts.map +0 -1
- package/cjs/types.d.ts +0 -371
- package/cjs/types.d.ts.map +0 -1
- package/cjs/utils/connect-to-database.d.ts +0 -307
- package/cjs/utils/connect-to-database.d.ts.map +0 -1
- package/cjs/utils/connect-to-database.js +0 -130
- package/cjs/utils/connect-to-database.js.map +0 -1
- package/cjs/utils/database-writer.utils.d.ts +0 -15
- package/cjs/utils/database-writer.utils.d.ts.map +0 -1
- package/cjs/utils/database-writer.utils.js +0 -14
- package/cjs/utils/database-writer.utils.js.map +0 -1
- package/cjs/utils/define-model.js +0 -100
- package/cjs/utils/define-model.js.map +0 -1
- package/cjs/utils/is-valid-date-value.d.ts +0 -5
- package/cjs/utils/is-valid-date-value.d.ts.map +0 -1
- package/cjs/utils/is-valid-date-value.js +0 -25
- package/cjs/utils/is-valid-date-value.js.map +0 -1
- package/cjs/utils/once-connected.d.ts +0 -146
- package/cjs/utils/once-connected.d.ts.map +0 -1
- package/cjs/utils/once-connected.js +0 -251
- package/cjs/utils/once-connected.js.map +0 -1
- package/cjs/validation/database-seal-plugins.d.ts +0 -12
- package/cjs/validation/database-seal-plugins.d.ts.map +0 -1
- package/cjs/validation/database-seal-plugins.js +0 -1
- package/cjs/validation/database-seal-plugins.js.map +0 -1
- package/cjs/validation/database-writer-validation-error.d.ts +0 -97
- package/cjs/validation/database-writer-validation-error.d.ts.map +0 -1
- package/cjs/validation/database-writer-validation-error.js +0 -160
- package/cjs/validation/database-writer-validation-error.js.map +0 -1
- package/cjs/validation/index.d.ts +0 -3
- package/cjs/validation/index.d.ts.map +0 -1
- package/cjs/validation/mutators/embed-mutator.d.ts +0 -9
- package/cjs/validation/mutators/embed-mutator.d.ts.map +0 -1
- package/cjs/validation/mutators/embed-mutator.js +0 -33
- package/cjs/validation/mutators/embed-mutator.js.map +0 -1
- package/cjs/validation/plugins/embed-validator-plugin.d.ts +0 -24
- package/cjs/validation/plugins/embed-validator-plugin.d.ts.map +0 -1
- package/cjs/validation/plugins/embed-validator-plugin.js +0 -18
- package/cjs/validation/plugins/embed-validator-plugin.js.map +0 -1
- package/cjs/validation/rules/database-model-rule.d.ts +0 -7
- package/cjs/validation/rules/database-model-rule.d.ts.map +0 -1
- package/cjs/validation/rules/database-model-rule.js +0 -27
- package/cjs/validation/rules/database-model-rule.js.map +0 -1
- package/cjs/validation/transformers/embed-model-transformer.d.ts +0 -3
- package/cjs/validation/transformers/embed-model-transformer.d.ts.map +0 -1
- package/cjs/validation/transformers/embed-model-transformer.js +0 -18
- package/cjs/validation/transformers/embed-model-transformer.js.map +0 -1
- package/cjs/validation/validators/embed-validator.d.ts +0 -21
- package/cjs/validation/validators/embed-validator.d.ts.map +0 -1
- package/cjs/validation/validators/embed-validator.js +0 -43
- package/cjs/validation/validators/embed-validator.js.map +0 -1
- package/cjs/writer/database-writer.d.ts +0 -174
- package/cjs/writer/database-writer.d.ts.map +0 -1
- package/cjs/writer/database-writer.js +0 -400
- package/cjs/writer/database-writer.js.map +0 -1
- package/esm/context/database-data-source-context.d.ts +0 -29
- package/esm/context/database-data-source-context.d.ts.map +0 -1
- package/esm/context/database-data-source-context.js +0 -28
- package/esm/context/database-data-source-context.js.map +0 -1
- package/esm/context/database-transaction-context.d.ts +0 -35
- package/esm/context/database-transaction-context.d.ts.map +0 -1
- package/esm/context/database-transaction-context.js +0 -40
- package/esm/context/database-transaction-context.js.map +0 -1
- package/esm/contracts/database-driver.contract.d.ts +0 -450
- package/esm/contracts/database-driver.contract.d.ts.map +0 -1
- package/esm/contracts/database-id-generator.contract.d.ts +0 -109
- package/esm/contracts/database-id-generator.contract.d.ts.map +0 -1
- package/esm/contracts/database-remover.contract.d.ts +0 -104
- package/esm/contracts/database-remover.contract.d.ts.map +0 -1
- package/esm/contracts/database-restorer.contract.d.ts +0 -143
- package/esm/contracts/database-restorer.contract.d.ts.map +0 -1
- package/esm/contracts/database-writer.contract.d.ts +0 -119
- package/esm/contracts/database-writer.contract.d.ts.map +0 -1
- package/esm/contracts/driver-blueprint.contract.d.ts +0 -49
- package/esm/contracts/driver-blueprint.contract.d.ts.map +0 -1
- package/esm/contracts/index.d.ts +0 -10
- package/esm/contracts/index.d.ts.map +0 -1
- package/esm/contracts/migration-driver.contract.d.ts +0 -522
- package/esm/contracts/migration-driver.contract.d.ts.map +0 -1
- package/esm/contracts/query-builder.contract.d.ts +0 -1609
- package/esm/contracts/query-builder.contract.d.ts.map +0 -1
- package/esm/contracts/sync-adapter.contract.d.ts +0 -58
- package/esm/contracts/sync-adapter.contract.d.ts.map +0 -1
- package/esm/data-source/data-source-registry.d.ts +0 -108
- package/esm/data-source/data-source-registry.d.ts.map +0 -1
- package/esm/data-source/data-source-registry.js +0 -145
- package/esm/data-source/data-source-registry.js.map +0 -1
- package/esm/data-source/data-source.d.ts +0 -147
- package/esm/data-source/data-source.d.ts.map +0 -1
- package/esm/data-source/data-source.js +0 -83
- package/esm/data-source/data-source.js.map +0 -1
- package/esm/database-dirty-tracker.d.ts +0 -252
- package/esm/database-dirty-tracker.d.ts.map +0 -1
- package/esm/database-dirty-tracker.js +0 -386
- package/esm/database-dirty-tracker.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-blueprint.d.ts +0 -30
- package/esm/drivers/mongodb/mongodb-blueprint.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-blueprint.js +0 -51
- package/esm/drivers/mongodb/mongodb-blueprint.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-driver.d.ts +0 -325
- package/esm/drivers/mongodb/mongodb-driver.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-driver.js +0 -845
- package/esm/drivers/mongodb/mongodb-driver.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-id-generator.d.ts +0 -116
- package/esm/drivers/mongodb/mongodb-id-generator.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-id-generator.js +0 -149
- package/esm/drivers/mongodb/mongodb-id-generator.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.d.ts +0 -317
- package/esm/drivers/mongodb/mongodb-migration-driver.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-migration-driver.js +0 -666
- package/esm/drivers/mongodb/mongodb-migration-driver.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-builder.d.ts +0 -1122
- package/esm/drivers/mongodb/mongodb-query-builder.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-builder.js +0 -1988
- package/esm/drivers/mongodb/mongodb-query-builder.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-operations.d.ts +0 -226
- package/esm/drivers/mongodb/mongodb-query-operations.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-operations.js +0 -270
- package/esm/drivers/mongodb/mongodb-query-operations.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-parser.d.ts +0 -262
- package/esm/drivers/mongodb/mongodb-query-parser.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-query-parser.js +0 -1351
- package/esm/drivers/mongodb/mongodb-query-parser.js.map +0 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.ts +0 -79
- package/esm/drivers/mongodb/mongodb-sync-adapter.d.ts.map +0 -1
- package/esm/drivers/mongodb/mongodb-sync-adapter.js +0 -146
- package/esm/drivers/mongodb/mongodb-sync-adapter.js.map +0 -1
- package/esm/drivers/mongodb/types.d.ts +0 -43
- package/esm/drivers/mongodb/types.d.ts.map +0 -1
- package/esm/drivers/postgres/index.d.ts +0 -16
- package/esm/drivers/postgres/index.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-blueprint.d.ts +0 -64
- package/esm/drivers/postgres/postgres-blueprint.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-blueprint.js +0 -121
- package/esm/drivers/postgres/postgres-blueprint.js.map +0 -1
- package/esm/drivers/postgres/postgres-dialect.d.ts +0 -136
- package/esm/drivers/postgres/postgres-dialect.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-dialect.js +0 -268
- package/esm/drivers/postgres/postgres-dialect.js.map +0 -1
- package/esm/drivers/postgres/postgres-driver.d.ts +0 -432
- package/esm/drivers/postgres/postgres-driver.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-driver.js +0 -1008
- package/esm/drivers/postgres/postgres-driver.js.map +0 -1
- package/esm/drivers/postgres/postgres-migration-driver.d.ts +0 -397
- package/esm/drivers/postgres/postgres-migration-driver.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-migration-driver.js +0 -900
- package/esm/drivers/postgres/postgres-migration-driver.js.map +0 -1
- package/esm/drivers/postgres/postgres-query-builder.d.ts +0 -254
- package/esm/drivers/postgres/postgres-query-builder.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-query-builder.js +0 -933
- package/esm/drivers/postgres/postgres-query-builder.js.map +0 -1
- package/esm/drivers/postgres/postgres-query-parser.d.ts +0 -328
- package/esm/drivers/postgres/postgres-query-parser.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-query-parser.js +0 -868
- package/esm/drivers/postgres/postgres-query-parser.js.map +0 -1
- package/esm/drivers/postgres/postgres-sql-serializer.d.ts +0 -37
- package/esm/drivers/postgres/postgres-sql-serializer.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-sql-serializer.js +0 -400
- package/esm/drivers/postgres/postgres-sql-serializer.js.map +0 -1
- package/esm/drivers/postgres/postgres-sync-adapter.d.ts +0 -83
- package/esm/drivers/postgres/postgres-sync-adapter.d.ts.map +0 -1
- package/esm/drivers/postgres/postgres-sync-adapter.js +0 -204
- package/esm/drivers/postgres/postgres-sync-adapter.js.map +0 -1
- package/esm/drivers/postgres/types.d.ts +0 -144
- package/esm/drivers/postgres/types.d.ts.map +0 -1
- package/esm/drivers/sql/index.d.ts +0 -10
- package/esm/drivers/sql/index.d.ts.map +0 -1
- package/esm/drivers/sql/sql-dialect.contract.d.ts +0 -204
- package/esm/drivers/sql/sql-dialect.contract.d.ts.map +0 -1
- package/esm/drivers/sql/sql-types.d.ts +0 -202
- package/esm/drivers/sql/sql-types.d.ts.map +0 -1
- package/esm/errors/missing-data-source.error.d.ts +0 -22
- package/esm/errors/missing-data-source.error.d.ts.map +0 -1
- package/esm/errors/missing-data-source.error.js +0 -29
- package/esm/errors/missing-data-source.error.js.map +0 -1
- package/esm/errors/transaction-rollback.error.d.ts +0 -20
- package/esm/errors/transaction-rollback.error.d.ts.map +0 -1
- package/esm/errors/transaction-rollback.error.js +0 -27
- package/esm/errors/transaction-rollback.error.js.map +0 -1
- package/esm/events/model-events.d.ts +0 -231
- package/esm/events/model-events.d.ts.map +0 -1
- package/esm/events/model-events.js +0 -259
- package/esm/events/model-events.js.map +0 -1
- package/esm/expressions/aggregate-expressions.d.ts +0 -215
- package/esm/expressions/aggregate-expressions.d.ts.map +0 -1
- package/esm/expressions/aggregate-expressions.js +0 -221
- package/esm/expressions/aggregate-expressions.js.map +0 -1
- package/esm/expressions/index.d.ts +0 -2
- package/esm/expressions/index.d.ts.map +0 -1
- package/esm/index.d.ts +0 -45
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +0 -1
- package/esm/migration/column-builder.d.ts +0 -417
- package/esm/migration/column-builder.d.ts.map +0 -1
- package/esm/migration/column-builder.js +0 -586
- package/esm/migration/column-builder.js.map +0 -1
- package/esm/migration/column-helpers.d.ts +0 -275
- package/esm/migration/column-helpers.d.ts.map +0 -1
- package/esm/migration/column-helpers.js +0 -389
- package/esm/migration/column-helpers.js.map +0 -1
- package/esm/migration/foreign-key-builder.d.ts +0 -103
- package/esm/migration/foreign-key-builder.d.ts.map +0 -1
- package/esm/migration/foreign-key-builder.js +0 -121
- package/esm/migration/foreign-key-builder.js.map +0 -1
- package/esm/migration/index.d.ts +0 -7
- package/esm/migration/index.d.ts.map +0 -1
- package/esm/migration/migration-runner.d.ts +0 -278
- package/esm/migration/migration-runner.d.ts.map +0 -1
- package/esm/migration/migration-runner.js +0 -815
- package/esm/migration/migration-runner.js.map +0 -1
- package/esm/migration/migration.d.ts +0 -1988
- package/esm/migration/migration.d.ts.map +0 -1
- package/esm/migration/migration.js +0 -2162
- package/esm/migration/migration.js.map +0 -1
- package/esm/migration/sql-grammar.d.ts +0 -61
- package/esm/migration/sql-grammar.d.ts.map +0 -1
- package/esm/migration/sql-grammar.js +0 -164
- package/esm/migration/sql-grammar.js.map +0 -1
- package/esm/migration/sql-serializer.d.ts +0 -22
- package/esm/migration/sql-serializer.d.ts.map +0 -1
- package/esm/migration/sql-serializer.js +0 -26
- package/esm/migration/sql-serializer.js.map +0 -1
- package/esm/migration/types.d.ts +0 -155
- package/esm/migration/types.d.ts.map +0 -1
- package/esm/model/methods/accessor-methods.d.ts +0 -13
- package/esm/model/methods/accessor-methods.d.ts.map +0 -1
- package/esm/model/methods/accessor-methods.js +0 -51
- package/esm/model/methods/accessor-methods.js.map +0 -1
- package/esm/model/methods/delete-methods.d.ts +0 -10
- package/esm/model/methods/delete-methods.d.ts.map +0 -1
- package/esm/model/methods/delete-methods.js +0 -10
- package/esm/model/methods/delete-methods.js.map +0 -1
- package/esm/model/methods/dirty-methods.d.ts +0 -10
- package/esm/model/methods/dirty-methods.d.ts.map +0 -1
- package/esm/model/methods/dirty-methods.js +0 -15
- package/esm/model/methods/dirty-methods.js.map +0 -1
- package/esm/model/methods/hydration-methods.d.ts +0 -10
- package/esm/model/methods/hydration-methods.d.ts.map +0 -1
- package/esm/model/methods/hydration-methods.js +0 -57
- package/esm/model/methods/hydration-methods.js.map +0 -1
- package/esm/model/methods/instance-event-methods.d.ts +0 -7
- package/esm/model/methods/instance-event-methods.d.ts.map +0 -1
- package/esm/model/methods/instance-event-methods.js +0 -15
- package/esm/model/methods/instance-event-methods.js.map +0 -1
- package/esm/model/methods/meta-methods.d.ts +0 -7
- package/esm/model/methods/meta-methods.d.ts.map +0 -1
- package/esm/model/methods/meta-methods.js +0 -78
- package/esm/model/methods/meta-methods.js.map +0 -1
- package/esm/model/methods/query-methods.d.ts +0 -24
- package/esm/model/methods/query-methods.d.ts.map +0 -1
- package/esm/model/methods/query-methods.js +0 -164
- package/esm/model/methods/query-methods.js.map +0 -1
- package/esm/model/methods/restore-methods.d.ts +0 -10
- package/esm/model/methods/restore-methods.d.ts.map +0 -1
- package/esm/model/methods/restore-methods.js +0 -13
- package/esm/model/methods/restore-methods.js.map +0 -1
- package/esm/model/methods/scope-methods.d.ts +0 -7
- package/esm/model/methods/scope-methods.d.ts.map +0 -1
- package/esm/model/methods/scope-methods.js +0 -15
- package/esm/model/methods/scope-methods.js.map +0 -1
- package/esm/model/methods/serialization-methods.d.ts +0 -3
- package/esm/model/methods/serialization-methods.d.ts.map +0 -1
- package/esm/model/methods/serialization-methods.js +0 -27
- package/esm/model/methods/serialization-methods.js.map +0 -1
- package/esm/model/methods/static-event-methods.d.ts +0 -9
- package/esm/model/methods/static-event-methods.d.ts.map +0 -1
- package/esm/model/methods/static-event-methods.js +0 -29
- package/esm/model/methods/static-event-methods.js.map +0 -1
- package/esm/model/methods/write-methods.d.ts +0 -10
- package/esm/model/methods/write-methods.d.ts.map +0 -1
- package/esm/model/methods/write-methods.js +0 -52
- package/esm/model/methods/write-methods.js.map +0 -1
- package/esm/model/model.d.ts +0 -1647
- package/esm/model/model.d.ts.map +0 -1
- package/esm/model/model.js +0 -1657
- package/esm/model/model.js.map +0 -1
- package/esm/model/model.types.d.ts +0 -44
- package/esm/model/model.types.d.ts.map +0 -1
- package/esm/model/register-model.d.ts +0 -81
- package/esm/model/register-model.d.ts.map +0 -1
- package/esm/model/register-model.js +0 -94
- package/esm/model/register-model.js.map +0 -1
- package/esm/query-builder/query-builder.d.ts +0 -556
- package/esm/query-builder/query-builder.d.ts.map +0 -1
- package/esm/query-builder/query-builder.js +0 -1070
- package/esm/query-builder/query-builder.js.map +0 -1
- package/esm/relations/helpers.d.ts +0 -156
- package/esm/relations/helpers.d.ts.map +0 -1
- package/esm/relations/helpers.js +0 -202
- package/esm/relations/helpers.js.map +0 -1
- package/esm/relations/index.d.ts +0 -35
- package/esm/relations/index.d.ts.map +0 -1
- package/esm/relations/pivot-operations.d.ts +0 -160
- package/esm/relations/pivot-operations.d.ts.map +0 -1
- package/esm/relations/pivot-operations.js +0 -293
- package/esm/relations/pivot-operations.js.map +0 -1
- package/esm/relations/relation-hydrator.d.ts +0 -68
- package/esm/relations/relation-hydrator.d.ts.map +0 -1
- package/esm/relations/relation-hydrator.js +0 -81
- package/esm/relations/relation-hydrator.js.map +0 -1
- package/esm/relations/relation-loader.d.ts +0 -194
- package/esm/relations/relation-loader.d.ts.map +0 -1
- package/esm/relations/relation-loader.js +0 -466
- package/esm/relations/relation-loader.js.map +0 -1
- package/esm/relations/types.d.ts +0 -306
- package/esm/relations/types.d.ts.map +0 -1
- package/esm/remover/database-remover.d.ts +0 -100
- package/esm/remover/database-remover.d.ts.map +0 -1
- package/esm/remover/database-remover.js +0 -214
- package/esm/remover/database-remover.js.map +0 -1
- package/esm/restorer/database-restorer.d.ts +0 -131
- package/esm/restorer/database-restorer.d.ts.map +0 -1
- package/esm/restorer/database-restorer.js +0 -434
- package/esm/restorer/database-restorer.js.map +0 -1
- package/esm/sql-database-dirty-tracker.d.ts +0 -13
- package/esm/sql-database-dirty-tracker.d.ts.map +0 -1
- package/esm/sql-database-dirty-tracker.js +0 -14
- package/esm/sql-database-dirty-tracker.js.map +0 -1
- package/esm/sync/index.d.ts +0 -12
- package/esm/sync/index.d.ts.map +0 -1
- package/esm/sync/model-events.d.ts +0 -62
- package/esm/sync/model-events.d.ts.map +0 -1
- package/esm/sync/model-events.js +0 -49
- package/esm/sync/model-events.js.map +0 -1
- package/esm/sync/model-sync-operation.d.ts +0 -163
- package/esm/sync/model-sync-operation.d.ts.map +0 -1
- package/esm/sync/model-sync-operation.js +0 -292
- package/esm/sync/model-sync-operation.js.map +0 -1
- package/esm/sync/model-sync.d.ts +0 -130
- package/esm/sync/model-sync.d.ts.map +0 -1
- package/esm/sync/model-sync.js +0 -178
- package/esm/sync/model-sync.js.map +0 -1
- package/esm/sync/sync-context.d.ts +0 -70
- package/esm/sync/sync-context.d.ts.map +0 -1
- package/esm/sync/sync-context.js +0 -101
- package/esm/sync/sync-context.js.map +0 -1
- package/esm/sync/sync-manager.d.ts +0 -213
- package/esm/sync/sync-manager.d.ts.map +0 -1
- package/esm/sync/sync-manager.js +0 -689
- package/esm/sync/sync-manager.js.map +0 -1
- package/esm/sync/types.d.ts +0 -289
- package/esm/sync/types.d.ts.map +0 -1
- package/esm/test-migrations/test-enhanced-features.migration.d.ts +0 -15
- package/esm/test-migrations/test-enhanced-features.migration.d.ts.map +0 -1
- package/esm/types.d.ts +0 -371
- package/esm/types.d.ts.map +0 -1
- package/esm/utils/connect-to-database.d.ts +0 -307
- package/esm/utils/connect-to-database.d.ts.map +0 -1
- package/esm/utils/connect-to-database.js +0 -130
- package/esm/utils/connect-to-database.js.map +0 -1
- package/esm/utils/database-writer.utils.d.ts +0 -15
- package/esm/utils/database-writer.utils.d.ts.map +0 -1
- package/esm/utils/database-writer.utils.js +0 -14
- package/esm/utils/database-writer.utils.js.map +0 -1
- package/esm/utils/define-model.js +0 -100
- package/esm/utils/define-model.js.map +0 -1
- package/esm/utils/is-valid-date-value.d.ts +0 -5
- package/esm/utils/is-valid-date-value.d.ts.map +0 -1
- package/esm/utils/is-valid-date-value.js +0 -25
- package/esm/utils/is-valid-date-value.js.map +0 -1
- package/esm/utils/once-connected.d.ts +0 -146
- package/esm/utils/once-connected.d.ts.map +0 -1
- package/esm/utils/once-connected.js +0 -251
- package/esm/utils/once-connected.js.map +0 -1
- package/esm/validation/database-seal-plugins.d.ts +0 -12
- package/esm/validation/database-seal-plugins.d.ts.map +0 -1
- package/esm/validation/database-seal-plugins.js +0 -1
- package/esm/validation/database-seal-plugins.js.map +0 -1
- package/esm/validation/database-writer-validation-error.d.ts +0 -97
- package/esm/validation/database-writer-validation-error.d.ts.map +0 -1
- package/esm/validation/database-writer-validation-error.js +0 -160
- package/esm/validation/database-writer-validation-error.js.map +0 -1
- package/esm/validation/index.d.ts +0 -3
- package/esm/validation/index.d.ts.map +0 -1
- package/esm/validation/mutators/embed-mutator.d.ts +0 -9
- package/esm/validation/mutators/embed-mutator.d.ts.map +0 -1
- package/esm/validation/mutators/embed-mutator.js +0 -33
- package/esm/validation/mutators/embed-mutator.js.map +0 -1
- package/esm/validation/plugins/embed-validator-plugin.d.ts +0 -24
- package/esm/validation/plugins/embed-validator-plugin.d.ts.map +0 -1
- package/esm/validation/plugins/embed-validator-plugin.js +0 -18
- package/esm/validation/plugins/embed-validator-plugin.js.map +0 -1
- package/esm/validation/rules/database-model-rule.d.ts +0 -7
- package/esm/validation/rules/database-model-rule.d.ts.map +0 -1
- package/esm/validation/rules/database-model-rule.js +0 -27
- package/esm/validation/rules/database-model-rule.js.map +0 -1
- package/esm/validation/transformers/embed-model-transformer.d.ts +0 -3
- package/esm/validation/transformers/embed-model-transformer.d.ts.map +0 -1
- package/esm/validation/transformers/embed-model-transformer.js +0 -18
- package/esm/validation/transformers/embed-model-transformer.js.map +0 -1
- package/esm/validation/validators/embed-validator.d.ts +0 -21
- package/esm/validation/validators/embed-validator.d.ts.map +0 -1
- package/esm/validation/validators/embed-validator.js +0 -43
- package/esm/validation/validators/embed-validator.js.map +0 -1
- package/esm/writer/database-writer.d.ts +0 -174
- package/esm/writer/database-writer.d.ts.map +0 -1
- package/esm/writer/database-writer.js +0 -400
- package/esm/writer/database-writer.js.map +0 -1
|
@@ -0,0 +1,1105 @@
|
|
|
1
|
+
import { dataSourceRegistry } from "../../data-source/data-source-registry.mjs";
|
|
2
|
+
import { resolveModelClass, tryResolveModelClass } from "../../model/register-model.mjs";
|
|
3
|
+
import { inferBelongsToForeignKey, inferHasForeignKey, inferPivotKey, inferPivotTable } from "../../relations/key-conventions.mjs";
|
|
4
|
+
import { RelationLoader, attachLoadedRelation } from "../../relations/relation-loader.mjs";
|
|
5
|
+
import { isAggregateExpression } from "../../expressions/aggregate-expressions.mjs";
|
|
6
|
+
import { QueryBuilder } from "../../query-builder/query-builder.mjs";
|
|
7
|
+
import { PostgresQueryParser } from "./postgres-query-parser.mjs";
|
|
8
|
+
|
|
9
|
+
//#region ../../@warlock.js/cascade/src/drivers/postgres/postgres-query-builder.ts
|
|
10
|
+
/**
|
|
11
|
+
* Cast an Op[] to PostgresParserOperation[] — the shapes are compatible since
|
|
12
|
+
* both have `type: string` and `data: Record<string, unknown>`.
|
|
13
|
+
*/
|
|
14
|
+
function toParserOps(ops) {
|
|
15
|
+
return ops;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* PostgreSQL Query Builder.
|
|
19
|
+
*
|
|
20
|
+
* Collects query operations (via the base class) and delegates SQL generation
|
|
21
|
+
* to `PostgresQueryParser`. Owns execution, hydration, and relation loading.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const users = await User.query()
|
|
26
|
+
* .select(["id", "name", "email"])
|
|
27
|
+
* .where("status", "active")
|
|
28
|
+
* .orderBy("createdAt", "desc")
|
|
29
|
+
* .limit(10)
|
|
30
|
+
* .get();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
var PostgresQueryBuilder = class PostgresQueryBuilder extends QueryBuilder {
|
|
34
|
+
table;
|
|
35
|
+
/** Data source backing this builder. */
|
|
36
|
+
dataSource;
|
|
37
|
+
/** Hydration callback for transforming result rows into model instances. */
|
|
38
|
+
hydrateCallback;
|
|
39
|
+
/** Invoked before query execution. */
|
|
40
|
+
fetchingCallback;
|
|
41
|
+
/** Invoked after fetch but before hydration. */
|
|
42
|
+
hydratingCallback;
|
|
43
|
+
/** Invoked after fetch and hydration. */
|
|
44
|
+
fetchedCallback;
|
|
45
|
+
/**
|
|
46
|
+
* Map of relations registered via `joinWith()`.
|
|
47
|
+
* Keyed by dot-notation path (e.g. "organizationAiModel.aiModel").
|
|
48
|
+
*/
|
|
49
|
+
joinRelations = /* @__PURE__ */ new Map();
|
|
50
|
+
/**
|
|
51
|
+
* Idempotency guard for `applyJoinRelations()` so calling `parse()` then
|
|
52
|
+
* `get()` (or `parse()` twice) doesn't double-emit `selectRelatedColumns`
|
|
53
|
+
* operations.
|
|
54
|
+
*/
|
|
55
|
+
joinRelationsApplied = false;
|
|
56
|
+
/**
|
|
57
|
+
* Idempotency guard for `applyCountRelations()` — see `joinRelationsApplied`.
|
|
58
|
+
*/
|
|
59
|
+
countRelationsApplied = false;
|
|
60
|
+
/**
|
|
61
|
+
* Idempotency guard for `applyHasRelations()` — see `joinRelationsApplied`.
|
|
62
|
+
*/
|
|
63
|
+
hasRelationsApplied = false;
|
|
64
|
+
/**
|
|
65
|
+
* Alias → SQL expression for two-arg `groupBy` aggregates. Recorded by the
|
|
66
|
+
* `groupBy` override; consumed by `applyGroupByAggregates` to rewrite a
|
|
67
|
+
* `having()` on the alias into the underlying expression (Postgres forbids
|
|
68
|
+
* SELECT aliases in HAVING).
|
|
69
|
+
*/
|
|
70
|
+
aggregateAliases = /* @__PURE__ */ new Map();
|
|
71
|
+
/**
|
|
72
|
+
* Idempotency guard for `applyGroupByAggregates()` — see `joinRelationsApplied`.
|
|
73
|
+
*/
|
|
74
|
+
groupByAggregatesApplied = false;
|
|
75
|
+
/**
|
|
76
|
+
* @param table - Target table name
|
|
77
|
+
* @param dataSource - Optional (uses default data source from registry if omitted)
|
|
78
|
+
*/
|
|
79
|
+
constructor(table, dataSource) {
|
|
80
|
+
super();
|
|
81
|
+
this.table = table;
|
|
82
|
+
this.dataSource = dataSource ?? dataSourceRegistry.get();
|
|
83
|
+
}
|
|
84
|
+
get driver() {
|
|
85
|
+
return this.dataSource.driver;
|
|
86
|
+
}
|
|
87
|
+
clone() {
|
|
88
|
+
const cloned = new PostgresQueryBuilder(this.table, this.dataSource);
|
|
89
|
+
cloned.operations = [...this.operations];
|
|
90
|
+
cloned.pendingGlobalScopes = this.pendingGlobalScopes;
|
|
91
|
+
cloned.availableLocalScopes = this.availableLocalScopes;
|
|
92
|
+
cloned.disabledGlobalScopes = new Set(this.disabledGlobalScopes);
|
|
93
|
+
cloned.scopesApplied = this.scopesApplied;
|
|
94
|
+
cloned.eagerLoadRelations = new Map(this.eagerLoadRelations);
|
|
95
|
+
cloned.countRelations = new Map(this.countRelations);
|
|
96
|
+
cloned.relationDefinitions = this.relationDefinitions;
|
|
97
|
+
cloned.modelClass = this.modelClass;
|
|
98
|
+
cloned.hydrateCallback = this.hydrateCallback;
|
|
99
|
+
cloned.joinRelations = new Map(this.joinRelations);
|
|
100
|
+
cloned.joinRelationsApplied = this.joinRelationsApplied;
|
|
101
|
+
cloned.countRelationsApplied = this.countRelationsApplied;
|
|
102
|
+
cloned.hasRelationsApplied = this.hasRelationsApplied;
|
|
103
|
+
cloned.aggregateAliases = new Map(this.aggregateAliases);
|
|
104
|
+
cloned.groupByAggregatesApplied = this.groupByAggregatesApplied;
|
|
105
|
+
return cloned;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Native-query escape hatch. Passes `operations[]` to the callback for
|
|
109
|
+
* direct manipulation. Use sparingly — only when fluent API is insufficient.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* q.raw(ops => ops.push({ type: "whereRaw", data: { expression: "1=1" } }))
|
|
113
|
+
*/
|
|
114
|
+
raw(callback) {
|
|
115
|
+
callback(this.operations);
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Record a DISTINCT flag AND auto-select the field(s).
|
|
120
|
+
* In PostgreSQL, DISTINCT ON (col) requires the col to appear in SELECT.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* q.distinctValues("category") // SELECT category … DISTINCT ON (category)
|
|
124
|
+
* q.distinctValues(["category", "status"]) // both fields in DISTINCT ON and SELECT
|
|
125
|
+
*/
|
|
126
|
+
distinctValues(fields) {
|
|
127
|
+
super.distinctValues(fields);
|
|
128
|
+
if (fields) {
|
|
129
|
+
const fieldArr = Array.isArray(fields) ? fields : [fields];
|
|
130
|
+
this.addOperation("select", { fields: fieldArr });
|
|
131
|
+
}
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
groupBy(fields, aggregates) {
|
|
135
|
+
if (!aggregates) return super.groupBy(fields);
|
|
136
|
+
const fieldList = Array.isArray(fields) ? fields : [fields];
|
|
137
|
+
this.addOperation("select", { fields: fieldList });
|
|
138
|
+
for (const [alias, expression] of Object.entries(aggregates)) {
|
|
139
|
+
let sql;
|
|
140
|
+
if (isAggregateExpression(expression)) sql = this.driver.dialect.aggregateToSql(expression);
|
|
141
|
+
else if (typeof expression === "string") sql = expression;
|
|
142
|
+
else throw new Error(`groupBy aggregate "${alias}" must be a $agg.* helper or a raw SQL string on Postgres; got ${typeof expression}. MongoDB operator objects are not portable to SQL — use selectRaw with explicit SQL.`);
|
|
143
|
+
this.aggregateAliases.set(alias, sql);
|
|
144
|
+
this.addOperation("selectRaw", {
|
|
145
|
+
expression: `${sql} AS ${this.driver.dialect.quoteIdentifier(alias)}`,
|
|
146
|
+
bindings: []
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return super.groupBy(fields);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Nearest-neighbour vector similarity search via pgvector cosine distance.
|
|
153
|
+
*
|
|
154
|
+
* Adds two operations atomically:
|
|
155
|
+
* 1. `selectRaw` → `1 - (column <=> $n::vector) AS <alias>`
|
|
156
|
+
* Makes the similarity score available on every returned row.
|
|
157
|
+
* 2. `orderByRaw` → `column <=> $n::vector`
|
|
158
|
+
* Tells the PostgreSQL query planner to use the IVFFlat/HNSW vector index.
|
|
159
|
+
* Using the alias in ORDER BY would bypass the index — the raw expression is required.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const results = await Vector.query()
|
|
164
|
+
* .where({ organization_id: "org-123", content_type: "summary" })
|
|
165
|
+
* .similarTo("embedding", queryEmbedding)
|
|
166
|
+
* .limit(5)
|
|
167
|
+
* .get<VectorRow & { score: number }>();
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
similarTo(column, embedding, alias = "score") {
|
|
171
|
+
const literal = `[${embedding.join(",")}]`;
|
|
172
|
+
const quotedCol = this.driver.dialect.quoteIdentifier(column);
|
|
173
|
+
const quotedTable = this.driver.dialect.quoteIdentifier(this.table);
|
|
174
|
+
this.addOperation("selectRaw", {
|
|
175
|
+
expression: `${quotedTable}.*`,
|
|
176
|
+
bindings: []
|
|
177
|
+
});
|
|
178
|
+
this.addOperation("selectRaw", {
|
|
179
|
+
expression: `1 - (${quotedCol} <=> ?::vector) AS ${alias}`,
|
|
180
|
+
bindings: [literal]
|
|
181
|
+
});
|
|
182
|
+
this.addOperation("orderByRaw", {
|
|
183
|
+
expression: `${quotedCol} <=> ?::vector`,
|
|
184
|
+
bindings: [literal]
|
|
185
|
+
});
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
/** Set a hydration callback that transforms each result row. */
|
|
189
|
+
hydrate(callback) {
|
|
190
|
+
this.hydrateCallback = callback;
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
/** Register a callback invoked before query execution. */
|
|
194
|
+
onFetching(callback) {
|
|
195
|
+
this.fetchingCallback = callback;
|
|
196
|
+
return () => {
|
|
197
|
+
this.fetchingCallback = void 0;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** Register a callback invoked after fetch but before hydration. */
|
|
201
|
+
onHydrating(callback) {
|
|
202
|
+
this.hydratingCallback = callback;
|
|
203
|
+
return () => {
|
|
204
|
+
this.hydratingCallback = void 0;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/** Register a callback invoked after fetch and hydration. */
|
|
208
|
+
onFetched(callback) {
|
|
209
|
+
this.fetchedCallback = callback;
|
|
210
|
+
return () => {
|
|
211
|
+
this.fetchedCallback = void 0;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/** Apply pending global scopes to the operations list. */
|
|
215
|
+
applyPendingScopes() {
|
|
216
|
+
if (!this.pendingGlobalScopes || this.scopesApplied) return;
|
|
217
|
+
const beforeOps = [];
|
|
218
|
+
const afterOps = [];
|
|
219
|
+
for (const [name, { callback, timing }] of this.pendingGlobalScopes) {
|
|
220
|
+
if (this.disabledGlobalScopes.has(name)) continue;
|
|
221
|
+
const temp = new PostgresQueryBuilder(this.table, this.dataSource);
|
|
222
|
+
callback(temp);
|
|
223
|
+
if (timing === "before") beforeOps.push(...temp.operations);
|
|
224
|
+
else afterOps.push(...temp.operations);
|
|
225
|
+
}
|
|
226
|
+
this.operations = [
|
|
227
|
+
...beforeOps,
|
|
228
|
+
...this.operations,
|
|
229
|
+
...afterOps
|
|
230
|
+
];
|
|
231
|
+
this.scopesApplied = true;
|
|
232
|
+
}
|
|
233
|
+
/** Array field contains a value (or object with key). */
|
|
234
|
+
whereArrayContains(field, value, key) {
|
|
235
|
+
const quotedField = this.driver.dialect.quoteIdentifier(field);
|
|
236
|
+
if (key) this.addOperation("whereRaw", {
|
|
237
|
+
expression: `${quotedField} @> ?::jsonb`,
|
|
238
|
+
bindings: [JSON.stringify([{ [key]: value }])]
|
|
239
|
+
});
|
|
240
|
+
else this.addOperation("whereRaw", {
|
|
241
|
+
expression: `? = ANY(${quotedField})`,
|
|
242
|
+
bindings: [value]
|
|
243
|
+
});
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
/** Array field does NOT contain a value (or object with key). */
|
|
247
|
+
whereArrayNotContains(field, value, key) {
|
|
248
|
+
const quotedField = this.driver.dialect.quoteIdentifier(field);
|
|
249
|
+
if (key) this.addOperation("whereRaw", {
|
|
250
|
+
expression: `NOT (${quotedField} @> ?::jsonb)`,
|
|
251
|
+
bindings: [JSON.stringify([{ [key]: value }])]
|
|
252
|
+
});
|
|
253
|
+
else this.addOperation("whereRaw", {
|
|
254
|
+
expression: `NOT (? = ANY(${quotedField}))`,
|
|
255
|
+
bindings: [value]
|
|
256
|
+
});
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
/** Array field contains value OR is empty. */
|
|
260
|
+
whereArrayHasOrEmpty(field, value, key) {
|
|
261
|
+
const quotedField = this.driver.dialect.quoteIdentifier(field);
|
|
262
|
+
if (key) this.addOperation("whereRaw", {
|
|
263
|
+
expression: `(${quotedField} @> ?::jsonb OR ${quotedField} = '[]'::jsonb OR ${quotedField} IS NULL)`,
|
|
264
|
+
bindings: [JSON.stringify([{ [key]: value }])]
|
|
265
|
+
});
|
|
266
|
+
else this.addOperation("whereRaw", {
|
|
267
|
+
expression: `(? = ANY(${quotedField}) OR array_length(${quotedField}, 1) IS NULL)`,
|
|
268
|
+
bindings: [value]
|
|
269
|
+
});
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
/** Array field does NOT contain value OR is empty. */
|
|
273
|
+
whereArrayNotHaveOrEmpty(field, value, key) {
|
|
274
|
+
const quotedField = this.driver.dialect.quoteIdentifier(field);
|
|
275
|
+
if (key) this.addOperation("whereRaw", {
|
|
276
|
+
expression: `(NOT (${quotedField} @> ?::jsonb) OR ${quotedField} = '[]'::jsonb OR ${quotedField} IS NULL)`,
|
|
277
|
+
bindings: [JSON.stringify([{ [key]: value }])]
|
|
278
|
+
});
|
|
279
|
+
else this.addOperation("whereRaw", {
|
|
280
|
+
expression: `(NOT (? = ANY(${quotedField})) OR array_length(${quotedField}, 1) IS NULL)`,
|
|
281
|
+
bindings: [value]
|
|
282
|
+
});
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Load relations via SQL JOINs (single query) with optional per-relation constraints.
|
|
287
|
+
*
|
|
288
|
+
* Supports:
|
|
289
|
+
* - `joinWith("author")` / `joinWith(["author", "category"])`
|
|
290
|
+
* - `joinWith({ actions: q => q.where("status", "pending").limit(5) })`
|
|
291
|
+
* - `joinWith({ organizationAiModel: "id,name", actions: q => q.orderBy("sort_order") })`
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ChatMessage.joinWith({
|
|
295
|
+
* actions: q => q.where("status", "pending").orderBy("sort_order", "asc").limit(5),
|
|
296
|
+
* organizationAiModel: "id,createdAt",
|
|
297
|
+
* })
|
|
298
|
+
*/
|
|
299
|
+
joinWith(...args) {
|
|
300
|
+
const entries = [];
|
|
301
|
+
for (const arg of args) if (typeof arg === "string") entries.push({ path: arg });
|
|
302
|
+
else if (Array.isArray(arg)) for (const rel of arg) entries.push({ path: rel });
|
|
303
|
+
else if (typeof arg === "object" && arg !== null) for (const [rel, val] of Object.entries(arg)) entries.push({
|
|
304
|
+
path: rel,
|
|
305
|
+
constraint: val
|
|
306
|
+
});
|
|
307
|
+
for (const { path, constraint } of entries) {
|
|
308
|
+
const segments = path.split(".");
|
|
309
|
+
let currentModel = this.modelClass;
|
|
310
|
+
let currentPath = "";
|
|
311
|
+
for (let i = 0; i < segments.length; i++) {
|
|
312
|
+
const rawSeg = segments[i];
|
|
313
|
+
const colonIdx = rawSeg.indexOf(":");
|
|
314
|
+
const segName = colonIdx === -1 ? rawSeg : rawSeg.slice(0, colonIdx);
|
|
315
|
+
const segColumns = colonIdx === -1 ? void 0 : rawSeg.slice(colonIdx + 1).split(",").filter(Boolean);
|
|
316
|
+
currentPath = currentPath ? `${currentPath}.${segName}` : segName;
|
|
317
|
+
if (this.joinRelations.has(currentPath)) {
|
|
318
|
+
const existing = this.joinRelations.get(currentPath);
|
|
319
|
+
if (segColumns) existing.select = segColumns;
|
|
320
|
+
if (i === segments.length - 1 && constraint !== void 0) existing.constraintOps = this._resolveConstraintOps(constraint);
|
|
321
|
+
currentModel = tryResolveModelClass(existing.model);
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (!this.relationDefinitions) continue;
|
|
325
|
+
const def = (i === 0 ? this.relationDefinitions : currentModel?.relations)?.[segName];
|
|
326
|
+
if (!def) throw new Error(`Relation "${segName}" not found on model ${currentModel?.name ?? "unknown"}`);
|
|
327
|
+
let selectColumns = segColumns ?? def.select;
|
|
328
|
+
let constraintOps;
|
|
329
|
+
if (i === segments.length - 1 && constraint !== void 0) if (typeof constraint === "string") selectColumns = constraint.split(",").filter(Boolean);
|
|
330
|
+
else constraintOps = this._resolveConstraintOps(constraint);
|
|
331
|
+
const alias = currentPath.replace(/\./g, "_");
|
|
332
|
+
this.joinRelations.set(currentPath, {
|
|
333
|
+
alias,
|
|
334
|
+
type: def.type,
|
|
335
|
+
model: def.model,
|
|
336
|
+
localKey: def.localKey,
|
|
337
|
+
foreignKey: def.foreignKey,
|
|
338
|
+
ownerKey: def.ownerKey,
|
|
339
|
+
parentPath: i > 0 ? currentPath.substring(0, currentPath.lastIndexOf(".")) : null,
|
|
340
|
+
relationName: segName,
|
|
341
|
+
parentModel: currentModel,
|
|
342
|
+
select: selectColumns,
|
|
343
|
+
constraintOps
|
|
344
|
+
});
|
|
345
|
+
currentModel = tryResolveModelClass(def.model);
|
|
346
|
+
if (!currentModel) throw new Error(`Relation model not found for "${segName}" in "${currentPath}"`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
/** Run a joinWith constraint callback against a sub-QB and capture its operations. */
|
|
352
|
+
_resolveConstraintOps(constraint) {
|
|
353
|
+
if (typeof constraint === "string") return [];
|
|
354
|
+
const sub = new PostgresQueryBuilder("__sub__", this.dataSource);
|
|
355
|
+
constraint(sub);
|
|
356
|
+
return sub.operations;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Execute the query and return all matching rows.
|
|
360
|
+
*/
|
|
361
|
+
async get() {
|
|
362
|
+
this.applyPendingScopes();
|
|
363
|
+
this._processJoinWithOps();
|
|
364
|
+
this.applyJoinRelations();
|
|
365
|
+
this.applyHasRelations();
|
|
366
|
+
this.applyCountRelations();
|
|
367
|
+
this.applyGroupByAggregates();
|
|
368
|
+
if (this.fetchingCallback) await this.fetchingCallback(this);
|
|
369
|
+
const { query = "", bindings = [] } = new PostgresQueryParser({
|
|
370
|
+
table: this.table,
|
|
371
|
+
operations: toParserOps(this.operations)
|
|
372
|
+
}).parse();
|
|
373
|
+
try {
|
|
374
|
+
let records = (await this.driver.query(query, bindings)).rows;
|
|
375
|
+
const joinedData = this.extractJoinedRelationData(records);
|
|
376
|
+
if (this.hydratingCallback) await this.hydratingCallback(records, {});
|
|
377
|
+
if (this.hydrateCallback) records = records.map((row, index) => this.hydrateCallback(row, index));
|
|
378
|
+
this.attachJoinedRelations(records, joinedData);
|
|
379
|
+
await this.applyEagerLoading(records);
|
|
380
|
+
if (this.fetchedCallback) await this.fetchedCallback(records, {});
|
|
381
|
+
this.operations = [];
|
|
382
|
+
return records;
|
|
383
|
+
} catch (error) {
|
|
384
|
+
console.log("Error while executing:", query, bindings);
|
|
385
|
+
console.log("Query Builder Error:", error);
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/** Get first result. */
|
|
390
|
+
async first() {
|
|
391
|
+
return (await this.limit(1).get())[0] ?? null;
|
|
392
|
+
}
|
|
393
|
+
/** Get last result (by id desc). */
|
|
394
|
+
async last() {
|
|
395
|
+
return (await this.orderByDesc("id").limit(1).get())[0] ?? null;
|
|
396
|
+
}
|
|
397
|
+
/** Get random results. */
|
|
398
|
+
async random(limit) {
|
|
399
|
+
this.orderByRaw("RANDOM()");
|
|
400
|
+
if (limit) this.limit(limit);
|
|
401
|
+
return this.get();
|
|
402
|
+
}
|
|
403
|
+
/** Get first or throw. */
|
|
404
|
+
async firstOrFail() {
|
|
405
|
+
const result = await this.first();
|
|
406
|
+
if (!result) throw new Error("No records found");
|
|
407
|
+
return result;
|
|
408
|
+
}
|
|
409
|
+
/** Get first or call callback. */
|
|
410
|
+
async firstOr(callback) {
|
|
411
|
+
return await this.first() ?? await callback();
|
|
412
|
+
}
|
|
413
|
+
/** Get first or return null. */
|
|
414
|
+
async firstOrNull() {
|
|
415
|
+
return this.first();
|
|
416
|
+
}
|
|
417
|
+
/** Get first or return default. */
|
|
418
|
+
async firstOrNew(defaults) {
|
|
419
|
+
return await this.first() ?? defaults;
|
|
420
|
+
}
|
|
421
|
+
/** Find by primary key. */
|
|
422
|
+
async find(id) {
|
|
423
|
+
return this.where("id", id).first();
|
|
424
|
+
}
|
|
425
|
+
/** Count matching rows. */
|
|
426
|
+
async count() {
|
|
427
|
+
this.applyPendingScopes();
|
|
428
|
+
const countOps = toParserOps([...this.operations.filter((op) => op.type.includes("where") || op.type.includes("join")), {
|
|
429
|
+
type: "selectRaw",
|
|
430
|
+
data: { expression: "COUNT(*) AS \"count\"" }
|
|
431
|
+
}]);
|
|
432
|
+
const { query = "", bindings = [] } = new PostgresQueryParser({
|
|
433
|
+
table: this.table,
|
|
434
|
+
operations: countOps
|
|
435
|
+
}).parse();
|
|
436
|
+
const result = await this.driver.query(query, bindings);
|
|
437
|
+
return parseInt(result.rows[0]?.count ?? "0", 10);
|
|
438
|
+
}
|
|
439
|
+
/** SUM a numeric field. */
|
|
440
|
+
async sum(field) {
|
|
441
|
+
this.applyPendingScopes();
|
|
442
|
+
const result = await this.selectRaw(`SUM(${field}) as sum`).first();
|
|
443
|
+
return parseFloat(result?.sum ?? "0");
|
|
444
|
+
}
|
|
445
|
+
/** AVG of a numeric field. */
|
|
446
|
+
async avg(field) {
|
|
447
|
+
this.applyPendingScopes();
|
|
448
|
+
const result = await this.selectRaw(`AVG(${field}) as avg`).first();
|
|
449
|
+
return parseFloat(result?.avg ?? "0");
|
|
450
|
+
}
|
|
451
|
+
/** MIN of a numeric field. */
|
|
452
|
+
async min(field) {
|
|
453
|
+
this.applyPendingScopes();
|
|
454
|
+
const result = await this.selectRaw(`MIN(${field}) as min`).first();
|
|
455
|
+
return parseFloat(result?.min ?? "0");
|
|
456
|
+
}
|
|
457
|
+
/** MAX of a numeric field. */
|
|
458
|
+
async max(field) {
|
|
459
|
+
this.applyPendingScopes();
|
|
460
|
+
const result = await this.selectRaw(`MAX(${field}) as max`).first();
|
|
461
|
+
return parseFloat(result?.max ?? "0");
|
|
462
|
+
}
|
|
463
|
+
/** Get distinct values for a field. */
|
|
464
|
+
async distinct(field) {
|
|
465
|
+
this.distinctValues(field);
|
|
466
|
+
return (await this.get()).map((row) => row[field]);
|
|
467
|
+
}
|
|
468
|
+
/** Get array of all values for a single field. */
|
|
469
|
+
async pluck(field) {
|
|
470
|
+
return (await this.select([field]).get()).map((row) => row[field]);
|
|
471
|
+
}
|
|
472
|
+
/** Get a single scalar value. */
|
|
473
|
+
async value(field) {
|
|
474
|
+
return (await this.select([field]).first())?.[field] ?? null;
|
|
475
|
+
}
|
|
476
|
+
/** Check whether any matching rows exist. */
|
|
477
|
+
async exists() {
|
|
478
|
+
return await this.limit(1).count() > 0;
|
|
479
|
+
}
|
|
480
|
+
/** Check whether NO matching rows exist. */
|
|
481
|
+
async notExists() {
|
|
482
|
+
return !await this.exists();
|
|
483
|
+
}
|
|
484
|
+
/** COUNT DISTINCT a field. */
|
|
485
|
+
async countDistinct(field) {
|
|
486
|
+
const result = await this.selectRaw(`COUNT(DISTINCT ${field}) as count`).first();
|
|
487
|
+
return parseInt(result?.count ?? "0", 10);
|
|
488
|
+
}
|
|
489
|
+
/** Get latest records ordered by a column. */
|
|
490
|
+
async latest(column = "createdAt") {
|
|
491
|
+
return this.orderBy(column, "desc").get();
|
|
492
|
+
}
|
|
493
|
+
/** Increment a numeric field. Returns new value. */
|
|
494
|
+
async increment(field, amount = 1) {
|
|
495
|
+
this.applyPendingScopes();
|
|
496
|
+
const { sql: filterSql, params: filterParams } = this.buildFilter();
|
|
497
|
+
const updateSql = `UPDATE ${this.driver.dialect.quoteIdentifier(this.table)} SET ${this.driver.dialect.quoteIdentifier(field)} = COALESCE(${this.driver.dialect.quoteIdentifier(field)}, 0) + $1 ` + (filterSql ? `WHERE ${filterSql.replace("WHERE ", "")} ` : "") + `RETURNING ${this.driver.dialect.quoteIdentifier(field)}`;
|
|
498
|
+
return (await this.driver.query(updateSql, [amount, ...filterParams])).rows[0]?.[field] ?? 0;
|
|
499
|
+
}
|
|
500
|
+
/** Decrement a numeric field. Returns new value. */
|
|
501
|
+
async decrement(field, amount = 1) {
|
|
502
|
+
return this.increment(field, -amount);
|
|
503
|
+
}
|
|
504
|
+
/** Increment a field for all matching rows. Returns affected row count. */
|
|
505
|
+
async incrementMany(field, amount = 1) {
|
|
506
|
+
this.applyPendingScopes();
|
|
507
|
+
const { sql: filterSql, params: filterParams } = this.buildFilter();
|
|
508
|
+
const updateSql = `UPDATE ${this.driver.dialect.quoteIdentifier(this.table)} SET ${this.driver.dialect.quoteIdentifier(field)} = COALESCE(${this.driver.dialect.quoteIdentifier(field)}, 0) + $1` + (filterSql ? ` WHERE ${filterSql.replace("WHERE ", "")}` : "");
|
|
509
|
+
return (await this.driver.query(updateSql, [amount, ...filterParams])).rowCount ?? 0;
|
|
510
|
+
}
|
|
511
|
+
/** Decrement a field for all matching rows. Returns affected row count. */
|
|
512
|
+
async decrementMany(field, amount = 1) {
|
|
513
|
+
return this.incrementMany(field, -amount);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Process results in memory-efficient chunks.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* await User.query().chunk(100, async (rows, idx) => { ... })
|
|
520
|
+
*/
|
|
521
|
+
async chunk(size, callback) {
|
|
522
|
+
let chunkIndex = 0;
|
|
523
|
+
let hasMore = true;
|
|
524
|
+
while (hasMore) {
|
|
525
|
+
const chunk = await this.clone().skip(chunkIndex * size).limit(size).get();
|
|
526
|
+
if (chunk.length === 0) break;
|
|
527
|
+
if (await callback(chunk, chunkIndex) === false) break;
|
|
528
|
+
hasMore = chunk.length === size;
|
|
529
|
+
chunkIndex++;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/** Page-based pagination. */
|
|
533
|
+
async paginate(options) {
|
|
534
|
+
const page = options?.page ?? 1;
|
|
535
|
+
const limit = options?.limit ?? 10;
|
|
536
|
+
const skip = (page - 1) * limit;
|
|
537
|
+
const [data, total] = await Promise.all([this.clone().skip(skip).limit(limit).get(), this.count()]);
|
|
538
|
+
return {
|
|
539
|
+
data,
|
|
540
|
+
pagination: {
|
|
541
|
+
total,
|
|
542
|
+
page,
|
|
543
|
+
limit,
|
|
544
|
+
pages: Math.ceil(total / limit)
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Set cursor pagination hints fluently.
|
|
550
|
+
* The recorded values are picked up by `cursorPaginate()` when no explicit
|
|
551
|
+
* options are passed.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* User.query().cursor(lastId).cursorPaginate({ limit: 20 })
|
|
555
|
+
*/
|
|
556
|
+
cursor(after, before) {
|
|
557
|
+
this.addOperation("cursor", {
|
|
558
|
+
after,
|
|
559
|
+
before
|
|
560
|
+
});
|
|
561
|
+
return this;
|
|
562
|
+
}
|
|
563
|
+
/** Cursor-based pagination. */
|
|
564
|
+
async cursorPaginate(options) {
|
|
565
|
+
const recordedCursor = this.getOps("cursor")[0]?.data.after;
|
|
566
|
+
const { limit = 10, cursor = recordedCursor, column = "id", direction = "next" } = options ?? {};
|
|
567
|
+
if (cursor) this.where(column, direction === "next" ? ">" : "<", cursor);
|
|
568
|
+
this.orderBy(column, direction === "next" ? "asc" : "desc");
|
|
569
|
+
const results = await this.limit(limit + 1).get();
|
|
570
|
+
const hasMore = results.length > limit;
|
|
571
|
+
let data = hasMore ? results.slice(0, limit) : results;
|
|
572
|
+
if (direction === "prev") data = data.reverse();
|
|
573
|
+
let nextCursor;
|
|
574
|
+
let prevCursor;
|
|
575
|
+
let hasPrev = false;
|
|
576
|
+
if (data.length > 0) {
|
|
577
|
+
const firstItem = data[0][column];
|
|
578
|
+
const lastItem = data[data.length - 1][column];
|
|
579
|
+
if (direction === "next") {
|
|
580
|
+
nextCursor = hasMore ? lastItem : void 0;
|
|
581
|
+
if (cursor) {
|
|
582
|
+
hasPrev = true;
|
|
583
|
+
prevCursor = firstItem;
|
|
584
|
+
}
|
|
585
|
+
} else {
|
|
586
|
+
prevCursor = hasMore ? firstItem : void 0;
|
|
587
|
+
hasPrev = hasMore;
|
|
588
|
+
if (cursor) nextCursor = lastItem;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return {
|
|
592
|
+
data,
|
|
593
|
+
pagination: {
|
|
594
|
+
hasMore,
|
|
595
|
+
hasPrev,
|
|
596
|
+
nextCursor,
|
|
597
|
+
prevCursor
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
/** Delete matching rows. Returns deleted count. */
|
|
602
|
+
async delete() {
|
|
603
|
+
this.applyPendingScopes();
|
|
604
|
+
const { sql, params } = this.buildFilter();
|
|
605
|
+
const deleteSql = `DELETE FROM ${this.driver.dialect.quoteIdentifier(this.table)} ${sql}`;
|
|
606
|
+
return (await this.driver.query(deleteSql, params)).rowCount ?? 0;
|
|
607
|
+
}
|
|
608
|
+
/** Delete the first matching row. */
|
|
609
|
+
async deleteOne() {
|
|
610
|
+
return this.limit(1).delete();
|
|
611
|
+
}
|
|
612
|
+
/** Update matching rows. */
|
|
613
|
+
async update(fields) {
|
|
614
|
+
this.applyPendingScopes();
|
|
615
|
+
return (await this.driver.updateMany(this.table, {}, { $set: fields })).modifiedCount;
|
|
616
|
+
}
|
|
617
|
+
/** Unset fields from matching rows. */
|
|
618
|
+
async unset(...fields) {
|
|
619
|
+
this.applyPendingScopes();
|
|
620
|
+
const updateObj = {};
|
|
621
|
+
for (const field of fields) updateObj[field] = 1;
|
|
622
|
+
return (await this.driver.updateMany(this.table, {}, { $unset: updateObj })).modifiedCount;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Return the SQL + bindings without executing.
|
|
626
|
+
*
|
|
627
|
+
* Runs the same prelude as `get()` (scopes, joinWith expansion, joinRelations,
|
|
628
|
+
* countRelations) so the preview matches what would actually be sent to the
|
|
629
|
+
* database. The apply* methods are idempotent — calling `parse()` then `get()`
|
|
630
|
+
* does not double-emit operations.
|
|
631
|
+
*/
|
|
632
|
+
parse() {
|
|
633
|
+
this.applyPendingScopes();
|
|
634
|
+
this._processJoinWithOps();
|
|
635
|
+
this.applyJoinRelations();
|
|
636
|
+
this.applyHasRelations();
|
|
637
|
+
this.applyCountRelations();
|
|
638
|
+
this.applyGroupByAggregates();
|
|
639
|
+
return new PostgresQueryParser({
|
|
640
|
+
table: this.table,
|
|
641
|
+
operations: toParserOps(this.operations)
|
|
642
|
+
}).parse();
|
|
643
|
+
}
|
|
644
|
+
/** Formatted SQL string (for logging/debugging). */
|
|
645
|
+
pretty() {
|
|
646
|
+
const { query = "", bindings } = this.parse();
|
|
647
|
+
return `${query}\n-- Bindings: ${JSON.stringify(bindings ?? [])}`;
|
|
648
|
+
}
|
|
649
|
+
/** Run EXPLAIN ANALYZE on the query. */
|
|
650
|
+
async explain() {
|
|
651
|
+
const { query = "", bindings = [] } = this.parse();
|
|
652
|
+
return (await this.driver.query(`EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) ${query}`, bindings)).rows;
|
|
653
|
+
}
|
|
654
|
+
/** Extend the builder with a driver-specific extension. */
|
|
655
|
+
extend(extension, ..._args) {
|
|
656
|
+
throw new Error(`Extension "${extension}" is not supported by PostgresQueryBuilder`);
|
|
657
|
+
}
|
|
658
|
+
/** Pluck scalar values for a single field (alias for pluck). */
|
|
659
|
+
async pluckOne(field) {
|
|
660
|
+
return (await this.select([field]).get()).map((row) => row[field]);
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Before `get()` runs the parser, consume any joinWith ops recorded by the base
|
|
664
|
+
* class and expand them into the joinRelations Map.
|
|
665
|
+
*/
|
|
666
|
+
_processJoinWithOps() {
|
|
667
|
+
const joinWithOps = this.operations.filter((op) => op.type === "joinWith");
|
|
668
|
+
if (joinWithOps.length === 0) return;
|
|
669
|
+
this.operations = this.operations.filter((op) => op.type !== "joinWith");
|
|
670
|
+
for (const op of joinWithOps) {
|
|
671
|
+
const constraints = op.data.constraints;
|
|
672
|
+
for (const [path, constraint] of Object.entries(constraints)) if (!constraint || constraint === "") this.joinWith(path);
|
|
673
|
+
else this.joinWith({ [path]: constraint });
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Translate each entry in `joinRelations` into actual JOIN + selectRelatedColumns operations.
|
|
678
|
+
*
|
|
679
|
+
* Idempotent — guarded by `joinRelationsApplied` so repeat calls (e.g.
|
|
680
|
+
* `parse()` followed by `get()`) don't double-emit operations.
|
|
681
|
+
*/
|
|
682
|
+
applyJoinRelations() {
|
|
683
|
+
if (this.joinRelationsApplied || this.joinRelations.size === 0) return;
|
|
684
|
+
this.joinRelationsApplied = true;
|
|
685
|
+
for (const [path, config] of this.joinRelations) {
|
|
686
|
+
const RelatedModel = tryResolveModelClass(config.model);
|
|
687
|
+
if (!RelatedModel) throw new Error(`Relation model not found for ${path}`);
|
|
688
|
+
const relatedTable = RelatedModel.table;
|
|
689
|
+
const alias = config.alias;
|
|
690
|
+
const parentTable = config.parentPath ? this.joinRelations.get(config.parentPath).alias : this.table;
|
|
691
|
+
const parentModel = config.parentModel;
|
|
692
|
+
const relatedModelMeta = RelatedModel;
|
|
693
|
+
let localField;
|
|
694
|
+
let foreignField;
|
|
695
|
+
const conventions = this.dataSource?.relationDefaults;
|
|
696
|
+
if (config.type === "belongsTo") {
|
|
697
|
+
localField = config.foreignKey ?? inferBelongsToForeignKey(config.relationName ?? "", conventions);
|
|
698
|
+
foreignField = config.ownerKey ?? relatedModelMeta.primaryKey ?? "id";
|
|
699
|
+
} else {
|
|
700
|
+
localField = config.localKey ?? parentModel?.primaryKey ?? "id";
|
|
701
|
+
foreignField = config.foreignKey ?? inferHasForeignKey(parentModel?.name ?? "Model", conventions);
|
|
702
|
+
}
|
|
703
|
+
if (config.type !== "hasMany") this.addOperation("leftJoin", {
|
|
704
|
+
table: relatedTable,
|
|
705
|
+
alias,
|
|
706
|
+
localField: `${parentTable}.${localField}`,
|
|
707
|
+
foreignField,
|
|
708
|
+
constraintOps: config.constraintOps
|
|
709
|
+
});
|
|
710
|
+
this.addOperation("selectRelatedColumns", {
|
|
711
|
+
alias,
|
|
712
|
+
relationName: config.relationName,
|
|
713
|
+
path,
|
|
714
|
+
table: relatedTable,
|
|
715
|
+
select: config.select,
|
|
716
|
+
type: config.type,
|
|
717
|
+
foreignKey: foreignField,
|
|
718
|
+
localKey: localField,
|
|
719
|
+
parentTable,
|
|
720
|
+
constraintOps: config.constraintOps
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Translate every `has` / `whereHas` / `orWhereHas` / `doesntHave` /
|
|
726
|
+
* `whereDoesntHave` operation into an equivalent `whereRaw` (or
|
|
727
|
+
* `orWhereRaw`) carrying an EXISTS / NOT EXISTS / COUNT-comparison
|
|
728
|
+
* subquery. Keeps the parser pure (no schema awareness) — same pattern as
|
|
729
|
+
* `applyJoinRelations` and `applyCountRelations`.
|
|
730
|
+
*
|
|
731
|
+
* In-place rewrite preserves position so the boolean (AND/OR) stays
|
|
732
|
+
* correctly slotted relative to other where conditions.
|
|
733
|
+
*
|
|
734
|
+
* Idempotent — guarded by `hasRelationsApplied` so repeat calls (e.g.
|
|
735
|
+
* `parse()` followed by `get()`) don't double-translate.
|
|
736
|
+
*/
|
|
737
|
+
applyHasRelations() {
|
|
738
|
+
if (this.hasRelationsApplied) return;
|
|
739
|
+
const HAS_OP_TYPES = new Set([
|
|
740
|
+
"has",
|
|
741
|
+
"whereHas",
|
|
742
|
+
"orWhereHas",
|
|
743
|
+
"doesntHave",
|
|
744
|
+
"whereDoesntHave"
|
|
745
|
+
]);
|
|
746
|
+
if (!this.operations.some((op) => HAS_OP_TYPES.has(op.type))) {
|
|
747
|
+
this.hasRelationsApplied = true;
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
this.hasRelationsApplied = true;
|
|
751
|
+
this.operations = this.operations.map((op) => {
|
|
752
|
+
if (!HAS_OP_TYPES.has(op.type)) return op;
|
|
753
|
+
return this.translateHasOp(op);
|
|
754
|
+
});
|
|
755
|
+
this.rebuildIndex();
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Translate one has-family operation into its `whereRaw`/`orWhereRaw`
|
|
759
|
+
* equivalent. Resolves the relation definition, builds the EXISTS or
|
|
760
|
+
* COUNT-comparison subquery, and returns the replacement op.
|
|
761
|
+
*/
|
|
762
|
+
translateHasOp(op) {
|
|
763
|
+
const data = op.data;
|
|
764
|
+
const definition = this.relationDefinitions?.[data.relation];
|
|
765
|
+
if (!definition) {
|
|
766
|
+
const modelName = this.modelClass?.name ?? "unknown";
|
|
767
|
+
throw new Error(`${op.type}: Relation "${data.relation}" not found on model ${modelName}`);
|
|
768
|
+
}
|
|
769
|
+
const RelatedModel = tryResolveModelClass(definition.model);
|
|
770
|
+
if (!RelatedModel || !RelatedModel.table) throw new Error(`${op.type}: Related model not resolvable for "${data.relation}"`);
|
|
771
|
+
const subquery = this.buildHasSubquery(op.type, data.relation, definition, RelatedModel, data.subquery, data.operator, data.count);
|
|
772
|
+
return {
|
|
773
|
+
type: op.type === "orWhereHas" ? "orWhereRaw" : "whereRaw",
|
|
774
|
+
data: {
|
|
775
|
+
expression: subquery.expression,
|
|
776
|
+
bindings: subquery.bindings
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Build the SQL fragment that goes inside a `whereRaw` op for a has-family
|
|
782
|
+
* translation. Branches on relation type AND on the operation type:
|
|
783
|
+
*
|
|
784
|
+
* - `has` with default operator/count → `EXISTS (SELECT 1 FROM ...)`
|
|
785
|
+
* - `has` with custom operator/count → `(SELECT COUNT(*) FROM ...) <op> <count>`
|
|
786
|
+
* - `whereHas` / `orWhereHas` → `EXISTS (SELECT 1 ... AND <constraint>)`
|
|
787
|
+
* - `doesntHave` → `NOT EXISTS (SELECT 1 FROM ...)`
|
|
788
|
+
* - `whereDoesntHave` → `NOT EXISTS (SELECT 1 ... AND <constraint>)`
|
|
789
|
+
*/
|
|
790
|
+
buildHasSubquery(opType, relationName, definition, RelatedModel, constraintOps, operator, count) {
|
|
791
|
+
const dialect = this.driver.dialect;
|
|
792
|
+
const quotedSelfTable = dialect.quoteIdentifier(this.table);
|
|
793
|
+
const quotedRelatedTable = dialect.quoteIdentifier(RelatedModel.table);
|
|
794
|
+
const relationType = definition.type;
|
|
795
|
+
const selfModel = this.modelClass;
|
|
796
|
+
const conventions = this.dataSource?.relationDefaults;
|
|
797
|
+
const where = this.extractCountWhereFragment(RelatedModel.table, constraintOps);
|
|
798
|
+
let fromClause;
|
|
799
|
+
let joinCondition;
|
|
800
|
+
if (relationType === "hasMany" || relationType === "hasOne") {
|
|
801
|
+
const localKey = definition.localKey ?? selfModel?.primaryKey ?? "id";
|
|
802
|
+
const foreignKey = definition.foreignKey ?? inferHasForeignKey(selfModel?.name ?? "Model", conventions);
|
|
803
|
+
fromClause = quotedRelatedTable;
|
|
804
|
+
joinCondition = `${quotedRelatedTable}.${dialect.quoteIdentifier(foreignKey)} = ${quotedSelfTable}.${dialect.quoteIdentifier(localKey)}`;
|
|
805
|
+
} else if (relationType === "belongsTo") {
|
|
806
|
+
const ownerKey = definition.localKey ?? RelatedModel.primaryKey ?? "id";
|
|
807
|
+
const foreignKey = definition.foreignKey ?? inferBelongsToForeignKey(relationName, conventions);
|
|
808
|
+
fromClause = quotedRelatedTable;
|
|
809
|
+
joinCondition = `${quotedRelatedTable}.${dialect.quoteIdentifier(ownerKey)} = ${quotedSelfTable}.${dialect.quoteIdentifier(foreignKey)}`;
|
|
810
|
+
} else if (relationType === "belongsToMany") {
|
|
811
|
+
const pivotTableName = definition.pivot ?? inferPivotTable(selfModel?.name ?? "Model", RelatedModel.name, conventions);
|
|
812
|
+
const quotedPivot = dialect.quoteIdentifier(pivotTableName);
|
|
813
|
+
const pivotLocalCol = definition.localKey ?? inferPivotKey(selfModel?.name ?? "Model", conventions);
|
|
814
|
+
const pivotForeignCol = definition.foreignKey ?? inferPivotKey(RelatedModel.name, conventions);
|
|
815
|
+
const selfPk = definition.pivotLocalKey ?? selfModel?.primaryKey ?? "id";
|
|
816
|
+
const relatedPk = definition.pivotForeignKey ?? RelatedModel.primaryKey ?? "id";
|
|
817
|
+
if (!constraintOps || constraintOps.length === 0) {
|
|
818
|
+
fromClause = quotedPivot;
|
|
819
|
+
joinCondition = `${quotedPivot}.${dialect.quoteIdentifier(pivotLocalCol)} = ${quotedSelfTable}.${dialect.quoteIdentifier(selfPk)}`;
|
|
820
|
+
} else {
|
|
821
|
+
fromClause = `${quotedPivot} INNER JOIN ${quotedRelatedTable} ON ${quotedRelatedTable}.${dialect.quoteIdentifier(relatedPk)} = ${quotedPivot}.${dialect.quoteIdentifier(pivotForeignCol)}`;
|
|
822
|
+
joinCondition = `${quotedPivot}.${dialect.quoteIdentifier(pivotLocalCol)} = ${quotedSelfTable}.${dialect.quoteIdentifier(selfPk)}`;
|
|
823
|
+
}
|
|
824
|
+
} else throw new Error(`${opType}: Unsupported relation type "${relationType}" for "${relationName}"`);
|
|
825
|
+
const fullWhere = where.fragment ? `${joinCondition} AND ${where.fragment}` : joinCondition;
|
|
826
|
+
if (opType === "has" && (operator !== void 0 && operator !== ">=" || (count ?? 1) !== 1)) return {
|
|
827
|
+
expression: `(SELECT COUNT(*) FROM ${fromClause} WHERE ${fullWhere}) ${operator ?? ">="} ${count ?? 1}`,
|
|
828
|
+
bindings: where.bindings
|
|
829
|
+
};
|
|
830
|
+
return {
|
|
831
|
+
expression: `${opType === "doesntHave" || opType === "whereDoesntHave" ? "NOT EXISTS" : "EXISTS"} (SELECT 1 FROM ${fromClause} WHERE ${fullWhere})`,
|
|
832
|
+
bindings: where.bindings
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Translate each entry in `countRelations` into a correlated COUNT subquery
|
|
837
|
+
* emitted as a `selectRaw` operation. Runs after `applyJoinRelations` so the
|
|
838
|
+
* "preserve main table columns" guard sees any joins already in place.
|
|
839
|
+
*
|
|
840
|
+
* Idempotent — guarded by `countRelationsApplied` so repeat calls (e.g.
|
|
841
|
+
* `parse()` followed by `get()`) don't double-emit operations.
|
|
842
|
+
*/
|
|
843
|
+
applyCountRelations() {
|
|
844
|
+
if (this.countRelationsApplied || this.countRelations.size === 0) return;
|
|
845
|
+
this.countRelationsApplied = true;
|
|
846
|
+
this.ensureMainColumnsForCount();
|
|
847
|
+
for (const [alias, entry] of this.countRelations) {
|
|
848
|
+
const definition = this.relationDefinitions?.[entry.relation];
|
|
849
|
+
if (!definition) {
|
|
850
|
+
const modelName = this.modelClass?.name ?? "unknown";
|
|
851
|
+
throw new Error(`withCount: Relation "${entry.relation}" not found on model ${modelName}`);
|
|
852
|
+
}
|
|
853
|
+
const RelatedModel = tryResolveModelClass(definition.model);
|
|
854
|
+
if (!RelatedModel || !RelatedModel.table) throw new Error(`withCount: Related model not resolvable for "${entry.relation}" (alias "${alias}")`);
|
|
855
|
+
const subquery = this.buildCountSubquery(alias, entry.relation, definition, RelatedModel, entry.constraintOps);
|
|
856
|
+
this.addOperation("selectRaw", {
|
|
857
|
+
expression: subquery.expression,
|
|
858
|
+
bindings: subquery.bindings
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Without an explicit `select(...)` or any `selectRaw`/`selectRelatedColumns`
|
|
864
|
+
* already pushed, the parser's "no selects → SELECT *" fallback would be
|
|
865
|
+
* suppressed once we add count expressions. Push `<table>.*` first so the
|
|
866
|
+
* caller's columns survive.
|
|
867
|
+
*/
|
|
868
|
+
ensureMainColumnsForCount() {
|
|
869
|
+
if (this.operations.some((op) => op.type === "select" || op.type === "selectRaw" || op.type === "selectRelatedColumns")) return;
|
|
870
|
+
const quotedTable = this.driver.dialect.quoteIdentifier(this.table);
|
|
871
|
+
this.addOperation("selectRaw", {
|
|
872
|
+
expression: `${quotedTable}.*`,
|
|
873
|
+
bindings: []
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Build a single correlated-subquery expression for a count entry. Branches
|
|
878
|
+
* on relation type (hasMany/hasOne/belongsTo/belongsToMany). The optional
|
|
879
|
+
* constraint callback's where-ops are translated via a sub-parser and
|
|
880
|
+
* spliced into the subquery's WHERE clause.
|
|
881
|
+
*/
|
|
882
|
+
buildCountSubquery(alias, relationName, definition, RelatedModel, constraintOps) {
|
|
883
|
+
const dialect = this.driver.dialect;
|
|
884
|
+
const quotedAlias = dialect.quoteIdentifier(alias);
|
|
885
|
+
const quotedSelfTable = dialect.quoteIdentifier(this.table);
|
|
886
|
+
const quotedRelatedTable = dialect.quoteIdentifier(RelatedModel.table);
|
|
887
|
+
const relationType = definition.type;
|
|
888
|
+
const selfModel = this.modelClass;
|
|
889
|
+
const relatedMeta = RelatedModel;
|
|
890
|
+
const conventions = this.dataSource?.relationDefaults;
|
|
891
|
+
if (relationType === "hasMany" || relationType === "hasOne") {
|
|
892
|
+
const localKey = definition.localKey ?? selfModel?.primaryKey ?? "id";
|
|
893
|
+
const foreignKey = definition.foreignKey ?? inferHasForeignKey(selfModel?.name ?? "Model", conventions);
|
|
894
|
+
const where = this.extractCountWhereFragment(RelatedModel.table, constraintOps);
|
|
895
|
+
const fkCondition = `${quotedRelatedTable}.${dialect.quoteIdentifier(foreignKey)} = ${quotedSelfTable}.${dialect.quoteIdentifier(localKey)}`;
|
|
896
|
+
return {
|
|
897
|
+
expression: `(SELECT COUNT(*) FROM ${quotedRelatedTable} WHERE ${where.fragment ? `${fkCondition} AND ${where.fragment}` : fkCondition})::int AS ${quotedAlias}`,
|
|
898
|
+
bindings: where.bindings
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
if (relationType === "belongsTo") {
|
|
902
|
+
const ownerKey = definition.localKey ?? relatedMeta.primaryKey ?? "id";
|
|
903
|
+
const foreignKey = definition.foreignKey ?? inferBelongsToForeignKey(relationName, conventions);
|
|
904
|
+
const where = this.extractCountWhereFragment(RelatedModel.table, constraintOps);
|
|
905
|
+
const condition = `${quotedRelatedTable}.${dialect.quoteIdentifier(ownerKey)} = ${quotedSelfTable}.${dialect.quoteIdentifier(foreignKey)}`;
|
|
906
|
+
return {
|
|
907
|
+
expression: `(SELECT COUNT(*) FROM ${quotedRelatedTable} WHERE ${where.fragment ? `${condition} AND ${where.fragment}` : condition})::int AS ${quotedAlias}`,
|
|
908
|
+
bindings: where.bindings
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
if (relationType === "belongsToMany") {
|
|
912
|
+
const pivotTableName = definition.pivot ?? inferPivotTable(selfModel?.name ?? "Model", relatedMeta.name, conventions);
|
|
913
|
+
const quotedPivot = dialect.quoteIdentifier(pivotTableName);
|
|
914
|
+
const pivotLocalCol = definition.localKey ?? inferPivotKey(selfModel?.name ?? "Model", conventions);
|
|
915
|
+
const pivotForeignCol = definition.foreignKey ?? inferPivotKey(relatedMeta.name, conventions);
|
|
916
|
+
const selfPk = definition.pivotLocalKey ?? selfModel?.primaryKey ?? "id";
|
|
917
|
+
const relatedPk = definition.pivotForeignKey ?? relatedMeta.primaryKey ?? "id";
|
|
918
|
+
const pivotCondition = `${quotedPivot}.${dialect.quoteIdentifier(pivotLocalCol)} = ${quotedSelfTable}.${dialect.quoteIdentifier(selfPk)}`;
|
|
919
|
+
if (!constraintOps || constraintOps.length === 0) return {
|
|
920
|
+
expression: `(SELECT COUNT(*) FROM ${quotedPivot} WHERE ${pivotCondition})::int AS ${quotedAlias}`,
|
|
921
|
+
bindings: []
|
|
922
|
+
};
|
|
923
|
+
const where = this.extractCountWhereFragment(RelatedModel.table, constraintOps);
|
|
924
|
+
return {
|
|
925
|
+
expression: `(SELECT COUNT(*) FROM ${quotedPivot} ${`INNER JOIN ${quotedRelatedTable} ON ${quotedRelatedTable}.${dialect.quoteIdentifier(relatedPk)} = ${quotedPivot}.${dialect.quoteIdentifier(pivotForeignCol)}`} WHERE ${where.fragment ? `${pivotCondition} AND ${where.fragment}` : pivotCondition})::int AS ${quotedAlias}`,
|
|
926
|
+
bindings: where.bindings
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
throw new Error(`withCount: Unsupported relation type "${relationType}" for "${relationName}"`);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Run a constraint's where-ops through a fresh sub-parser to obtain a SQL
|
|
933
|
+
* WHERE-fragment plus bindings. Strips the leading `WHERE ` and rewrites
|
|
934
|
+
* `$N` placeholders back to `?` so the outer parser renumbers them
|
|
935
|
+
* consistently when it processes the enclosing `selectRaw` operation.
|
|
936
|
+
*
|
|
937
|
+
* Non-where ops (orderBy / limit / etc.) are silently dropped — they have
|
|
938
|
+
* no meaning inside a COUNT subquery.
|
|
939
|
+
*/
|
|
940
|
+
extractCountWhereFragment(relatedTable, constraintOps) {
|
|
941
|
+
if (!constraintOps || constraintOps.length === 0) return {
|
|
942
|
+
fragment: "",
|
|
943
|
+
bindings: []
|
|
944
|
+
};
|
|
945
|
+
const whereOps = constraintOps.filter((op) => op.type.startsWith("where") || op.type.startsWith("orWhere"));
|
|
946
|
+
if (whereOps.length === 0) return {
|
|
947
|
+
fragment: "",
|
|
948
|
+
bindings: []
|
|
949
|
+
};
|
|
950
|
+
const { query = "", bindings = [] } = new PostgresQueryParser({
|
|
951
|
+
table: relatedTable,
|
|
952
|
+
operations: toParserOps(whereOps)
|
|
953
|
+
}).parse();
|
|
954
|
+
const match = query.match(/WHERE\s+(.+)$/);
|
|
955
|
+
if (!match) return {
|
|
956
|
+
fragment: "",
|
|
957
|
+
bindings: []
|
|
958
|
+
};
|
|
959
|
+
return {
|
|
960
|
+
fragment: match[1].replace(/\$\d+/g, "?"),
|
|
961
|
+
bindings: bindings ?? []
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Rewrite every `having` op whose field matches a recorded aggregate alias
|
|
966
|
+
* into a `havingRaw` carrying the underlying SQL expression. PostgreSQL
|
|
967
|
+
* forbids SELECT aliases in HAVING, so `having("revenue", ">", 1000)` on a
|
|
968
|
+
* `groupBy` aggregate would otherwise throw at runtime. A `having` on a
|
|
969
|
+
* grouped column (no alias match) is left untouched. Runs at parse time
|
|
970
|
+
* (not in the `groupBy` override) so it is independent of fluent call order.
|
|
971
|
+
*
|
|
972
|
+
* Idempotent — guarded by `groupByAggregatesApplied` so repeat calls (e.g.
|
|
973
|
+
* `parse()` followed by `get()`) don't double-process.
|
|
974
|
+
*/
|
|
975
|
+
applyGroupByAggregates() {
|
|
976
|
+
if (this.groupByAggregatesApplied) return;
|
|
977
|
+
this.groupByAggregatesApplied = true;
|
|
978
|
+
if (this.aggregateAliases.size === 0) return;
|
|
979
|
+
this.operations = this.operations.map((operation) => {
|
|
980
|
+
if (operation.type !== "having") return operation;
|
|
981
|
+
const field = operation.data.field;
|
|
982
|
+
const sql = this.aggregateAliases.get(field);
|
|
983
|
+
if (!sql) return operation;
|
|
984
|
+
return {
|
|
985
|
+
type: "havingRaw",
|
|
986
|
+
data: {
|
|
987
|
+
expression: `${sql} ${operation.data.operator ?? "="} ?`,
|
|
988
|
+
bindings: [operation.data.value]
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
});
|
|
992
|
+
this.rebuildIndex();
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Run the RelationLoader against the fetched rows for every relation
|
|
996
|
+
* registered via `with()`. Mutates each model instance in place — attaches
|
|
997
|
+
* loaded relations onto `model.loadedRelations` and as direct properties.
|
|
998
|
+
*
|
|
999
|
+
* Lives here (not in `buildQuery`'s `onFetched` callback as it did
|
|
1000
|
+
* historically) so any code path that calls `get()` — including
|
|
1001
|
+
* `Model.newQueryBuilder()` direct instantiation, custom builder subclasses
|
|
1002
|
+
* via `static builder`, or any `eagerLoadRelations`-bearing builder — gets
|
|
1003
|
+
* eager-loading. Previously the loader was only installed when the builder
|
|
1004
|
+
* was constructed via `Model.query()` / `buildQuery`, so bypassing that
|
|
1005
|
+
* factory made `with()` a silent no-op.
|
|
1006
|
+
*
|
|
1007
|
+
* Skipped silently when `modelClass` is absent (raw driver-level
|
|
1008
|
+
* `queryBuilder()` usage has no relations map to consult).
|
|
1009
|
+
*/
|
|
1010
|
+
async applyEagerLoading(records) {
|
|
1011
|
+
if (!this.modelClass || this.eagerLoadRelations.size === 0 || records.length === 0) return;
|
|
1012
|
+
const constraints = {};
|
|
1013
|
+
for (const [name, constraint] of this.eagerLoadRelations) if (typeof constraint === "function") constraints[name] = constraint;
|
|
1014
|
+
await new RelationLoader(records, this.modelClass).load([...this.eagerLoadRelations.keys()], constraints);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Extract per-relation data from raw DB rows (before hydration).
|
|
1018
|
+
* Returns a Map of row index → nested relation data tree.
|
|
1019
|
+
*/
|
|
1020
|
+
extractJoinedRelationData(records) {
|
|
1021
|
+
const result = /* @__PURE__ */ new Map();
|
|
1022
|
+
if (this.joinRelations.size === 0) return result;
|
|
1023
|
+
records.forEach((record, index) => {
|
|
1024
|
+
const relationData = {};
|
|
1025
|
+
const sortedPaths = Array.from(this.joinRelations.keys()).sort((a, b) => a.split(".").length - b.split(".").length);
|
|
1026
|
+
for (const path of sortedPaths) {
|
|
1027
|
+
const columnName = this.joinRelations.get(path).alias;
|
|
1028
|
+
const relatedData = record[columnName];
|
|
1029
|
+
delete record[columnName];
|
|
1030
|
+
const parsedData = relatedData !== null && !(typeof relatedData === "object" && Object.values(relatedData).every((v) => v === null)) ? relatedData : null;
|
|
1031
|
+
const parts = path.split(".");
|
|
1032
|
+
const lastPart = parts.pop();
|
|
1033
|
+
let current = relationData;
|
|
1034
|
+
for (const part of parts) {
|
|
1035
|
+
if (!current[part]) current[part] = {};
|
|
1036
|
+
current = current[part];
|
|
1037
|
+
}
|
|
1038
|
+
current[lastPart] = parsedData;
|
|
1039
|
+
}
|
|
1040
|
+
result.set(index, relationData);
|
|
1041
|
+
});
|
|
1042
|
+
return result;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Attach extracted relation data to hydrated model instances.
|
|
1046
|
+
*/
|
|
1047
|
+
attachJoinedRelations(records, joinedData) {
|
|
1048
|
+
if (this.joinRelations.size === 0) return;
|
|
1049
|
+
const attachNested = (model, dataTree, currentPath = "") => {
|
|
1050
|
+
if (!dataTree || typeof dataTree !== "object") return;
|
|
1051
|
+
for (const [key, data] of Object.entries(dataTree)) {
|
|
1052
|
+
const path = currentPath ? `${currentPath}.${key}` : key;
|
|
1053
|
+
const config = this.joinRelations.get(path);
|
|
1054
|
+
if (!config) continue;
|
|
1055
|
+
if (data === null) {
|
|
1056
|
+
attachLoadedRelation(model, key, null);
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
1059
|
+
const RelatedModel = resolveModelClass(config.model);
|
|
1060
|
+
if (!RelatedModel) continue;
|
|
1061
|
+
const childKeys = Array.from(this.joinRelations.keys()).filter((p) => p.startsWith(`${path}.`)).map((p) => p.split(".")[path.split(".").length]);
|
|
1062
|
+
if (config.type === "hasMany") attachLoadedRelation(model, key, (Array.isArray(data) ? data : []).map((row) => {
|
|
1063
|
+
const rowData = { ...row };
|
|
1064
|
+
for (const childKey of childKeys) delete rowData[childKey];
|
|
1065
|
+
return RelatedModel.hydrate(rowData);
|
|
1066
|
+
}));
|
|
1067
|
+
else {
|
|
1068
|
+
const modelData = { ...data };
|
|
1069
|
+
for (const childKey of childKeys) delete modelData[childKey];
|
|
1070
|
+
const relatedInstance = RelatedModel.hydrate(modelData);
|
|
1071
|
+
attachNested(relatedInstance, data, path);
|
|
1072
|
+
attachLoadedRelation(model, key, relatedInstance);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
records.forEach((model, index) => {
|
|
1077
|
+
const relationData = joinedData.get(index);
|
|
1078
|
+
if (relationData) attachNested(model, relationData);
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Build a WHERE-only SQL fragment from `where*` operations on the current builder.
|
|
1083
|
+
* Used by DELETE / UPDATE / increment paths.
|
|
1084
|
+
*/
|
|
1085
|
+
buildFilter() {
|
|
1086
|
+
const whereOps = this.operations.filter((op) => op.type.includes("where") || op.type.includes("Where"));
|
|
1087
|
+
if (whereOps.length === 0) return {
|
|
1088
|
+
sql: "",
|
|
1089
|
+
params: []
|
|
1090
|
+
};
|
|
1091
|
+
const { query = "", bindings = [] } = new PostgresQueryParser({
|
|
1092
|
+
table: this.table,
|
|
1093
|
+
operations: toParserOps(whereOps)
|
|
1094
|
+
}).parse();
|
|
1095
|
+
const whereMatch = query.match(/WHERE .+$/);
|
|
1096
|
+
return {
|
|
1097
|
+
sql: whereMatch ? whereMatch[0] : "",
|
|
1098
|
+
params: bindings
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
//#endregion
|
|
1104
|
+
export { PostgresQueryBuilder };
|
|
1105
|
+
//# sourceMappingURL=postgres-query-builder.mjs.map
|