ts-prorm-orm 1.1.0 → 1.2.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/CHANGELOG.md +95 -0
- package/README.md +194 -72
- package/dist/audit/history-query.d.ts +35 -0
- package/dist/audit/index.d.ts +16 -0
- package/dist/audit/logger.d.ts +126 -0
- package/dist/cache/cache-manager.d.ts +341 -0
- package/dist/cache/index.d.ts +8 -0
- package/dist/cache/redis-cluster-cache.d.ts +164 -0
- package/dist/cache/redis-cluster-cache.js +19 -36
- package/dist/cli/cloud.d.ts +55 -0
- package/dist/cli/cloud.js +318 -0
- package/dist/cli/commands/auth.d.ts +2 -0
- package/dist/cli/commands/auth.js +345 -0
- package/dist/cli/commands/billing.d.ts +2 -0
- package/dist/cli/commands/billing.js +135 -0
- package/dist/cli/commands/code.d.ts +2 -0
- package/dist/cli/commands/code.js +168 -0
- package/dist/cli/commands/config.d.ts +2 -0
- package/dist/cli/commands/config.js +154 -0
- package/dist/cli/commands/db.d.ts +2 -0
- package/dist/cli/commands/db.js +189 -0
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.js +22 -0
- package/dist/cli/commands/keys.d.ts +2 -0
- package/dist/cli/commands/keys.js +100 -0
- package/dist/cli/commands/misc.d.ts +2 -0
- package/dist/cli/commands/misc.js +282 -0
- package/dist/cli/commands/pull.d.ts +2 -0
- package/dist/cli/commands/pull.js +306 -0
- package/dist/cli/commands/runners.d.ts +2 -0
- package/dist/cli/commands/runners.js +218 -0
- package/dist/cli/commands/scaffold.d.ts +2 -0
- package/dist/cli/commands/scaffold.js +383 -0
- package/dist/cli/commands/secrets.d.ts +2 -0
- package/dist/cli/commands/secrets.js +162 -0
- package/dist/cli/commands/store.d.ts +2 -0
- package/dist/cli/commands/store.js +274 -0
- package/dist/cli/commands/system.d.ts +10 -0
- package/dist/cli/commands/system.js +169 -0
- package/dist/cli/commands/teams.d.ts +2 -0
- package/dist/cli/commands/teams.js +189 -0
- package/dist/cli/commands/user.d.ts +2 -0
- package/dist/cli/commands/user.js +171 -0
- package/dist/cli/framework.d.ts +103 -0
- package/dist/cli/framework.js +436 -0
- package/dist/cli/io.d.ts +26 -0
- package/dist/cli/io.js +181 -0
- package/dist/cli/keychain.d.ts +10 -0
- package/dist/cli/keychain.js +101 -0
- package/dist/cli/prompt.d.ts +20 -0
- package/dist/cli/prompt.js +111 -0
- package/dist/cli.d.ts +214 -0
- package/dist/cli.js +72 -5
- package/dist/compliance/audit-trail.d.ts +66 -0
- package/dist/compliance/backup-verification.d.ts +279 -0
- package/dist/compliance/breach-detector.d.ts +197 -0
- package/dist/compliance/consent-record.d.ts +107 -0
- package/dist/compliance/consent-versioning.d.ts +169 -0
- package/dist/compliance/cross-border-log.d.ts +254 -0
- package/dist/compliance/data-classifier.d.ts +127 -0
- package/dist/compliance/data-lineage.d.ts +268 -0
- package/dist/compliance/data-masker.d.ts +110 -0
- package/dist/compliance/data-portability.d.ts +98 -0
- package/dist/compliance/data-retention.d.ts +108 -0
- package/dist/compliance/dsar-workflow.d.ts +175 -0
- package/dist/compliance/field-encryption.d.ts +84 -0
- package/dist/compliance/immutable-record.d.ts +84 -0
- package/dist/compliance/index.d.ts +93 -0
- package/dist/compliance/privacy-impact-assessment.d.ts +196 -0
- package/dist/compliance/pseudonymization.d.ts +96 -0
- package/dist/compliance/query-firewall.d.ts +661 -0
- package/dist/compliance/rate-limiter.d.ts +203 -0
- package/dist/compliance/right-to-erasure.d.ts +96 -0
- package/dist/compliance/row-level-security.d.ts +152 -0
- package/dist/compliance/security-decorator.d.ts +388 -0
- package/dist/compliance/security-monitor.d.ts +170 -0
- package/dist/compliance/sensitive-data-discovery.d.ts +151 -0
- package/dist/compliance/session-isolation.d.ts +286 -0
- package/dist/compliance/tls-enforcer.d.ts +51 -0
- package/dist/compliance/worm-storage.d.ts +225 -0
- package/dist/connection-manager.d.ts +130 -0
- package/dist/connection-pool.d.ts +311 -0
- package/dist/decorators/audit.d.ts +49 -0
- package/dist/decorators/check.d.ts +218 -0
- package/dist/decorators/collate.d.ts +346 -0
- package/dist/decorators/comment.d.ts +51 -0
- package/dist/decorators/database-settings.d.ts +193 -0
- package/dist/decorators/default.d.ts +148 -0
- package/dist/decorators/encryption.d.ts +175 -0
- package/dist/decorators/engine.d.ts +97 -0
- package/dist/decorators/fk-constraints.d.ts +387 -0
- package/dist/decorators/foreign-table.d.ts +57 -0
- package/dist/decorators/generated.d.ts +232 -0
- package/dist/decorators/hstore.d.ts +96 -0
- package/dist/decorators/index.d.ts +57 -0
- package/dist/decorators/index.js +14 -30
- package/dist/decorators/json-column.d.ts +47 -0
- package/dist/decorators/jsonb.d.ts +83 -0
- package/dist/decorators/orm-decorators.d.ts +274 -0
- package/dist/decorators/permissions.d.ts +192 -0
- package/dist/decorators/procedure.d.ts +168 -0
- package/dist/decorators/procedure.js +31 -7
- package/dist/decorators/query-options.d.ts +527 -0
- package/dist/decorators/range.d.ts +122 -0
- package/dist/decorators/set-column.d.ts +43 -0
- package/dist/decorators/spatial.d.ts +60 -0
- package/dist/decorators/storage.d.ts +561 -0
- package/dist/decorators/timezone.d.ts +319 -0
- package/dist/decorators/trigger.d.ts +50 -0
- package/dist/decorators/uuid.d.ts +102 -0
- package/dist/decorators/view.d.ts +213 -0
- package/dist/diagrams/chen-diagram.d.ts +70 -0
- package/dist/diagrams/chen-diagram.js +33 -31
- package/dist/diagrams/class-diagram.d.ts +78 -0
- package/dist/diagrams/class-diagram.js +23 -27
- package/dist/diagrams/dependency-diagram.d.ts +82 -0
- package/dist/diagrams/dependency-diagram.js +18 -9
- package/dist/diagrams/er-diagram.d.ts +82 -0
- package/dist/diagrams/er-diagram.js +174 -231
- package/dist/diagrams/flow-diagram.d.ts +70 -0
- package/dist/diagrams/flow-diagram.js +23 -18
- package/dist/diagrams/gantt-diagram.d.ts +67 -0
- package/dist/diagrams/gantt-diagram.js +20 -18
- package/dist/diagrams/index-diagram.d.ts +61 -0
- package/dist/diagrams/index-diagram.js +36 -31
- package/dist/diagrams/index.d.ts +155 -0
- package/dist/diagrams/index.js +7 -1
- package/dist/diagrams/migration-diagram.d.ts +67 -0
- package/dist/diagrams/migration-diagram.js +45 -57
- package/dist/diagrams/model-diagram.d.ts +85 -0
- package/dist/diagrams/model-diagram.js +225 -287
- package/dist/diagrams/package-diagram.d.ts +69 -0
- package/dist/diagrams/package-diagram.js +30 -32
- package/dist/diagrams/palette.d.ts +138 -0
- package/dist/diagrams/palette.js +134 -25
- package/dist/diagrams/relational-diagram.d.ts +82 -0
- package/dist/diagrams/relational-diagram.js +51 -59
- package/dist/diagrams/schemadoc-diagram.d.ts +57 -0
- package/dist/diagrams/schemadoc-diagram.js +36 -28
- package/dist/diagrams/sequence-diagram.d.ts +61 -0
- package/dist/diagrams/sequence-diagram.js +20 -11
- package/dist/diagrams/state-diagram.d.ts +85 -0
- package/dist/diagrams/state-diagram.js +21 -17
- package/dist/diagrams/svg-dom.d.ts +62 -0
- package/dist/diagrams/svg-dom.js +11 -0
- package/dist/diagrams/tree-diagram.d.ts +47 -0
- package/dist/diagrams/tree-diagram.js +19 -10
- package/dist/dialects/clickhouse/index.d.ts +660 -0
- package/dist/dialects/clickhouse/index.js +107 -2
- package/dist/dialects/cockroachdb/index.d.ts +1708 -0
- package/dist/dialects/cockroachdb/index.js +139 -10
- package/dist/dialects/cratedb/index.d.ts +262 -0
- package/dist/dialects/cratedb/index.js +148 -0
- package/dist/dialects/databricks/index.d.ts +397 -0
- package/dist/dialects/databricks/index.js +233 -11
- package/dist/dialects/db2/index.d.ts +729 -0
- package/dist/dialects/db2/index.js +152 -2
- package/dist/dialects/dialect.d.ts +1653 -0
- package/dist/dialects/duckdb/index.d.ts +440 -0
- package/dist/dialects/duckdb/index.js +21 -37
- package/dist/dialects/exasol/index.d.ts +197 -0
- package/dist/dialects/exasol/index.js +14 -0
- package/dist/dialects/firebird/index.d.ts +286 -0
- package/dist/dialects/firebird/index.js +135 -0
- package/dist/dialects/greenplum/index.d.ts +336 -0
- package/dist/dialects/greenplum/index.js +168 -0
- package/dist/dialects/hana/index.d.ts +512 -0
- package/dist/dialects/hana/index.js +17 -35
- package/dist/dialects/mariadb/index.d.ts +1241 -0
- package/dist/dialects/mariadb/index.js +181 -43
- package/dist/dialects/mssql/index.d.ts +729 -0
- package/dist/dialects/mssql/index.js +76 -7
- package/dist/dialects/mysql/index.d.ts +1233 -0
- package/dist/dialects/mysql/index.js +87 -19
- package/dist/dialects/oracle/index.d.ts +1222 -0
- package/dist/dialects/oracle/index.js +210 -9
- package/dist/dialects/postgres/index.d.ts +1598 -0
- package/dist/dialects/postgres/index.js +34 -13
- package/dist/dialects/query-stream-helper.d.ts +58 -0
- package/dist/dialects/questdb/index.d.ts +430 -0
- package/dist/dialects/questdb/index.js +292 -0
- package/dist/dialects/redshift/index.d.ts +933 -0
- package/dist/dialects/redshift/index.js +17 -5
- package/dist/dialects/singlestore/index.d.ts +233 -0
- package/dist/dialects/singlestore/index.js +53 -0
- package/dist/dialects/snowflake/index.d.ts +727 -0
- package/dist/dialects/snowflake/index.js +154 -5
- package/dist/dialects/spanner/index.d.ts +660 -0
- package/dist/dialects/spanner/index.js +43 -21
- package/dist/dialects/sqlite/index.d.ts +1133 -0
- package/dist/dialects/sqlite/index.js +168 -30
- package/dist/dialects/tidb/index.d.ts +226 -0
- package/dist/dialects/tidb/index.js +10 -0
- package/dist/dialects/timescaledb/index.d.ts +286 -0
- package/dist/dialects/timescaledb/index.js +179 -0
- package/dist/dialects/trino/index.d.ts +230 -0
- package/dist/dialects/trino/index.js +85 -10
- package/dist/dialects/turso/index.d.ts +98 -0
- package/dist/dialects/turso/index.js +10 -0
- package/dist/dialects/vertica/index.d.ts +321 -0
- package/dist/dialects/vertica/index.js +161 -0
- package/dist/dialects/yugabytedb/index.d.ts +276 -0
- package/dist/dialects/yugabytedb/index.js +121 -0
- package/dist/errors/index.d.ts +378 -0
- package/dist/errors/index.js +29 -1
- package/dist/errors/utils.d.ts +53 -0
- package/dist/errors.d.ts +5 -0
- package/dist/extensions/catalog/cloud-warehouse-features.d.ts +27 -0
- package/dist/extensions/catalog/mssql-features.d.ts +20 -0
- package/dist/extensions/catalog/mysql-mariadb-plugins.d.ts +18 -0
- package/dist/extensions/catalog/oracle-db2-features.d.ts +17 -0
- package/dist/extensions/catalog/postgres-extensions.d.ts +15 -0
- package/dist/extensions/index.d.ts +34 -0
- package/dist/extensions/types.d.ts +43 -0
- package/dist/external-fields/adapters.d.ts +50 -0
- package/dist/external-fields/adapters.js +227 -0
- package/dist/external-fields/decorator.d.ts +77 -0
- package/dist/external-fields/decorator.js +80 -0
- package/dist/external-fields/index.d.ts +10 -0
- package/dist/external-fields/index.js +19 -0
- package/dist/external-fields/runtime.d.ts +39 -0
- package/dist/external-fields/runtime.js +221 -0
- package/dist/foreign-data.d.ts +168 -0
- package/dist/graph/base-graph-dialect.d.ts +250 -0
- package/dist/graph/base-graph-dialect.js +539 -0
- package/dist/graph/dgraph/index.d.ts +65 -0
- package/dist/graph/dgraph/index.js +559 -0
- package/dist/graph/gremlin/index.d.ts +59 -0
- package/dist/graph/gremlin/index.js +378 -0
- package/dist/graph/index.d.ts +60 -0
- package/dist/graph/index.js +67 -0
- package/dist/graph/neo4j/index.d.ts +50 -0
- package/dist/graph/neo4j/index.js +462 -0
- package/dist/graph/types.d.ts +213 -0
- package/dist/graph/types.js +234 -0
- package/dist/hooks/hooks-manager.d.ts +189 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/index.d.ts +713 -0
- package/dist/index.js +36 -4
- package/dist/logging.d.ts +183 -0
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/migration.d.ts +143 -0
- package/dist/migrations/migrator.d.ts +199 -0
- package/dist/migrations/prormmigration.d.ts +131 -0
- package/dist/migrations/query-interface.d.ts +335 -0
- package/dist/migrations/seeder.d.ts +167 -0
- package/dist/models/associations.d.ts +131 -0
- package/dist/models/associations.js +7 -2
- package/dist/models/constraints.d.ts +175 -0
- package/dist/models/data-types.d.ts +1656 -0
- package/dist/models/decorators.d.ts +328 -0
- package/dist/models/decorators.js +61 -82
- package/dist/models/eager-load.d.ts +86 -0
- package/dist/models/eager-load.js +369 -0
- package/dist/models/index.d.ts +13 -0
- package/dist/models/indexes.d.ts +325 -0
- package/dist/models/methods.d.ts +419 -0
- package/dist/models/model-manager.d.ts +76 -0
- package/dist/models/model.d.ts +820 -0
- package/dist/models/model.js +15 -101
- package/dist/models/operators.d.ts +29 -0
- package/dist/models/scopes.d.ts +71 -0
- package/dist/models/typescript-types.d.ts +177 -0
- package/dist/nosql/aerospike/index.d.ts +126 -0
- package/dist/nosql/allegrograph/index.d.ts +86 -0
- package/dist/nosql/arangodb/index.d.ts +285 -0
- package/dist/nosql/arangodb/index.js +274 -2
- package/dist/nosql/arangodb/where.d.ts +38 -0
- package/dist/nosql/arangodb/where.js +94 -0
- package/dist/nosql/azure-blob/index.d.ts +104 -0
- package/dist/nosql/beanstalkd/index.d.ts +88 -0
- package/dist/nosql/beequeue/index.d.ts +99 -0
- package/dist/nosql/bigchaindb/index.d.ts +113 -0
- package/dist/nosql/bigtable/index.d.ts +144 -0
- package/dist/nosql/blazegraph/index.d.ts +88 -0
- package/dist/nosql/bullmq/index.d.ts +83 -0
- package/dist/nosql/cassandra/index.d.ts +119 -0
- package/dist/nosql/chroma/index.d.ts +151 -0
- package/dist/nosql/cloudflare-kv/index.d.ts +120 -0
- package/dist/nosql/coherence/index.d.ts +91 -0
- package/dist/nosql/cosmosdb/index.d.ts +78 -0
- package/dist/nosql/couchbase/index.d.ts +103 -0
- package/dist/nosql/dax/index.d.ts +118 -0
- package/dist/nosql/deno-kv/index.d.ts +109 -0
- package/dist/nosql/dgraph/index.d.ts +80 -0
- package/dist/nosql/doris/index.d.ts +88 -0
- package/dist/nosql/druid/index.d.ts +95 -0
- package/dist/nosql/dynamodb/index.d.ts +643 -0
- package/dist/nosql/dynamodb/index.js +423 -0
- package/dist/nosql/elasticsearch/index.d.ts +239 -0
- package/dist/nosql/etcd/index.d.ts +243 -0
- package/dist/nosql/eventhubs/index.d.ts +89 -0
- package/dist/nosql/eventstore/index.d.ts +102 -0
- package/dist/nosql/faunadb/index.d.ts +141 -0
- package/dist/nosql/faunadb/index.js +329 -0
- package/dist/nosql/firestore/index.d.ts +67 -0
- package/dist/nosql/fluree/index.d.ts +88 -0
- package/dist/nosql/fuseki/index.d.ts +94 -0
- package/dist/nosql/gcs/index.d.ts +62 -0
- package/dist/nosql/gearman/index.d.ts +77 -0
- package/dist/nosql/geode/index.d.ts +93 -0
- package/dist/nosql/graphdb/index.d.ts +86 -0
- package/dist/nosql/graylog/index.d.ts +118 -0
- package/dist/nosql/gridgain/index.d.ts +78 -0
- package/dist/nosql/hazelcast/index.d.ts +73 -0
- package/dist/nosql/hbase/index.d.ts +123 -0
- package/dist/nosql/ignite/index.d.ts +80 -0
- package/dist/nosql/immudb/index.d.ts +131 -0
- package/dist/nosql/index.d.ts +215 -0
- package/dist/nosql/infinispan/index.d.ts +95 -0
- package/dist/nosql/influxdb/flux-compiler.d.ts +23 -0
- package/dist/nosql/influxdb/flux-compiler.js +170 -0
- package/dist/nosql/influxdb/index.d.ts +300 -0
- package/dist/nosql/influxdb/index.js +0 -0
- package/dist/nosql/kafka/index.d.ts +113 -0
- package/dist/nosql/keyspaces/index.d.ts +122 -0
- package/dist/nosql/kinesis/index.d.ts +121 -0
- package/dist/nosql/leveldb/index.d.ts +112 -0
- package/dist/nosql/leveldb/index.js +103 -1
- package/dist/nosql/lmdb/index.d.ts +76 -0
- package/dist/nosql/loki/index.d.ts +126 -0
- package/dist/nosql/marklogic/index.d.ts +76 -0
- package/dist/nosql/materialize/index.d.ts +91 -0
- package/dist/nosql/meilisearch/index.d.ts +76 -0
- package/dist/nosql/memcached/index.d.ts +138 -0
- package/dist/nosql/milvus/index.d.ts +167 -0
- package/dist/nosql/minio/index.d.ts +122 -0
- package/dist/nosql/momento/index.d.ts +99 -0
- package/dist/nosql/mongodb/index.d.ts +265 -0
- package/dist/nosql/mongodb/index.js +139 -0
- package/dist/nosql/mongodb/where.d.ts +8 -0
- package/dist/nosql/mongodb/where.js +181 -0
- package/dist/nosql/nats/index.d.ts +139 -0
- package/dist/nosql/nedb/index.d.ts +79 -0
- package/dist/nosql/neo4j/index.d.ts +217 -0
- package/dist/nosql/neo4j/index.js +26 -14
- package/dist/nosql/neptune/index.d.ts +234 -0
- package/dist/nosql/neptune/index.js +23 -9
- package/dist/nosql/nsq/index.d.ts +93 -0
- package/dist/nosql/opensearch/index.d.ts +97 -0
- package/dist/nosql/orientdb/index.d.ts +72 -0
- package/dist/nosql/papertrail/index.d.ts +120 -0
- package/dist/nosql/pinecone/index.d.ts +148 -0
- package/dist/nosql/pinot/index.d.ts +90 -0
- package/dist/nosql/pouchdb/index.d.ts +95 -0
- package/dist/nosql/prometheus/index.d.ts +112 -0
- package/dist/nosql/provendb/index.d.ts +143 -0
- package/dist/nosql/provendb/index.js +262 -0
- package/dist/nosql/pubsub/index.d.ts +83 -0
- package/dist/nosql/pulsar/index.d.ts +105 -0
- package/dist/nosql/qdrant/index.d.ts +231 -0
- package/dist/nosql/qldb/index.d.ts +182 -0
- package/dist/nosql/qldb/index.js +302 -1
- package/dist/nosql/r2/index.d.ts +160 -0
- package/dist/nosql/rabbitmq/index.d.ts +131 -0
- package/dist/nosql/ravendb/index.d.ts +138 -0
- package/dist/nosql/ravendb/index.js +323 -9
- package/dist/nosql/ravendb/where.d.ts +38 -0
- package/dist/nosql/ravendb/where.js +94 -0
- package/dist/nosql/redis/index.d.ts +267 -0
- package/dist/nosql/redis/index.js +19 -5
- package/dist/nosql/redpanda/index.d.ts +117 -0
- package/dist/nosql/resque/index.d.ts +91 -0
- package/dist/nosql/rethinkdb/index.d.ts +194 -0
- package/dist/nosql/rethinkdb/index.js +290 -0
- package/dist/nosql/rethinkdb/where.d.ts +38 -0
- package/dist/nosql/rethinkdb/where.js +94 -0
- package/dist/nosql/rocksdb/document-layer.d.ts +162 -0
- package/dist/nosql/rocksdb/document-layer.js +338 -0
- package/dist/nosql/rocksdb/index.d.ts +112 -0
- package/dist/nosql/rocksdb/index.js +103 -1
- package/dist/nosql/rocksdb/where-match.d.ts +21 -0
- package/dist/nosql/rocksdb/where-match.js +238 -0
- package/dist/nosql/rockset/index.d.ts +84 -0
- package/dist/nosql/s3/index.d.ts +170 -0
- package/dist/nosql/scylladb/index.d.ts +117 -0
- package/dist/nosql/signoz/index.d.ts +116 -0
- package/dist/nosql/sns/index.d.ts +99 -0
- package/dist/nosql/solr/index.d.ts +129 -0
- package/dist/nosql/splunk/index.d.ts +125 -0
- package/dist/nosql/sqs/index.d.ts +116 -0
- package/dist/nosql/stardog/index.d.ts +86 -0
- package/dist/nosql/starrocks/index.d.ts +89 -0
- package/dist/nosql/store.d.ts +23 -0
- package/dist/nosql/sumologic/index.d.ts +119 -0
- package/dist/nosql/surrealdb/index.d.ts +156 -0
- package/dist/nosql/surrealdb/index.js +174 -1
- package/dist/nosql/surrealdb/query-compiler.d.ts +26 -0
- package/dist/nosql/surrealdb/query-compiler.js +193 -0
- package/dist/nosql/terminusdb/index.d.ts +95 -0
- package/dist/nosql/tigergraph/index.d.ts +314 -0
- package/dist/nosql/typesense/index.d.ts +82 -0
- package/dist/nosql/unqlite/index.d.ts +68 -0
- package/dist/nosql/upstash/index.d.ts +80 -0
- package/dist/nosql/vercel-kv/index.d.ts +82 -0
- package/dist/nosql/victoriametrics/index.d.ts +129 -0
- package/dist/nosql/virtuoso/index.d.ts +87 -0
- package/dist/nosql/weaviate/index.d.ts +196 -0
- package/dist/operators/index.d.ts +7 -0
- package/dist/operators.d.ts +2947 -0
- package/dist/operators.js +46 -1
- package/dist/prisma-migrate/index.d.ts +28 -0
- package/dist/prisma-migrate/migration-generator.d.ts +21 -0
- package/dist/prisma-migrate/model-generator.d.ts +12 -0
- package/dist/prisma-migrate/relations.d.ts +28 -0
- package/dist/prisma-migrate/schema-parser.d.ts +42 -0
- package/dist/prisma-migrate/type-mapper.d.ts +20 -0
- package/dist/prorm.d.ts +2093 -0
- package/dist/prorm.js +721 -302
- package/dist/query-builders/cte-builder.d.ts +104 -0
- package/dist/query-builders/functions/aggregate.d.ts +199 -0
- package/dist/query-builders/functions/conditional.d.ts +195 -0
- package/dist/query-builders/functions/datetime.d.ts +202 -0
- package/dist/query-builders/functions/fulltext.d.ts +220 -0
- package/dist/query-builders/functions/index.d.ts +17 -0
- package/dist/query-builders/functions/json.d.ts +157 -0
- package/dist/query-builders/functions/math.d.ts +215 -0
- package/dist/query-builders/functions/string.d.ts +233 -0
- package/dist/query-builders/functions/window.d.ts +209 -0
- package/dist/query-builders/include-builder.d.ts +85 -0
- package/dist/query-builders/index-expression-builder.d.ts +153 -0
- package/dist/query-builders/index.d.ts +121 -0
- package/dist/query-builders/index.js +10 -0
- package/dist/query-builders/insert-builder.d.ts +62 -0
- package/dist/query-builders/model-helpers.d.ts +28 -0
- package/dist/query-builders/order-limit-builder.d.ts +84 -0
- package/dist/query-builders/sql-compiler.d.ts +562 -0
- package/dist/query-builders/subquery-builder.d.ts +133 -0
- package/dist/query-builders/update-builder.d.ts +71 -0
- package/dist/query-builders/view-builder.d.ts +189 -0
- package/dist/query-builders/where-builder.d.ts +124 -0
- package/dist/query-interface.d.ts +407 -0
- package/dist/query-interface.js +84 -0
- package/dist/query-optimizers/batch-optimizer.d.ts +175 -0
- package/dist/query-optimizers/explain-plans.d.ts +187 -0
- package/dist/query-optimizers/index.d.ts +27 -0
- package/dist/query-optimizers/prepared-statement-cache.d.ts +252 -0
- package/dist/query-optimizers/query-hints.d.ts +201 -0
- package/dist/query-optimizers/query-optimizer.d.ts +162 -0
- package/dist/query-optimizers/slow-query-logger.d.ts +186 -0
- package/dist/replica-manager.d.ts +235 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/migration-generator.d.ts +74 -0
- package/dist/schema/schema-differ.d.ts +114 -0
- package/dist/schema/types.d.ts +246 -0
- package/dist/schema-objects.d.ts +78 -0
- package/dist/schema-objects.js +203 -0
- package/dist/sql-constants.d.ts +240 -0
- package/dist/sqlite-advanced.d.ts +572 -0
- package/dist/streams/index.d.ts +5 -0
- package/dist/streams/transforms.d.ts +120 -0
- package/dist/transaction.d.ts +221 -0
- package/dist/types/index.d.ts +3123 -0
- package/dist/user-management.d.ts +141 -0
- package/dist/utils/date.d.ts +149 -0
- package/dist/utils/index.d.ts +359 -0
- package/dist/utils/string.d.ts +88 -0
- package/dist/validators/index.d.ts +7 -0
- package/dist/validators/validator.d.ts +306 -0
- package/package.json +20 -5
|
@@ -0,0 +1,3123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the Prorm-like ORM
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Referential actions for foreign key constraints (onDelete / onUpdate).
|
|
6
|
+
*
|
|
7
|
+
* This enum is a companion to the existing string-literal unions used for
|
|
8
|
+
* `onDelete`/`onUpdate` fields (e.g. `'CASCADE' | 'RESTRICT' | ...`). Both
|
|
9
|
+
* forms are accepted wherever these fields appear, so existing string
|
|
10
|
+
* literals continue to work unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { ReferentialAction } from 'prorm';
|
|
15
|
+
*
|
|
16
|
+
* User.hasMany(Post, {
|
|
17
|
+
* foreignKey: 'userId',
|
|
18
|
+
* onDelete: ReferentialAction.Cascade,
|
|
19
|
+
* onUpdate: ReferentialAction.Cascade,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Equivalent to the string-literal form:
|
|
23
|
+
* User.hasMany(Post, {
|
|
24
|
+
* foreignKey: 'userId',
|
|
25
|
+
* onDelete: 'CASCADE',
|
|
26
|
+
* onUpdate: 'CASCADE',
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare enum ReferentialAction {
|
|
31
|
+
Cascade = "CASCADE",
|
|
32
|
+
Restrict = "RESTRICT",
|
|
33
|
+
SetNull = "SET NULL",
|
|
34
|
+
NoAction = "NO ACTION",
|
|
35
|
+
SetDefault = "SET DEFAULT"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Minimum log level for Prorm's built-in logger.
|
|
39
|
+
*
|
|
40
|
+
* This enum is a companion to the existing string-literal union used for
|
|
41
|
+
* `loggingLevel` (`'debug' | 'info' | 'warn' | 'error'`). Both forms are
|
|
42
|
+
* accepted wherever this field appears, so existing string literals
|
|
43
|
+
* continue to work unchanged.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { LoggingLevel } from 'prorm';
|
|
48
|
+
*
|
|
49
|
+
* new Prorm({
|
|
50
|
+
* dialect: 'postgres',
|
|
51
|
+
* loggingLevel: LoggingLevel.Warn,
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Equivalent to the string-literal form:
|
|
55
|
+
* new Prorm({
|
|
56
|
+
* dialect: 'postgres',
|
|
57
|
+
* loggingLevel: 'warn',
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare enum LoggingLevel {
|
|
62
|
+
Debug = "debug",
|
|
63
|
+
Info = "info",
|
|
64
|
+
Warn = "warn",
|
|
65
|
+
Error = "error"
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Refresh method for materialized views
|
|
69
|
+
*/
|
|
70
|
+
export type RefreshMethod = 'FAST' | 'COMPLETE' | 'FORCE';
|
|
71
|
+
/**
|
|
72
|
+
* Build mode for materialized views (Oracle)
|
|
73
|
+
*/
|
|
74
|
+
export type BuildMode = 'IMMEDIATE' | 'DEFERRED';
|
|
75
|
+
/**
|
|
76
|
+
* Refresh timing for materialized views (Oracle)
|
|
77
|
+
*/
|
|
78
|
+
export type RefreshOn = 'COMMIT' | 'DEMAND';
|
|
79
|
+
/**
|
|
80
|
+
* Options for refreshing a materialized view
|
|
81
|
+
*/
|
|
82
|
+
export interface RefreshOptions {
|
|
83
|
+
/** If true, uses CONCURRENTLY (requires unique index on the view) - PostgreSQL only */
|
|
84
|
+
concurrently?: boolean;
|
|
85
|
+
/** If true, uses WITH NO DATA (creates view without populating data) */
|
|
86
|
+
withNoData?: boolean;
|
|
87
|
+
/** Schema name for the materialized view */
|
|
88
|
+
schema?: string;
|
|
89
|
+
/** Refresh method: FAST, COMPLETE, or FORCE (Oracle) */
|
|
90
|
+
refresh?: RefreshMethod;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Options for creating a materialized view
|
|
94
|
+
*/
|
|
95
|
+
export interface MaterializedViewOptions {
|
|
96
|
+
/** Name of the materialized view */
|
|
97
|
+
name: string;
|
|
98
|
+
/** The SELECT query that defines the materialized view */
|
|
99
|
+
query: string;
|
|
100
|
+
/** Schema to create the materialized view in (PostgreSQL) */
|
|
101
|
+
schema?: string;
|
|
102
|
+
/** If true, uses CREATE MATERIALIZED VIEW IF NOT EXISTS */
|
|
103
|
+
ifNotExists?: boolean;
|
|
104
|
+
/** If true, uses CREATE OR REPLACE MATERIALIZED VIEW */
|
|
105
|
+
replace?: boolean;
|
|
106
|
+
/** Columns to include in the WITH DATA clause (for initial data load) */
|
|
107
|
+
withData?: boolean;
|
|
108
|
+
/** Unique index name for CONCURRENTLY refresh support */
|
|
109
|
+
uniqueIndex?: string;
|
|
110
|
+
/** Optional comment for the materialized view */
|
|
111
|
+
comment?: string;
|
|
112
|
+
/** Build mode: IMMEDIATE or DEFERRED (Oracle) */
|
|
113
|
+
build?: BuildMode;
|
|
114
|
+
/** Refresh method: FAST, COMPLETE, or FORCE (Oracle) */
|
|
115
|
+
refresh?: RefreshMethod;
|
|
116
|
+
/** Refresh timing: COMMIT or DEMAND (Oracle) */
|
|
117
|
+
on?: RefreshOn;
|
|
118
|
+
/**
|
|
119
|
+
* Ongoing maintenance mode: 'IMMEDIATE' keeps the materialized view in
|
|
120
|
+
* sync automatically on every write to a base table; 'DEFERRED' only
|
|
121
|
+
* updates it when explicitly refreshed (Db2: `REFRESH IMMEDIATE|DEFERRED`).
|
|
122
|
+
* This is independent of `withData`, which only controls whether the view
|
|
123
|
+
* is populated at creation time. Defaults to 'DEFERRED' to avoid the perf
|
|
124
|
+
* cost of continuous auto-maintenance unless explicitly requested.
|
|
125
|
+
*/
|
|
126
|
+
refreshMode?: 'IMMEDIATE' | 'DEFERRED';
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Options for dropping a materialized view
|
|
130
|
+
*/
|
|
131
|
+
export interface DropMaterializedViewOptions {
|
|
132
|
+
/** If true, does not throw error if materialized view does not exist */
|
|
133
|
+
ifExists?: boolean;
|
|
134
|
+
/** If true, also drops dependent materialized views (CASCADE) */
|
|
135
|
+
cascade?: boolean;
|
|
136
|
+
/** Schema name for the materialized view */
|
|
137
|
+
schema?: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Options for creating/dropping a materialized view log (Oracle).
|
|
141
|
+
*
|
|
142
|
+
* A materialized view log is created on a *master table* (not on the
|
|
143
|
+
* materialized view itself) and is a prerequisite for `FAST` (incremental)
|
|
144
|
+
* refresh of any materialized view built on that table - without a log,
|
|
145
|
+
* `REFRESH FAST` fails with ORA-23413 ("table does not have a materialized
|
|
146
|
+
* view log").
|
|
147
|
+
*
|
|
148
|
+
* Oracle syntax:
|
|
149
|
+
* ```sql
|
|
150
|
+
* CREATE MATERIALIZED VIEW LOG ON table_name
|
|
151
|
+
* [WITH [ROWID] [, PRIMARY KEY] [, SEQUENCE] [(col1, col2, ...)] [INCLUDING NEW VALUES]]
|
|
152
|
+
* DROP MATERIALIZED VIEW LOG ON table_name
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export interface MaterializedViewLogOptions {
|
|
156
|
+
/** Schema the master table (and resulting log) belongs to. */
|
|
157
|
+
schema?: string;
|
|
158
|
+
/**
|
|
159
|
+
* Include ROWID in the log (`WITH ROWID`). Required for fast refresh of
|
|
160
|
+
* materialized views without a primary key, or that use ROWID as the
|
|
161
|
+
* join/lookup key.
|
|
162
|
+
*/
|
|
163
|
+
withRowid?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Include the primary key in the log (`WITH PRIMARY KEY`). This is
|
|
166
|
+
* Oracle's own default when neither `withRowid` nor `withPrimaryKey` is
|
|
167
|
+
* specified, so this library defaults to it as well when nothing is set.
|
|
168
|
+
*/
|
|
169
|
+
withPrimaryKey?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Include a SEQUENCE value in the log (`WITH ... SEQUENCE`). Required for
|
|
172
|
+
* fast refresh of materialized views that involve joins or set operators
|
|
173
|
+
* such as UNION.
|
|
174
|
+
*/
|
|
175
|
+
sequence?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Specific filter columns to log in addition to the logging key
|
|
178
|
+
* (`WITH ... (col1, col2, ...)`). Needed for fast refresh of materialized
|
|
179
|
+
* views that aggregate or reference specific columns.
|
|
180
|
+
*/
|
|
181
|
+
columns?: string[];
|
|
182
|
+
/**
|
|
183
|
+
* Log the new values of columns, not just old values (`INCLUDING NEW
|
|
184
|
+
* VALUES`). Required for fast refresh of materialized views containing
|
|
185
|
+
* aggregate functions. Defaults to true since that is the common case for
|
|
186
|
+
* fast-refreshable materialized views.
|
|
187
|
+
*/
|
|
188
|
+
includingNewValues?: boolean;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Options for creating a stored procedure
|
|
192
|
+
*/
|
|
193
|
+
export interface StoredProcedureOptions {
|
|
194
|
+
/** Name of the stored procedure */
|
|
195
|
+
name: string;
|
|
196
|
+
/** Schema where the stored procedure belongs */
|
|
197
|
+
schema?: string;
|
|
198
|
+
/** Input parameters */
|
|
199
|
+
params?: StoredProcedureParam[];
|
|
200
|
+
/** The procedure body (SQL statements) */
|
|
201
|
+
body: string;
|
|
202
|
+
/** Return type (for functions) */
|
|
203
|
+
returnType?: string;
|
|
204
|
+
/** Language (SQL, PL/pgSQL, etc.) */
|
|
205
|
+
language?: string;
|
|
206
|
+
/** If true, uses CREATE OR REPLACE */
|
|
207
|
+
replace?: boolean;
|
|
208
|
+
/** If true, does not throw if already exists */
|
|
209
|
+
ifNotExists?: boolean;
|
|
210
|
+
/** Optional comment */
|
|
211
|
+
comment?: string;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Parameter for stored procedure
|
|
215
|
+
*/
|
|
216
|
+
export interface StoredProcedureParam {
|
|
217
|
+
/** Parameter name (without @ for T-SQL, $1 for PostgreSQL) */
|
|
218
|
+
name: string;
|
|
219
|
+
/** Data type */
|
|
220
|
+
type: string;
|
|
221
|
+
/** Parameter mode */
|
|
222
|
+
mode?: 'IN' | 'OUT' | 'INOUT';
|
|
223
|
+
/** Default value */
|
|
224
|
+
defaultValue?: any;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Options for dropping a stored procedure
|
|
228
|
+
*/
|
|
229
|
+
export interface DropStoredProcedureOptions {
|
|
230
|
+
/** If true, does not throw error if procedure does not exist */
|
|
231
|
+
ifExists?: boolean;
|
|
232
|
+
/** If true, also drops dependent objects (CASCADE) */
|
|
233
|
+
cascade?: boolean;
|
|
234
|
+
/** Schema (for PostgreSQL) */
|
|
235
|
+
schema?: string;
|
|
236
|
+
/**
|
|
237
|
+
* Explicit argument type signature for the procedure (e.g. ['VARCHAR', 'NUMBER']).
|
|
238
|
+
* Required by dialects (e.g. Snowflake) whose DROP PROCEDURE syntax must match the
|
|
239
|
+
* exact argument types the procedure was created with, since procedures are
|
|
240
|
+
* overloadable by signature.
|
|
241
|
+
*/
|
|
242
|
+
paramTypes?: string[];
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Options for executing a stored procedure
|
|
246
|
+
*/
|
|
247
|
+
export interface ExecuteStoredProcedureOptions {
|
|
248
|
+
/** Procedure name */
|
|
249
|
+
procedureName: string;
|
|
250
|
+
/** Schema (for PostgreSQL) */
|
|
251
|
+
schema?: string;
|
|
252
|
+
/** Input parameters */
|
|
253
|
+
params?: Record<string, any>;
|
|
254
|
+
/** Timeout in milliseconds */
|
|
255
|
+
timeout?: number;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Options for creating a user-defined function (UDF).
|
|
259
|
+
*
|
|
260
|
+
* Deliberately shaped to mirror `StoredProcedureOptions` as closely as
|
|
261
|
+
* possible, since `CREATE FUNCTION` and `CREATE PROCEDURE` share almost
|
|
262
|
+
* identical grammar in Postgres-family dialects (CockroachDB, Postgres).
|
|
263
|
+
* The main differences are that a function always has a `returnType` and
|
|
264
|
+
* may declare a `volatility` category, which procedures do not have.
|
|
265
|
+
*/
|
|
266
|
+
export interface FunctionOptions {
|
|
267
|
+
/** Name of the function */
|
|
268
|
+
name: string;
|
|
269
|
+
/** Schema where the function belongs */
|
|
270
|
+
schema?: string;
|
|
271
|
+
/** Input parameters */
|
|
272
|
+
params?: StoredProcedureParam[];
|
|
273
|
+
/** The function body (SQL statements / expression) */
|
|
274
|
+
body: string;
|
|
275
|
+
/** Return type. Required: unlike procedures, functions always return a value. */
|
|
276
|
+
returnType: string;
|
|
277
|
+
/** Language (SQL, plpgsql, etc.). Defaults to 'SQL'. */
|
|
278
|
+
language?: string;
|
|
279
|
+
/**
|
|
280
|
+
* Volatility/optimization category:
|
|
281
|
+
* - `VOLATILE` (default if omitted): may modify the database and/or return
|
|
282
|
+
* different results on successive calls with the same arguments.
|
|
283
|
+
* - `STABLE`: cannot modify the database, and is guaranteed to return the
|
|
284
|
+
* same results given the same arguments within a single statement.
|
|
285
|
+
* - `IMMUTABLE`: cannot modify the database and always returns the same
|
|
286
|
+
* results given the same arguments. Required for use in computed columns.
|
|
287
|
+
*/
|
|
288
|
+
volatility?: 'VOLATILE' | 'STABLE' | 'IMMUTABLE';
|
|
289
|
+
/** If true, uses CREATE OR REPLACE */
|
|
290
|
+
replace?: boolean;
|
|
291
|
+
/** If true, does not throw if already exists */
|
|
292
|
+
ifNotExists?: boolean;
|
|
293
|
+
/** Optional comment */
|
|
294
|
+
comment?: string;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Options for dropping a user-defined function
|
|
298
|
+
*/
|
|
299
|
+
export interface DropFunctionOptions {
|
|
300
|
+
/** If true, does not throw error if function does not exist */
|
|
301
|
+
ifExists?: boolean;
|
|
302
|
+
/** If true, also drops dependent objects (CASCADE) */
|
|
303
|
+
cascade?: boolean;
|
|
304
|
+
/** Schema (for PostgreSQL/CockroachDB) */
|
|
305
|
+
schema?: string;
|
|
306
|
+
/**
|
|
307
|
+
* Explicit argument type signature for the function (e.g. ['INT', 'TEXT']).
|
|
308
|
+
* Required to disambiguate overloaded functions sharing the same name but
|
|
309
|
+
* different argument types.
|
|
310
|
+
*/
|
|
311
|
+
paramTypes?: string[];
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Options for creating a trigger
|
|
315
|
+
*/
|
|
316
|
+
export interface TriggerOptions {
|
|
317
|
+
/** Trigger name */
|
|
318
|
+
name: string;
|
|
319
|
+
/** Table to attach trigger to */
|
|
320
|
+
tableName: string;
|
|
321
|
+
/** Timing: BEFORE, AFTER, or INSTEAD OF */
|
|
322
|
+
timing: 'BEFORE' | 'AFTER' | 'INSTEAD OF';
|
|
323
|
+
/** Events: INSERT, UPDATE, DELETE */
|
|
324
|
+
events: Array<'INSERT' | 'UPDATE' | 'DELETE'>;
|
|
325
|
+
/** Trigger body (SQL statements) */
|
|
326
|
+
body: string;
|
|
327
|
+
/** For each row or for each statement */
|
|
328
|
+
level?: 'ROW' | 'STATEMENT';
|
|
329
|
+
/** Schema (for PostgreSQL) */
|
|
330
|
+
schema?: string;
|
|
331
|
+
/** If true, uses OR REPLACE */
|
|
332
|
+
replace?: boolean;
|
|
333
|
+
/** Constraint name for triggers that fire on constraint */
|
|
334
|
+
constraint?: string;
|
|
335
|
+
/** REFERENCING clause for transition tables (PostgreSQL) */
|
|
336
|
+
referencing?: {
|
|
337
|
+
oldRow?: string;
|
|
338
|
+
newRow?: string;
|
|
339
|
+
};
|
|
340
|
+
/** Optional comment */
|
|
341
|
+
comment?: string;
|
|
342
|
+
/** WHEN clause for conditional triggers (Oracle, PostgreSQL) */
|
|
343
|
+
when?: string;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Options for dropping a trigger
|
|
347
|
+
*/
|
|
348
|
+
export interface DropTriggerOptions {
|
|
349
|
+
/** If true, does not throw error if trigger does not exist */
|
|
350
|
+
ifExists?: boolean;
|
|
351
|
+
/** If true, also drops dependent objects (CASCADE) */
|
|
352
|
+
cascade?: boolean;
|
|
353
|
+
/** Schema (for PostgreSQL) */
|
|
354
|
+
schema?: string;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Schedule options for MySQL events (AT timestamp or EVERY interval)
|
|
358
|
+
*/
|
|
359
|
+
export interface EventSchedule {
|
|
360
|
+
/** Schedule type: AT a specific timestamp or EVERY interval */
|
|
361
|
+
type: 'AT' | 'EVERY';
|
|
362
|
+
/** Timestamp for AT schedule (YYYY-MM-DD HH:MM:SS) */
|
|
363
|
+
timestamp?: string;
|
|
364
|
+
/** Interval value (e.g., 1, 2, 3) */
|
|
365
|
+
intervalValue?: number;
|
|
366
|
+
/** Interval unit (SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR) */
|
|
367
|
+
intervalUnit?: 'SECOND' | 'MINUTE' | 'HOUR' | 'DAY' | 'WEEK' | 'MONTH' | 'YEAR';
|
|
368
|
+
/** STARTS clause - when to start */
|
|
369
|
+
starts?: string;
|
|
370
|
+
/** ENDS clause - when to end */
|
|
371
|
+
ends?: string;
|
|
372
|
+
/** ON SCHEDULE PRESERVE - keeps event after execution */
|
|
373
|
+
preserve?: boolean;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Options for creating an event
|
|
377
|
+
*/
|
|
378
|
+
export interface CreateEventOptions {
|
|
379
|
+
/** Event name */
|
|
380
|
+
name: string;
|
|
381
|
+
/** Schedule (AT timestamp or EVERY interval) */
|
|
382
|
+
schedule: EventSchedule;
|
|
383
|
+
/** Event body (SQL statements) */
|
|
384
|
+
body: string;
|
|
385
|
+
/** Schema (for MySQL database) */
|
|
386
|
+
schema?: string;
|
|
387
|
+
/** If true, uses CREATE EVENT IF NOT EXISTS */
|
|
388
|
+
ifNotExists?: boolean;
|
|
389
|
+
/** If true, uses OR REPLACE */
|
|
390
|
+
replace?: boolean;
|
|
391
|
+
/** Comment */
|
|
392
|
+
comment?: string;
|
|
393
|
+
/** Enable or disable the event (ENABLED/DISABLED) */
|
|
394
|
+
status?: 'ENABLED' | 'DISABLED';
|
|
395
|
+
/** ON COMPLETION PRESERVE (default) or ON COMPLETION DROP */
|
|
396
|
+
onCompletion?: 'PRESERVE' | 'DROP';
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Options for dropping an event
|
|
400
|
+
*/
|
|
401
|
+
export interface DropEventOptions {
|
|
402
|
+
/** If true, does not throw error if event does not exist */
|
|
403
|
+
ifExists?: boolean;
|
|
404
|
+
/** Schema (for MySQL database) */
|
|
405
|
+
schema?: string;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Options for altering an event
|
|
409
|
+
*/
|
|
410
|
+
export interface AlterEventOptions {
|
|
411
|
+
/** Event name */
|
|
412
|
+
name: string;
|
|
413
|
+
/** New schedule */
|
|
414
|
+
schedule?: EventSchedule;
|
|
415
|
+
/** New body */
|
|
416
|
+
body?: string;
|
|
417
|
+
/** Schema (for MySQL database) */
|
|
418
|
+
schema?: string;
|
|
419
|
+
/** Enable or disable the event */
|
|
420
|
+
status?: 'ENABLED' | 'DISABLED';
|
|
421
|
+
/** Comment */
|
|
422
|
+
comment?: string;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Enhanced stored procedure options with full PL/SQL support
|
|
426
|
+
*/
|
|
427
|
+
export interface CreateProcedureOptions {
|
|
428
|
+
/** Procedure name */
|
|
429
|
+
name: string;
|
|
430
|
+
/** Schema where the procedure belongs */
|
|
431
|
+
schema?: string;
|
|
432
|
+
/** Parameters */
|
|
433
|
+
params?: StoredProcedureParam[];
|
|
434
|
+
/** Procedure body (SQL statements) */
|
|
435
|
+
body: string;
|
|
436
|
+
/** If true, drops existing procedure first */
|
|
437
|
+
replace?: boolean;
|
|
438
|
+
/** If true, does not throw if already exists */
|
|
439
|
+
ifNotExists?: boolean;
|
|
440
|
+
/** Optional comment */
|
|
441
|
+
comment?: string;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Options for creating a sequence
|
|
445
|
+
*/
|
|
446
|
+
export interface SequenceOptions {
|
|
447
|
+
/** Sequence name */
|
|
448
|
+
name: string;
|
|
449
|
+
/** Schema (for PostgreSQL) */
|
|
450
|
+
schema?: string;
|
|
451
|
+
/** Starting value */
|
|
452
|
+
startWith?: number;
|
|
453
|
+
/** Minimum value */
|
|
454
|
+
minvalue?: number;
|
|
455
|
+
/** Maximum value */
|
|
456
|
+
maxvalue?: number;
|
|
457
|
+
/** Increment value */
|
|
458
|
+
incrementBy?: number;
|
|
459
|
+
/** Whether sequence cycles */
|
|
460
|
+
cycle?: boolean;
|
|
461
|
+
/** Cache size */
|
|
462
|
+
cache?: number;
|
|
463
|
+
/** If true, uses CREATE SEQUENCE IF NOT EXISTS */
|
|
464
|
+
ifNotExists?: boolean;
|
|
465
|
+
/** If true, uses CREATE OR REPLACE */
|
|
466
|
+
replace?: boolean;
|
|
467
|
+
/** Temporary sequence (exists only for session) */
|
|
468
|
+
temporary?: boolean;
|
|
469
|
+
/** Owned by a column */
|
|
470
|
+
ownedBy?: string;
|
|
471
|
+
/** Force ordering (Oracle) */
|
|
472
|
+
order?: boolean;
|
|
473
|
+
/** No cache (Oracle) */
|
|
474
|
+
nocache?: boolean;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Options for dropping a sequence
|
|
478
|
+
*/
|
|
479
|
+
export interface DropSequenceOptions {
|
|
480
|
+
/** If true, does not throw error if sequence does not exist */
|
|
481
|
+
ifExists?: boolean;
|
|
482
|
+
/** If true, also drops dependent objects (CASCADE) */
|
|
483
|
+
cascade?: boolean;
|
|
484
|
+
/** Schema (for PostgreSQL) */
|
|
485
|
+
schema?: string;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Options for creating a policy (PostgreSQL RLS)
|
|
489
|
+
*/
|
|
490
|
+
export interface PolicyOptions {
|
|
491
|
+
/** Policy name */
|
|
492
|
+
name: string;
|
|
493
|
+
/** Table name */
|
|
494
|
+
tableName: string;
|
|
495
|
+
/** If true, creates a permissive policy (combines with OR); if false, creates a restrictive policy (combines with AND) */
|
|
496
|
+
permissive?: boolean;
|
|
497
|
+
/** Command the policy applies to (defaults to ALL) */
|
|
498
|
+
command?: 'ALL' | 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE';
|
|
499
|
+
/** Roles to apply the policy to */
|
|
500
|
+
roles?: string[];
|
|
501
|
+
/** CHECK expression for INSERT/UPDATE */
|
|
502
|
+
withCheck?: string;
|
|
503
|
+
/** USING expression for SELECT */
|
|
504
|
+
using?: string;
|
|
505
|
+
/** Schema (for PostgreSQL) */
|
|
506
|
+
schema?: string;
|
|
507
|
+
/** MSSQL: Predicate function (e.g., 'dbo.fn_SecurityPredicate') */
|
|
508
|
+
predicateFunction?: string;
|
|
509
|
+
/** MSSQL: Column to pass to predicate function */
|
|
510
|
+
column?: string;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Options for dropping a policy
|
|
514
|
+
*/
|
|
515
|
+
export interface DropPolicyOptions {
|
|
516
|
+
/** If true, does not throw error if policy does not exist */
|
|
517
|
+
ifExists?: boolean;
|
|
518
|
+
/** If true, also drops dependent objects (CASCADE) */
|
|
519
|
+
cascade?: boolean;
|
|
520
|
+
/** Schema (for PostgreSQL) */
|
|
521
|
+
schema?: string;
|
|
522
|
+
}
|
|
523
|
+
export type Dialect = 'mysql' | 'postgres' | 'sqlite' | 'mssql' | 'mariadb' | 'oracle' | 'cockroachdb' | 'redshift' | 'db2' | 'snowflake' | 'clickhouse' | 'duckdb' | 'hana' | 'spanner' | 'turso' | 'tidb' | 'singlestore' | 'yugabytedb' | 'timescaledb' | 'greenplum' | 'vertica' | 'trino' | 'exasol' | 'questdb' | 'cratedb' | 'firebird' | 'databricks';
|
|
524
|
+
/**
|
|
525
|
+
* Query event data emitted when a query is executed
|
|
526
|
+
*/
|
|
527
|
+
export interface QueryEvent {
|
|
528
|
+
/** The SQL query that was executed */
|
|
529
|
+
sql: string;
|
|
530
|
+
/** Query execution duration in milliseconds */
|
|
531
|
+
duration: number;
|
|
532
|
+
/** Timestamp when the query was executed */
|
|
533
|
+
timestamp: Date;
|
|
534
|
+
/** Query type (SELECT, INSERT, UPDATE, DELETE, etc.) */
|
|
535
|
+
type?: string;
|
|
536
|
+
/** Model name if query was executed via model method */
|
|
537
|
+
model?: string;
|
|
538
|
+
/** Whether the query resulted in an error */
|
|
539
|
+
error?: boolean;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Slow query event data emitted when a query exceeds the threshold
|
|
543
|
+
*/
|
|
544
|
+
export interface SlowQueryEvent extends QueryEvent {
|
|
545
|
+
/** The threshold in milliseconds that was exceeded */
|
|
546
|
+
threshold: number;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Event listener types for Prorm events
|
|
550
|
+
*/
|
|
551
|
+
export interface PrormEvents {
|
|
552
|
+
/** Fired before a query is executed */
|
|
553
|
+
beforeQuery: (event: QueryEvent) => void;
|
|
554
|
+
/** Fired after a query is executed */
|
|
555
|
+
query: (event: QueryEvent) => void;
|
|
556
|
+
/** Fired when a query exceeds the slow query threshold */
|
|
557
|
+
slowQuery: (event: SlowQueryEvent) => void;
|
|
558
|
+
/** Fired when a connection is acquired from the pool */
|
|
559
|
+
acquire: (connection: any) => void;
|
|
560
|
+
/** Fired when a connection is released back to the pool */
|
|
561
|
+
release: (connection: any) => void;
|
|
562
|
+
/** Fired when there's a pool error */
|
|
563
|
+
pool: (error: Error) => void;
|
|
564
|
+
/** Fired when there's an error */
|
|
565
|
+
error: (error: Error) => void;
|
|
566
|
+
}
|
|
567
|
+
export interface PrormOptions {
|
|
568
|
+
dialect: Dialect;
|
|
569
|
+
database?: string;
|
|
570
|
+
username?: string;
|
|
571
|
+
password?: string;
|
|
572
|
+
host?: string;
|
|
573
|
+
port?: number;
|
|
574
|
+
storage?: string;
|
|
575
|
+
logging?: boolean | ((sql: string, timing?: number) => void);
|
|
576
|
+
loggingLevel?: LoggingLevel | 'debug' | 'info' | 'warn' | 'error';
|
|
577
|
+
logSQL?: boolean;
|
|
578
|
+
logSlowQueries?: boolean;
|
|
579
|
+
slowQueryThreshold?: number;
|
|
580
|
+
colors?: boolean;
|
|
581
|
+
pool?: PoolOptions;
|
|
582
|
+
/** Connection pool settings */
|
|
583
|
+
retry?: RetryOptions;
|
|
584
|
+
/** Connection timeout in milliseconds */
|
|
585
|
+
connectTimeout?: number;
|
|
586
|
+
/** Idle timeout in milliseconds */
|
|
587
|
+
idleTimeout?: number;
|
|
588
|
+
timezone?: string;
|
|
589
|
+
/** Keep the database's default timezone instead of converting to UTC */
|
|
590
|
+
keepDefaultTimezone?: boolean;
|
|
591
|
+
/** Additional options to pass to the database driver (e.g., SSL config) */
|
|
592
|
+
dialectOptions?: Record<string, any>;
|
|
593
|
+
transactionType?: string;
|
|
594
|
+
isolationLevel?: string;
|
|
595
|
+
raw?: boolean;
|
|
596
|
+
migrationModule?: string | any;
|
|
597
|
+
migrationStorage?: 'prorm' | 'table' | 'none';
|
|
598
|
+
migrationStorageTableName?: string;
|
|
599
|
+
migrationStorageTableSchema?: string;
|
|
600
|
+
migrationsPath?: string;
|
|
601
|
+
/** Schema to use for database operations (PostgreSQL) */
|
|
602
|
+
schema?: string;
|
|
603
|
+
/** Search path for query resolution (PostgreSQL) */
|
|
604
|
+
searchPath?: string | string[];
|
|
605
|
+
/** Additional named connections for cross-database queries */
|
|
606
|
+
connections?: NamedConnectionOptions[];
|
|
607
|
+
/** Name of the default connection to use */
|
|
608
|
+
defaultConnection?: string;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Named connection options for adding a new database connection
|
|
612
|
+
*/
|
|
613
|
+
export interface NamedConnectionOptions {
|
|
614
|
+
/** Unique name to identify this connection */
|
|
615
|
+
name: string;
|
|
616
|
+
/** Prorm options for the connection */
|
|
617
|
+
options: Omit<PrormOptions, 'connections' | 'defaultConnection'>;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Query event data emitted when a query is executed
|
|
621
|
+
*/
|
|
622
|
+
export interface QueryEvent {
|
|
623
|
+
/** The SQL query that was executed */
|
|
624
|
+
sql: string;
|
|
625
|
+
/** Query execution time in milliseconds */
|
|
626
|
+
duration: number;
|
|
627
|
+
/** Timestamp when the query was executed */
|
|
628
|
+
timestamp: Date;
|
|
629
|
+
/** Query type (SELECT, INSERT, UPDATE, etc.) */
|
|
630
|
+
type?: string;
|
|
631
|
+
/** Model name if this was a model query */
|
|
632
|
+
model?: string;
|
|
633
|
+
/** Whether the query threw an error */
|
|
634
|
+
error?: boolean;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Slow query event data emitted when a query exceeds the threshold
|
|
638
|
+
*/
|
|
639
|
+
export interface SlowQueryEvent extends QueryEvent {
|
|
640
|
+
/** The threshold that was exceeded (in ms) */
|
|
641
|
+
threshold: number;
|
|
642
|
+
}
|
|
643
|
+
export interface PoolOptions {
|
|
644
|
+
/** Maximum number of connections in the pool */
|
|
645
|
+
max?: number;
|
|
646
|
+
/** Minimum number of idle connections to maintain */
|
|
647
|
+
min?: number;
|
|
648
|
+
/** Maximum time in milliseconds to wait for a connection to become available */
|
|
649
|
+
acquire?: number;
|
|
650
|
+
/** Maximum time in milliseconds that a connection can be idle before being evicted */
|
|
651
|
+
idle?: number;
|
|
652
|
+
/** Interval in milliseconds to check for idle connections to evict */
|
|
653
|
+
evict?: number;
|
|
654
|
+
/** Whether to automatically handle disconnects */
|
|
655
|
+
handleDisconnects?: boolean;
|
|
656
|
+
/** Callback when a connection is acquired from the pool */
|
|
657
|
+
onConnect?: (connection: any) => void;
|
|
658
|
+
/** Callback when a connection is released back to the pool */
|
|
659
|
+
onDisconnect?: (connection: any) => void;
|
|
660
|
+
/** Enable pool event emission (for monitoring/debugging) */
|
|
661
|
+
enableEvents?: boolean;
|
|
662
|
+
/** Log pool operations (acquire, release, etc.) */
|
|
663
|
+
logPoolOperations?: boolean;
|
|
664
|
+
}
|
|
665
|
+
export interface RetryOptions {
|
|
666
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
667
|
+
max?: number;
|
|
668
|
+
/** Timeout in milliseconds between retries (default: 1000) */
|
|
669
|
+
timeout?: number;
|
|
670
|
+
/** Array of error message patterns to retry on (default: common connection errors) */
|
|
671
|
+
match?: string[];
|
|
672
|
+
/** Enable exponential backoff for retries (default: false) */
|
|
673
|
+
backoff?: boolean;
|
|
674
|
+
/** Multiplier for exponential backoff (default: 2) */
|
|
675
|
+
backoffMultiplier?: number;
|
|
676
|
+
/** Maximum backoff time in ms (default: 10000) */
|
|
677
|
+
backoffMax?: number;
|
|
678
|
+
}
|
|
679
|
+
export interface ModelOptions {
|
|
680
|
+
tableName?: string;
|
|
681
|
+
/** Schema to use for this model (PostgreSQL) or database (MySQL) */
|
|
682
|
+
schema?: string;
|
|
683
|
+
/** Schema delimiter for table name generation (default: '.') */
|
|
684
|
+
schemaDelimiter?: string;
|
|
685
|
+
timestamps?: boolean;
|
|
686
|
+
createdAt?: string | false;
|
|
687
|
+
updatedAt?: string | false;
|
|
688
|
+
deletedAt?: string | false;
|
|
689
|
+
paranoid?: boolean;
|
|
690
|
+
preserveDeletedAt?: boolean;
|
|
691
|
+
underscored?: boolean;
|
|
692
|
+
freezeTableName?: boolean;
|
|
693
|
+
hooks?: ModelHooks;
|
|
694
|
+
scopes?: Record<string, ScopeOptions>;
|
|
695
|
+
defaultScope?: ScopeOptions;
|
|
696
|
+
validate?: ModelValidationOptions;
|
|
697
|
+
/** Primary key field(s) - supports both single field (string) and composite keys (string[]) */
|
|
698
|
+
primaryKey?: string | string[];
|
|
699
|
+
indexes?: IndexOptions[];
|
|
700
|
+
constraints?: ConstraintOptions[];
|
|
701
|
+
classMethods?: Record<string, Function>;
|
|
702
|
+
instanceMethods?: Record<string, Function>;
|
|
703
|
+
hidden?: Record<string, boolean>;
|
|
704
|
+
virtualFields?: boolean;
|
|
705
|
+
/** MySQL/MariaDB storage engine (e.g., 'InnoDB', 'MyISAM') */
|
|
706
|
+
engine?: string;
|
|
707
|
+
/** Character set for the table (e.g., 'utf8mb4') */
|
|
708
|
+
charset?: string;
|
|
709
|
+
/** Collation for the table (e.g., 'utf8mb4_unicode_ci') */
|
|
710
|
+
collate?: string;
|
|
711
|
+
/** Comment for the table */
|
|
712
|
+
comment?: string;
|
|
713
|
+
/** Initial auto-increment value for the table */
|
|
714
|
+
initialAutoIncrement?: number;
|
|
715
|
+
/** Row format for MySQL/MariaDB (e.g., 'DYNAMIC', 'FIXED', 'COMPRESSED') */
|
|
716
|
+
rowFormat?: string;
|
|
717
|
+
/** Unique keys to create with the table - supports both simple and composite keys */
|
|
718
|
+
uniqueKeys?: UniqueKeyOptions[];
|
|
719
|
+
/** Legacy unique keys format (deprecated - use UniqueKeyOptions instead) */
|
|
720
|
+
uniqueKeysLegacy?: Record<string, string[]>;
|
|
721
|
+
/** PostgreSQL tablespace */
|
|
722
|
+
tablespace?: string;
|
|
723
|
+
/** PostgreSQL: inherit from parent table */
|
|
724
|
+
inherit?: string;
|
|
725
|
+
/** PostgreSQL: partition by clause */
|
|
726
|
+
partitionBy?: string;
|
|
727
|
+
/** Validate on create (default: true) */
|
|
728
|
+
validateOnInsert?: boolean;
|
|
729
|
+
/** Validate on update (default: true) */
|
|
730
|
+
validateOnUpdate?: boolean;
|
|
731
|
+
/** Skip validations (default: false) */
|
|
732
|
+
skipValidations?: boolean;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Sort direction for index column ordering.
|
|
736
|
+
*
|
|
737
|
+
* Companion enum for the `'ASC' | 'DESC'` string-literal union used by
|
|
738
|
+
* {@link IndexField.order}. Raw string literals remain valid; the enum is an
|
|
739
|
+
* additive, opt-in alternative.
|
|
740
|
+
*
|
|
741
|
+
* @example
|
|
742
|
+
* ```typescript
|
|
743
|
+
* // Using raw string literals (still supported)
|
|
744
|
+
* indexes: [{ fields: [{ name: 'email', order: 'DESC' }] }]
|
|
745
|
+
*
|
|
746
|
+
* // Using the SortDirection enum
|
|
747
|
+
* import { SortDirection } from 'prorm';
|
|
748
|
+
* indexes: [{ fields: [{ name: 'email', order: SortDirection.DESC }] }]
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
export declare enum SortDirection {
|
|
752
|
+
ASC = "ASC",
|
|
753
|
+
DESC = "DESC"
|
|
754
|
+
}
|
|
755
|
+
export interface IndexField {
|
|
756
|
+
name: string;
|
|
757
|
+
length?: number;
|
|
758
|
+
order?: SortDirection | 'ASC' | 'DESC';
|
|
759
|
+
collate?: string;
|
|
760
|
+
}
|
|
761
|
+
export interface IndexOptions {
|
|
762
|
+
name?: string;
|
|
763
|
+
/** Single field name or array of field names for composite indexes */
|
|
764
|
+
fields?: string[] | IndexField[];
|
|
765
|
+
unique?: boolean;
|
|
766
|
+
type?: string;
|
|
767
|
+
using?: string;
|
|
768
|
+
where?: WhereOptions;
|
|
769
|
+
/** PostgreSQL: specify tablespace for the index */
|
|
770
|
+
tablespace?: string;
|
|
771
|
+
/** PostgreSQL: index storage parameters */
|
|
772
|
+
storageParameters?: Record<string, string | number>;
|
|
773
|
+
/** MySQL/MariaDB: parser for full-text index */
|
|
774
|
+
parser?: string;
|
|
775
|
+
/** MySQL/MariaDB: FULLTEXT index */
|
|
776
|
+
fulltext?: boolean;
|
|
777
|
+
/** PostgreSQL: text search configuration for GIN index */
|
|
778
|
+
textSearchConfig?: string;
|
|
779
|
+
/** PostgreSQL/MySQL: include columns in index (covering index) */
|
|
780
|
+
include?: string[];
|
|
781
|
+
/** PostgreSQL/MySQL: index with NULLS NOT DISTINCT */
|
|
782
|
+
nullsNotDistinct?: boolean;
|
|
783
|
+
/** Expression-based index (e.g., LOWER(column), (column1 || ' ' || column2)) */
|
|
784
|
+
expression?: string;
|
|
785
|
+
/** If true, does not throw error if index already exists */
|
|
786
|
+
ifNotExists?: boolean;
|
|
787
|
+
}
|
|
788
|
+
/** Expression-based index definition */
|
|
789
|
+
export interface IndexExpression {
|
|
790
|
+
/** The expression to index (e.g., "LOWER(email)", "(first_name || ' ' || last_name)") */
|
|
791
|
+
expression: string;
|
|
792
|
+
/** Optional name for the expression */
|
|
793
|
+
name?: string;
|
|
794
|
+
}
|
|
795
|
+
export interface ConstraintOptions {
|
|
796
|
+
/** Custom constraint name (auto-generated if not provided) */
|
|
797
|
+
name?: string;
|
|
798
|
+
/** Alias for name - custom constraint name */
|
|
799
|
+
constraintName?: string;
|
|
800
|
+
type: 'PRIMARY KEY' | 'UNIQUE' | 'FOREIGN KEY' | 'CHECK';
|
|
801
|
+
/** Single field or array of fields for composite constraints */
|
|
802
|
+
fields?: string[];
|
|
803
|
+
/** Composite foreign key fields - used with compositeKey in associations */
|
|
804
|
+
compositeKey?: string[];
|
|
805
|
+
references?: {
|
|
806
|
+
model: string;
|
|
807
|
+
field: string;
|
|
808
|
+
/** Composite foreign key fields on the referenced table */
|
|
809
|
+
compositeKey?: string[];
|
|
810
|
+
onDelete?: ReferentialAction | 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION' | 'SET DEFAULT';
|
|
811
|
+
onUpdate?: ReferentialAction | 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION';
|
|
812
|
+
/** PostgreSQL: match type for foreign key (FULL, PARTIAL, SIMPLE) */
|
|
813
|
+
match?: 'FULL' | 'PARTIAL' | 'SIMPLE';
|
|
814
|
+
/** PostgreSQL: deferrable constraint */
|
|
815
|
+
deferrable?: 'INITIALLY DEFERRED' | 'INITIALLY IMMEDIATE' | 'NOT DEFERRABLE';
|
|
816
|
+
};
|
|
817
|
+
check?: string;
|
|
818
|
+
/** PostgreSQL: deferrable constraint */
|
|
819
|
+
deferrable?: 'INITIALLY DEFERRED' | 'INITIALLY IMMEDIATE' | 'NOT DEFERRABLE';
|
|
820
|
+
/** Foreign key match type (FULL, PARTIAL) */
|
|
821
|
+
match?: 'FULL' | 'PARTIAL';
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Unique key definition for model options
|
|
825
|
+
* Supports both simple unique constraints and composite unique constraints
|
|
826
|
+
*/
|
|
827
|
+
export interface UniqueKeyOptions {
|
|
828
|
+
/** Name of the unique constraint */
|
|
829
|
+
name?: string;
|
|
830
|
+
/** Fields to include in the unique constraint */
|
|
831
|
+
fields: string[];
|
|
832
|
+
/** Whether this is a unique index (true) or unique constraint (false/default) */
|
|
833
|
+
unique?: boolean;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Extended model options to support composite unique constraints
|
|
837
|
+
*/
|
|
838
|
+
export interface ModelOptionsWithConstraints extends ModelOptions {
|
|
839
|
+
/** Unique keys to create with the table - supports both simple and composite keys */
|
|
840
|
+
uniqueKeys?: UniqueKeyOptions[];
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* PostgreSQL partition type
|
|
844
|
+
*/
|
|
845
|
+
export type PartitionType = 'range' | 'list' | 'hash';
|
|
846
|
+
/**
|
|
847
|
+
* Partition bound specification for range partitions
|
|
848
|
+
*/
|
|
849
|
+
export interface PartitionBound {
|
|
850
|
+
/** Start value (inclusive) */
|
|
851
|
+
from: string | number | Date;
|
|
852
|
+
/** End value (exclusive for range) */
|
|
853
|
+
to?: string | number | Date;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Partition bound specification for list partitions
|
|
857
|
+
*/
|
|
858
|
+
export interface PartitionListBound {
|
|
859
|
+
/** Values for list partition */
|
|
860
|
+
values: (string | number)[];
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Partition bound specification for hash partitions
|
|
864
|
+
*/
|
|
865
|
+
export interface PartitionHashBound {
|
|
866
|
+
/** Modulus value */
|
|
867
|
+
modulus: number;
|
|
868
|
+
/** Remainder value */
|
|
869
|
+
remainder: number;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Partition options for model definitions
|
|
873
|
+
*/
|
|
874
|
+
export interface PartitionOptions {
|
|
875
|
+
/** Partition type: range, list, or hash */
|
|
876
|
+
type: PartitionType;
|
|
877
|
+
/** Column(s) to partition by */
|
|
878
|
+
column: string | string[];
|
|
879
|
+
/** Partition definitions */
|
|
880
|
+
partitions?: PartitionDefinition[];
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Individual partition definition
|
|
884
|
+
*/
|
|
885
|
+
export interface PartitionDefinition {
|
|
886
|
+
/** Name of the partition */
|
|
887
|
+
name: string;
|
|
888
|
+
/** Partition bound specification */
|
|
889
|
+
bound?: PartitionBound | PartitionListBound | PartitionHashBound;
|
|
890
|
+
/** Tablespace for the partition (PostgreSQL) */
|
|
891
|
+
tablespace?: string;
|
|
892
|
+
/** Storage parameters for the partition */
|
|
893
|
+
storageParameters?: Record<string, string | number>;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Options for creating a partition
|
|
897
|
+
*/
|
|
898
|
+
export interface CreatePartitionOptions {
|
|
899
|
+
/** Parent table name */
|
|
900
|
+
parentTable: string;
|
|
901
|
+
/** Partition name */
|
|
902
|
+
name: string;
|
|
903
|
+
/** Partition bound */
|
|
904
|
+
bound?: PartitionBound | PartitionListBound | PartitionHashBound;
|
|
905
|
+
/** Tablespace */
|
|
906
|
+
tablespace?: string;
|
|
907
|
+
/** Storage parameters */
|
|
908
|
+
storageParameters?: Record<string, string | number>;
|
|
909
|
+
/** Include partition in queries (default: true) */
|
|
910
|
+
including?: boolean;
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Options for attaching a partition
|
|
914
|
+
*/
|
|
915
|
+
export interface AttachPartitionOptions {
|
|
916
|
+
/** Parent table name */
|
|
917
|
+
parentTable: string;
|
|
918
|
+
/** Partition name */
|
|
919
|
+
partitionName: string;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Options for detaching a partition
|
|
923
|
+
*/
|
|
924
|
+
export interface DetachPartitionOptions {
|
|
925
|
+
/** Partition name */
|
|
926
|
+
partitionName: string;
|
|
927
|
+
/** Whether to use NOT VALIDATE option */
|
|
928
|
+
validate?: boolean;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Custom validator function type
|
|
932
|
+
* Returns true if valid, or throws an error if invalid
|
|
933
|
+
*/
|
|
934
|
+
export type CustomValidator = (value: any, options?: {
|
|
935
|
+
instance?: Model;
|
|
936
|
+
model?: ModelStatic<any>;
|
|
937
|
+
field?: string;
|
|
938
|
+
}) => boolean | void | Promise<boolean | void>;
|
|
939
|
+
/**
|
|
940
|
+
* When to run validation: on create, update, or both
|
|
941
|
+
*/
|
|
942
|
+
export type ValidateOnOption = 'create' | 'update' | 'save' | 'saveOnly';
|
|
943
|
+
/**
|
|
944
|
+
* Companion enum for `ValidateOnOption`. Mirrors the same fixed set of
|
|
945
|
+
* string values so callers who prefer enums (autocomplete, refactor-safe
|
|
946
|
+
* references, etc.) can use `ValidateOn.Create` instead of the raw string
|
|
947
|
+
* literal `'create'`. Both forms are accepted anywhere `ValidateOnOption`
|
|
948
|
+
* is used - this is purely additive and does not replace the string
|
|
949
|
+
* literal union.
|
|
950
|
+
*/
|
|
951
|
+
export declare enum ValidateOn {
|
|
952
|
+
Create = "create",
|
|
953
|
+
Update = "update",
|
|
954
|
+
Save = "save",
|
|
955
|
+
SaveOnly = "saveOnly"
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Per-field validation options
|
|
959
|
+
*/
|
|
960
|
+
export interface FieldValidationOptions {
|
|
961
|
+
/** Custom error message */
|
|
962
|
+
msg?: string;
|
|
963
|
+
/** When to run this validation. Accepts either the `ValidateOnOption`
|
|
964
|
+
* string literals or the equivalent `ValidateOn` enum members. */
|
|
965
|
+
on?: ValidateOnOption | ValidateOn | (ValidateOnOption | ValidateOn)[];
|
|
966
|
+
/** Custom validator function */
|
|
967
|
+
customValidator?: CustomValidator;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Extended validation options for attributes and model
|
|
971
|
+
*/
|
|
972
|
+
export interface ExtendedValidationOptions {
|
|
973
|
+
/** Custom validators by name */
|
|
974
|
+
[customValidator: string]: ValidationMethod | ValidationChain | CustomValidator | FieldValidationOptions;
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Validation result interface
|
|
978
|
+
*/
|
|
979
|
+
export interface ValidationResult {
|
|
980
|
+
valid: boolean;
|
|
981
|
+
errors: ValidationErrorItem[];
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Options for Model.validate() static method
|
|
985
|
+
*/
|
|
986
|
+
export interface ModelValidateOptions {
|
|
987
|
+
/** Fields to validate (validates all if not provided) */
|
|
988
|
+
fields?: string[];
|
|
989
|
+
/** Whether to run hooks (default: true) */
|
|
990
|
+
hooks?: boolean;
|
|
991
|
+
/** Only validate specific fields */
|
|
992
|
+
validateSchema?: boolean;
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Options for instance validate() method
|
|
996
|
+
*/
|
|
997
|
+
export interface InstanceValidateOptions {
|
|
998
|
+
/** Fields to validate (validates all if not provided) */
|
|
999
|
+
fields?: string[];
|
|
1000
|
+
/** Whether to run hooks (default: true) */
|
|
1001
|
+
hooks?: boolean;
|
|
1002
|
+
/** Validate on create only (for instance validation) */
|
|
1003
|
+
validateOnCreate?: boolean;
|
|
1004
|
+
/** Validate on update only (for instance validation) */
|
|
1005
|
+
validateOnUpdate?: boolean;
|
|
1006
|
+
}
|
|
1007
|
+
export interface ScopeOptions {
|
|
1008
|
+
attributes?: FindOptions['attributes'];
|
|
1009
|
+
where?: WhereOptions;
|
|
1010
|
+
include?: Includeable[] | IncludeOptions[];
|
|
1011
|
+
order?: Order;
|
|
1012
|
+
limit?: number;
|
|
1013
|
+
offset?: number;
|
|
1014
|
+
transaction?: Transaction;
|
|
1015
|
+
}
|
|
1016
|
+
export interface ModelValidationOptions {
|
|
1017
|
+
[key: string]: ValidationMethod | ValidationChain;
|
|
1018
|
+
}
|
|
1019
|
+
export type ValidationMethod = (value: any) => boolean | string | Error;
|
|
1020
|
+
export interface ValidationChain {
|
|
1021
|
+
is: [RegExp | string, string?];
|
|
1022
|
+
not: [RegExp | string, string?];
|
|
1023
|
+
isEmail: boolean | string;
|
|
1024
|
+
isUrl: boolean | string;
|
|
1025
|
+
isIP: boolean | string;
|
|
1026
|
+
isAlpha: boolean | string;
|
|
1027
|
+
isAlphanumeric: boolean | string;
|
|
1028
|
+
isNumeric: boolean | string;
|
|
1029
|
+
isInt: boolean | string;
|
|
1030
|
+
isFloat: boolean | string;
|
|
1031
|
+
isDecimal: boolean | string;
|
|
1032
|
+
isLowercase: boolean | string;
|
|
1033
|
+
isUppercase: boolean | string;
|
|
1034
|
+
isNull: boolean | string;
|
|
1035
|
+
notEmpty: boolean | string;
|
|
1036
|
+
equals: string;
|
|
1037
|
+
contains: string;
|
|
1038
|
+
notContains: string;
|
|
1039
|
+
len: [number, number?] | number;
|
|
1040
|
+
isUUID: boolean | string;
|
|
1041
|
+
isDate: boolean | string;
|
|
1042
|
+
isAfter: string;
|
|
1043
|
+
isBefore: string;
|
|
1044
|
+
isIn: any[][];
|
|
1045
|
+
notIn: any[][];
|
|
1046
|
+
max: number;
|
|
1047
|
+
min: number;
|
|
1048
|
+
}
|
|
1049
|
+
export type DataType = DataTypeString | DataTypeChar | DataTypeText | DataTypeNumber | DataTypeInteger | DataTypeBigInt | DataTypeFloat | DataTypeDouble | DataTypeDecimal | DataTypeBoolean | DataTypeDate | DataTypeDateOnly | DataTypeTime | DataTypeBlob | DataTypeEnum | DataTypeJSON | DataTypeJSONB | DataTypeUUID | DataTypeGeometry | DataTypeSET | DataTypeHStore | DataTypeRange | DataTypeInet | DataTypeCidr | DataTypeMacAddr | string;
|
|
1050
|
+
export interface DataTypeAbstract {
|
|
1051
|
+
key: string;
|
|
1052
|
+
toSql?: () => string;
|
|
1053
|
+
}
|
|
1054
|
+
export interface DataTypeString extends DataTypeAbstract {
|
|
1055
|
+
key: 'STRING';
|
|
1056
|
+
length: number;
|
|
1057
|
+
}
|
|
1058
|
+
export interface DataTypeChar extends DataTypeAbstract {
|
|
1059
|
+
key: 'CHAR';
|
|
1060
|
+
length: number;
|
|
1061
|
+
}
|
|
1062
|
+
export interface DataTypeText extends DataTypeAbstract {
|
|
1063
|
+
key: 'TEXT';
|
|
1064
|
+
length?: number;
|
|
1065
|
+
}
|
|
1066
|
+
export interface DataTypeNumber extends DataTypeAbstract {
|
|
1067
|
+
key: 'NUMBER';
|
|
1068
|
+
precision: number;
|
|
1069
|
+
scale: number;
|
|
1070
|
+
}
|
|
1071
|
+
export interface DataTypeInteger extends DataTypeAbstract {
|
|
1072
|
+
key: 'INTEGER';
|
|
1073
|
+
length?: number;
|
|
1074
|
+
unsigned?: boolean;
|
|
1075
|
+
zerofill?: boolean;
|
|
1076
|
+
}
|
|
1077
|
+
export interface DataTypeBigInt extends DataTypeAbstract {
|
|
1078
|
+
key: 'BIGINT';
|
|
1079
|
+
length?: number;
|
|
1080
|
+
unsigned?: boolean;
|
|
1081
|
+
}
|
|
1082
|
+
export interface DataTypeFloat extends DataTypeAbstract {
|
|
1083
|
+
key: 'FLOAT';
|
|
1084
|
+
length?: number;
|
|
1085
|
+
decimals?: number;
|
|
1086
|
+
unsigned?: boolean;
|
|
1087
|
+
}
|
|
1088
|
+
export interface DataTypeDouble extends DataTypeAbstract {
|
|
1089
|
+
key: 'DOUBLE';
|
|
1090
|
+
length?: number;
|
|
1091
|
+
decimals?: number;
|
|
1092
|
+
unsigned?: boolean;
|
|
1093
|
+
}
|
|
1094
|
+
export interface DataTypeDecimal extends DataTypeAbstract {
|
|
1095
|
+
key: 'DECIMAL';
|
|
1096
|
+
precision: number;
|
|
1097
|
+
scale: number;
|
|
1098
|
+
unsigned?: boolean;
|
|
1099
|
+
}
|
|
1100
|
+
export interface DataTypeBoolean extends DataTypeAbstract {
|
|
1101
|
+
key: 'BOOLEAN';
|
|
1102
|
+
}
|
|
1103
|
+
export interface DataTypeDate extends DataTypeAbstract {
|
|
1104
|
+
key: 'DATE';
|
|
1105
|
+
precision?: number;
|
|
1106
|
+
timezone?: boolean;
|
|
1107
|
+
}
|
|
1108
|
+
export interface DataTypeDateOnly extends DataTypeAbstract {
|
|
1109
|
+
key: 'DATEONLY';
|
|
1110
|
+
}
|
|
1111
|
+
export interface DataTypeTime extends DataTypeAbstract {
|
|
1112
|
+
key: 'TIME';
|
|
1113
|
+
precision?: number;
|
|
1114
|
+
}
|
|
1115
|
+
export interface DataTypeBlob extends DataTypeAbstract {
|
|
1116
|
+
key: 'BLOB';
|
|
1117
|
+
length?: 'tiny' | 'medium' | 'long';
|
|
1118
|
+
}
|
|
1119
|
+
export interface DataTypeEnum extends DataTypeAbstract {
|
|
1120
|
+
key: 'ENUM';
|
|
1121
|
+
values: string[];
|
|
1122
|
+
}
|
|
1123
|
+
export interface DataTypeJSON extends DataTypeAbstract {
|
|
1124
|
+
key: 'JSON';
|
|
1125
|
+
}
|
|
1126
|
+
export interface DataTypeJSONB extends DataTypeAbstract {
|
|
1127
|
+
key: 'JSONB';
|
|
1128
|
+
}
|
|
1129
|
+
export interface DataTypeUUID extends DataTypeAbstract {
|
|
1130
|
+
key: 'UUID';
|
|
1131
|
+
}
|
|
1132
|
+
export interface DataTypeGeometry extends DataTypeAbstract {
|
|
1133
|
+
key: 'GEOMETRY';
|
|
1134
|
+
type: string;
|
|
1135
|
+
srid?: number;
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* MySQL-specific spatial types
|
|
1139
|
+
*/
|
|
1140
|
+
export type SpatialType = 'POINT' | 'LINESTRING' | 'POLYGON' | 'MULTIPOINT' | 'MULTILINESTRING' | 'MULTIPOLYGON' | 'GEOMETRYCOLLECTION' | 'GEOMETRY';
|
|
1141
|
+
/**
|
|
1142
|
+
* Options for JSON column in MySQL
|
|
1143
|
+
*/
|
|
1144
|
+
export interface JSONColumnOptions {
|
|
1145
|
+
/** Whether to validate JSON format on insert/update */
|
|
1146
|
+
validate?: boolean;
|
|
1147
|
+
/** Whether to use JSON unescaped Unicode mode */
|
|
1148
|
+
unescapedUnicode?: boolean;
|
|
1149
|
+
/** Whether to use compact JSON output */
|
|
1150
|
+
compact?: boolean;
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* MySQL SET column options
|
|
1154
|
+
*/
|
|
1155
|
+
export interface SetColumnOptions {
|
|
1156
|
+
/** Array of allowed values for the SET column */
|
|
1157
|
+
values: string[];
|
|
1158
|
+
/** Optional name for the SET type (useful for custom types) */
|
|
1159
|
+
name?: string;
|
|
1160
|
+
}
|
|
1161
|
+
export interface DataTypeVirtual extends DataTypeAbstract {
|
|
1162
|
+
key: 'VIRTUAL';
|
|
1163
|
+
returnType?: DataType;
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* MySQL SET column data type
|
|
1167
|
+
*/
|
|
1168
|
+
export interface DataTypeSET extends DataTypeAbstract {
|
|
1169
|
+
key: 'SET';
|
|
1170
|
+
values: string[];
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* Options for JSON column in MySQL
|
|
1174
|
+
*/
|
|
1175
|
+
export interface JSONColumnOptions {
|
|
1176
|
+
/** Whether to validate JSON format on insert/update */
|
|
1177
|
+
validate?: boolean;
|
|
1178
|
+
/** Whether to use JSON unescaped Unicode mode */
|
|
1179
|
+
unescapedUnicode?: boolean;
|
|
1180
|
+
/** Whether to use compact JSON output */
|
|
1181
|
+
compact?: boolean;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* MySQL SET column options
|
|
1185
|
+
*/
|
|
1186
|
+
export interface SetColumnOptions {
|
|
1187
|
+
/** Array of allowed values for the SET column */
|
|
1188
|
+
values: string[];
|
|
1189
|
+
/** Optional name for the SET type (useful for custom types) */
|
|
1190
|
+
name?: string;
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* PostgreSQL HStore key-value type
|
|
1194
|
+
* Requires extension: CREATE EXTENSION IF NOT EXISTS hstore
|
|
1195
|
+
*/
|
|
1196
|
+
export interface DataTypeHStore extends DataTypeAbstract {
|
|
1197
|
+
key: 'HSTORE';
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* PostgreSQL Range Types
|
|
1201
|
+
* - int4range: Range of integer
|
|
1202
|
+
* - int8range: Range of bigint
|
|
1203
|
+
* - numrange: Range of numeric
|
|
1204
|
+
* - tsrange: Range of timestamp without time zone
|
|
1205
|
+
* - tstzrange: Range of timestamp with time zone
|
|
1206
|
+
* - daterange: Range of date
|
|
1207
|
+
*/
|
|
1208
|
+
export type RangeSubtype = 'int4range' | 'int8range' | 'numrange' | 'tsrange' | 'tstzrange' | 'daterange';
|
|
1209
|
+
export interface DataTypeRange extends DataTypeAbstract {
|
|
1210
|
+
key: 'RANGE';
|
|
1211
|
+
subtype: RangeSubtype;
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* PostgreSQL INET type for IP addresses
|
|
1215
|
+
*/
|
|
1216
|
+
export interface DataTypeInet extends DataTypeAbstract {
|
|
1217
|
+
key: 'INET';
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* PostgreSQL CIDR type for network addresses
|
|
1221
|
+
*/
|
|
1222
|
+
export interface DataTypeCidr extends DataTypeAbstract {
|
|
1223
|
+
key: 'CIDR';
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* PostgreSQL MACADDR type for MAC addresses
|
|
1227
|
+
*/
|
|
1228
|
+
export interface DataTypeMacAddr extends DataTypeAbstract {
|
|
1229
|
+
key: 'MACADDR';
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Options for UUID type
|
|
1233
|
+
*/
|
|
1234
|
+
export interface UUIDOptions {
|
|
1235
|
+
/** Use gen_random_uuid() for default value (PostgreSQL 13+) */
|
|
1236
|
+
defaultValue?: 'gen_random_uuid' | 'uuid_generate_v4' | string;
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Options for JSONB type
|
|
1240
|
+
*/
|
|
1241
|
+
export interface JSONBOptions {
|
|
1242
|
+
/** Whether to validate JSON structure */
|
|
1243
|
+
validate?: boolean;
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Options for HStore type
|
|
1247
|
+
*/
|
|
1248
|
+
export interface HStoreOptions {
|
|
1249
|
+
/** Whether to use native HStore or JSONB fallback */
|
|
1250
|
+
useNative?: boolean;
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Options for Range type
|
|
1254
|
+
*/
|
|
1255
|
+
export interface RangeOptions {
|
|
1256
|
+
/** The range subtype */
|
|
1257
|
+
subtype: RangeSubtype;
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Options for INET/CIDR types
|
|
1261
|
+
*/
|
|
1262
|
+
export interface InetOptions {
|
|
1263
|
+
/** For CIDR: whether to include address family */
|
|
1264
|
+
includeFamily?: boolean;
|
|
1265
|
+
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Table inheritance options for PostgreSQL
|
|
1268
|
+
*/
|
|
1269
|
+
export interface InheritOptions {
|
|
1270
|
+
/** Parent table(s) to inherit from */
|
|
1271
|
+
parentTable: string | string[];
|
|
1272
|
+
/** Only include rows from child table in queries */
|
|
1273
|
+
only?: boolean;
|
|
1274
|
+
/** Include rows from parent table in queries (default) */
|
|
1275
|
+
inherit?: boolean;
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Array column options for PostgreSQL array types
|
|
1279
|
+
*/
|
|
1280
|
+
export interface ArrayOptions {
|
|
1281
|
+
/** The data type of array elements */
|
|
1282
|
+
type: DataType;
|
|
1283
|
+
/** Whether the array can be null */
|
|
1284
|
+
allowNull?: boolean;
|
|
1285
|
+
/** Default value for the array column */
|
|
1286
|
+
defaultValue?: any;
|
|
1287
|
+
/** Comment for the column */
|
|
1288
|
+
comment?: string;
|
|
1289
|
+
/** Custom column name in the database */
|
|
1290
|
+
field?: string;
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Array operator options for querying array columns
|
|
1294
|
+
*/
|
|
1295
|
+
export interface ArrayOperatorOptions {
|
|
1296
|
+
/** Array contains operator (@>) */
|
|
1297
|
+
$arrayContains?: any[];
|
|
1298
|
+
/** Array contained by operator (<@) */
|
|
1299
|
+
$arrayContainedBy?: any[];
|
|
1300
|
+
/** Array overlaps operator (&&) */
|
|
1301
|
+
$arrayOverlaps?: any[];
|
|
1302
|
+
/** Array ANY operator */
|
|
1303
|
+
$arrayAny?: any;
|
|
1304
|
+
/** Array ALL operator */
|
|
1305
|
+
$arrayAll?: any;
|
|
1306
|
+
}
|
|
1307
|
+
export interface AttributeOptions {
|
|
1308
|
+
type: DataType;
|
|
1309
|
+
allowNull?: boolean;
|
|
1310
|
+
defaultValue?: any;
|
|
1311
|
+
primaryKey?: boolean;
|
|
1312
|
+
/**
|
|
1313
|
+
* Unique constraint on this field
|
|
1314
|
+
* - true: auto-generate constraint name
|
|
1315
|
+
* - string: use as constraint name
|
|
1316
|
+
* - { name: string, msg?: string }: custom name with optional error message
|
|
1317
|
+
*/
|
|
1318
|
+
unique?: boolean | string | {
|
|
1319
|
+
name: string;
|
|
1320
|
+
msg?: string;
|
|
1321
|
+
};
|
|
1322
|
+
/**
|
|
1323
|
+
* Unique key name for this attribute - used to group with other fields for composite unique constraints.
|
|
1324
|
+
* When multiple fields share the same uniqueKey, they form a composite unique constraint.
|
|
1325
|
+
* Example: { uniqueKey: 'uq_org_email' } on orgId and email fields creates a composite unique constraint.
|
|
1326
|
+
*/
|
|
1327
|
+
uniqueKey?: string;
|
|
1328
|
+
references?: ReferenceOptions;
|
|
1329
|
+
autoIncrement?: boolean;
|
|
1330
|
+
comment?: string;
|
|
1331
|
+
validate?: ModelValidationOptions;
|
|
1332
|
+
field?: string;
|
|
1333
|
+
get?: () => any;
|
|
1334
|
+
set?: (value: any) => void;
|
|
1335
|
+
hidden?: boolean;
|
|
1336
|
+
virtual?: boolean;
|
|
1337
|
+
}
|
|
1338
|
+
export interface ReferenceOptions {
|
|
1339
|
+
model: string | ModelStatic<any>;
|
|
1340
|
+
key?: string;
|
|
1341
|
+
deferrable?: string;
|
|
1342
|
+
onDelete?: ReferentialAction | 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT';
|
|
1343
|
+
onUpdate?: ReferentialAction | 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT';
|
|
1344
|
+
}
|
|
1345
|
+
export interface ModelHooks {
|
|
1346
|
+
beforeValidate?: HookHandler;
|
|
1347
|
+
afterValidate?: HookHandler;
|
|
1348
|
+
beforeCreate?: HookHandler;
|
|
1349
|
+
afterCreate?: HookHandler;
|
|
1350
|
+
beforeUpdate?: HookHandler;
|
|
1351
|
+
afterUpdate?: HookHandler;
|
|
1352
|
+
beforeDestroy?: HookHandler;
|
|
1353
|
+
afterDestroy?: HookHandler;
|
|
1354
|
+
beforeSave?: HookHandler;
|
|
1355
|
+
afterSave?: HookHandler;
|
|
1356
|
+
beforeBulkCreate?: BulkHookHandler;
|
|
1357
|
+
afterBulkCreate?: BulkHookHandler;
|
|
1358
|
+
beforeBulkUpdate?: BulkHookHandler;
|
|
1359
|
+
afterBulkUpdate?: BulkHookHandler;
|
|
1360
|
+
beforeBulkDestroy?: BulkHookHandler;
|
|
1361
|
+
afterBulkDestroy?: BulkHookHandler;
|
|
1362
|
+
beforeFind?: FindHookHandler;
|
|
1363
|
+
afterFind?: AfterFindHookHandler;
|
|
1364
|
+
}
|
|
1365
|
+
export type FindHookHandler = (options: FindOptions, model: ModelStatic<any>) => Promise<void> | void;
|
|
1366
|
+
export type AfterFindHookHandler = (instances: Model[], options: FindOptions, model: ModelStatic<any>) => Promise<void> | void;
|
|
1367
|
+
export type HookHandler = (instance: Model, options?: HookOptions) => Promise<void> | void;
|
|
1368
|
+
export type BulkHookHandler = (instances?: Model[], options?: HookOptions) => Promise<void> | void;
|
|
1369
|
+
export interface HookOptions {
|
|
1370
|
+
transaction?: Transaction;
|
|
1371
|
+
hooks?: boolean;
|
|
1372
|
+
validate?: boolean;
|
|
1373
|
+
fields?: string[];
|
|
1374
|
+
skip?: string[];
|
|
1375
|
+
individualHooks?: boolean;
|
|
1376
|
+
bench?: boolean;
|
|
1377
|
+
model?: any;
|
|
1378
|
+
instances?: Model[];
|
|
1379
|
+
}
|
|
1380
|
+
export type WhereOptions<T = any> = {
|
|
1381
|
+
[key: string]: any;
|
|
1382
|
+
} | WhereLogical<T>;
|
|
1383
|
+
export interface WhereLogical<T> {
|
|
1384
|
+
$and?: WhereOptions<T>[];
|
|
1385
|
+
$or?: WhereOptions<T>[];
|
|
1386
|
+
$not?: WhereOptions<T>;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Full-text search options for MATCH AGAINST (MySQL) and tsvector (PostgreSQL)
|
|
1390
|
+
*/
|
|
1391
|
+
export interface FullTextSearchOptions {
|
|
1392
|
+
/** Search mode: 'natural' for natural language mode, 'boolean' for boolean mode */
|
|
1393
|
+
mode?: 'natural' | 'boolean';
|
|
1394
|
+
/** Columns to search (for MATCH AGAINST) */
|
|
1395
|
+
fields?: string[];
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* PostgreSQL tsvector options
|
|
1399
|
+
*/
|
|
1400
|
+
export interface TsVectorOptions {
|
|
1401
|
+
/** Text search configuration (e.g., 'english', 'simple') */
|
|
1402
|
+
config?: string;
|
|
1403
|
+
/** Pre-computed tsvector column name */
|
|
1404
|
+
column?: string;
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* UNION type for combining query results
|
|
1408
|
+
*/
|
|
1409
|
+
export type UnionType = 'UNION' | 'UNION ALL' | 'EXCEPT' | 'INTERSECT';
|
|
1410
|
+
/**
|
|
1411
|
+
* Options for a single union query
|
|
1412
|
+
*/
|
|
1413
|
+
export interface UnionQueryOptions {
|
|
1414
|
+
/** The model to query */
|
|
1415
|
+
model: ModelStatic<any>;
|
|
1416
|
+
/** WHERE conditions for this union query */
|
|
1417
|
+
where?: WhereOptions;
|
|
1418
|
+
/** Attributes to select */
|
|
1419
|
+
attributes?: string[] | {
|
|
1420
|
+
include?: string[];
|
|
1421
|
+
exclude?: string[];
|
|
1422
|
+
};
|
|
1423
|
+
/** ORDER BY for this union query */
|
|
1424
|
+
order?: Order;
|
|
1425
|
+
/** LIMIT for this union query */
|
|
1426
|
+
limit?: number | string;
|
|
1427
|
+
/** OFFSET for this union query */
|
|
1428
|
+
offset?: number | string;
|
|
1429
|
+
/** Include related models */
|
|
1430
|
+
include?: Includeable[] | IncludeOptions[];
|
|
1431
|
+
/** Alias for this query (useful for debugging) */
|
|
1432
|
+
as?: string;
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Subquery wrapper for use in WHERE clauses
|
|
1436
|
+
*/
|
|
1437
|
+
export interface SubqueryOptions {
|
|
1438
|
+
/** The SQL query string (raw or with model reference) */
|
|
1439
|
+
sql: string;
|
|
1440
|
+
/** Whether this is a literal SQL string vs a model-based subquery */
|
|
1441
|
+
literal?: boolean;
|
|
1442
|
+
/** Model to use for building the subquery */
|
|
1443
|
+
model?: ModelStatic<any>;
|
|
1444
|
+
/** Options for building the subquery (if model is provided) */
|
|
1445
|
+
modelOptions?: FindOptions;
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* HAVING clause options - supports aggregations and alias references
|
|
1449
|
+
* Similar to WhereOptions but can reference aggregate function aliases
|
|
1450
|
+
*/
|
|
1451
|
+
export type HavingOptions<T = any> = {
|
|
1452
|
+
[key: string]: any;
|
|
1453
|
+
} | HavingLogical<T>;
|
|
1454
|
+
export interface HavingLogical<T> {
|
|
1455
|
+
$and?: HavingOptions<T>[];
|
|
1456
|
+
$or?: HavingOptions<T>[];
|
|
1457
|
+
$not?: HavingOptions<T>;
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Attribute selection format
|
|
1461
|
+
* Supports:
|
|
1462
|
+
* - Simple strings: 'columnName'
|
|
1463
|
+
* - Arrays of strings: ['col1', 'col2']
|
|
1464
|
+
* - Function expressions with alias: [[fn('COUNT', col('id')), 'count']]
|
|
1465
|
+
* - Literal SQL with alias: [['COUNT(*)', 'count']]
|
|
1466
|
+
*/
|
|
1467
|
+
export type AttributeValue = string | [any, string] | [any, any, string];
|
|
1468
|
+
export type AttributesOptions = string[] | {
|
|
1469
|
+
include?: string[];
|
|
1470
|
+
exclude?: string[];
|
|
1471
|
+
} | AttributeValue[];
|
|
1472
|
+
/**
|
|
1473
|
+
* Common Table Expression (CTE) options
|
|
1474
|
+
* Used for WITH RECURSIVE and regular WITH clauses
|
|
1475
|
+
*/
|
|
1476
|
+
export interface CTEOptions {
|
|
1477
|
+
/** Name of the CTE */
|
|
1478
|
+
name: string;
|
|
1479
|
+
/** Column names for the CTE (optional) */
|
|
1480
|
+
columns?: string[];
|
|
1481
|
+
/**
|
|
1482
|
+
* The CTE body. Prefer a structured query object (same shape as
|
|
1483
|
+
* `SelectOptions` in `src/dialects/dialect.ts`: `tableName`, `where`,
|
|
1484
|
+
* `attributes`, `order`, etc.) over a raw SQL string wherever possible -
|
|
1485
|
+
* a plain string is only meant as an escape hatch for CTE bodies that
|
|
1486
|
+
* can't be expressed structurally (e.g. hand-written recursive UNION ALL
|
|
1487
|
+
* logic referencing the CTE's own name).
|
|
1488
|
+
*/
|
|
1489
|
+
query: string | Record<string, unknown>;
|
|
1490
|
+
/** Whether this is a recursive CTE */
|
|
1491
|
+
recursive?: boolean;
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Aggregate function types for pivot operations
|
|
1495
|
+
*/
|
|
1496
|
+
export type AggregateFunction = 'SUM' | 'COUNT' | 'AVG' | 'MAX' | 'MIN';
|
|
1497
|
+
/**
|
|
1498
|
+
* Pivot options for transforming rows to columns
|
|
1499
|
+
*/
|
|
1500
|
+
export interface PivotOptions {
|
|
1501
|
+
/** The column to pivot on (values become new column names) */
|
|
1502
|
+
on: string;
|
|
1503
|
+
/** Map of column names to aggregate functions */
|
|
1504
|
+
using: Record<string, AggregateFunction>;
|
|
1505
|
+
/** Aggregate function to use (overrides using if provided) */
|
|
1506
|
+
aggregate?: AggregateFunction;
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Unpivot options for transforming columns to rows
|
|
1510
|
+
*/
|
|
1511
|
+
export interface UnpivotOptions {
|
|
1512
|
+
/** Columns to unpivot (transform to rows) */
|
|
1513
|
+
in: string[];
|
|
1514
|
+
/** Name for the value column in the result */
|
|
1515
|
+
valueColumn: string;
|
|
1516
|
+
/** Name for the column name column in the result */
|
|
1517
|
+
nameColumn: string;
|
|
1518
|
+
}
|
|
1519
|
+
export interface FindOptions {
|
|
1520
|
+
where?: WhereOptions;
|
|
1521
|
+
attributes?: AttributesOptions;
|
|
1522
|
+
/** Schema to use for the main table */
|
|
1523
|
+
schema?: string;
|
|
1524
|
+
/**
|
|
1525
|
+
* Overrides the FROM target of the query, in place of the model's own
|
|
1526
|
+
* table name. Primarily useful together with `cte` to select from a CTE
|
|
1527
|
+
* result set instead of the model's base table
|
|
1528
|
+
* @example
|
|
1529
|
+
* // Select from the `org_chart` CTE instead of `employees`
|
|
1530
|
+
* Employee.findAll({ cte: [...], tableName: 'org_chart' })
|
|
1531
|
+
*/
|
|
1532
|
+
tableName?: string;
|
|
1533
|
+
/** Search path for query resolution (PostgreSQL) */
|
|
1534
|
+
searchPath?: string | string[];
|
|
1535
|
+
/**
|
|
1536
|
+
* Connection name to use for this query
|
|
1537
|
+
* Allows querying a different database connection
|
|
1538
|
+
* @example
|
|
1539
|
+
* // Use analytics connection
|
|
1540
|
+
* User.findAll({
|
|
1541
|
+
* using: 'analytics'
|
|
1542
|
+
* });
|
|
1543
|
+
*/
|
|
1544
|
+
using?: string;
|
|
1545
|
+
include?: Includeable[] | IncludeOptions[];
|
|
1546
|
+
order?: Order;
|
|
1547
|
+
/** Number of records to return */
|
|
1548
|
+
limit?: number;
|
|
1549
|
+
/** Number of records to skip */
|
|
1550
|
+
offset?: number;
|
|
1551
|
+
/**
|
|
1552
|
+
* GROUP BY clause - can be a string, array of strings, array of arrays with function expressions, or array of model objects
|
|
1553
|
+
* @example
|
|
1554
|
+
* group: 'status'
|
|
1555
|
+
* group: ['status']
|
|
1556
|
+
* group: ['userId', 'category']
|
|
1557
|
+
* group: [['status', 'role']] // Array format for mixed columns and expressions
|
|
1558
|
+
* group: [[prorm.fn('COUNT', 'id'), 'count']] // Function expressions with alias
|
|
1559
|
+
* group: [{ model: User, as: 'author' }]
|
|
1560
|
+
*/
|
|
1561
|
+
group?: string | string[] | [any, string][] | {
|
|
1562
|
+
model: ModelStatic<any>;
|
|
1563
|
+
as?: string;
|
|
1564
|
+
}[];
|
|
1565
|
+
/**
|
|
1566
|
+
* Type of grouping for advanced aggregation features
|
|
1567
|
+
* - 'rollup': Generates ROLLUP(column, ...) for hierarchical aggregations
|
|
1568
|
+
* - 'cube': Generates CUBE(column, ...) for multi-dimensional aggregations
|
|
1569
|
+
* - 'grouping': Uses GROUPING SETS for custom grouping combinations
|
|
1570
|
+
* - 'none': No special grouping type (default)
|
|
1571
|
+
* @example
|
|
1572
|
+
* groupType: 'rollup'
|
|
1573
|
+
* groupType: 'cube'
|
|
1574
|
+
* groupType: 'grouping'
|
|
1575
|
+
*/
|
|
1576
|
+
groupType?: 'rollup' | 'cube' | 'grouping' | 'none';
|
|
1577
|
+
/**
|
|
1578
|
+
* GROUPING SETS - custom grouping combinations for advanced aggregation
|
|
1579
|
+
* Each element is an array representing one grouping set
|
|
1580
|
+
* @example
|
|
1581
|
+
* groupingSets: [['status'], ['region'], []] // Group by status, region, and grand total
|
|
1582
|
+
* groupingSets: [['a', 'b'], ['a'], []] // Group by (a,b), (a), and grand total
|
|
1583
|
+
*/
|
|
1584
|
+
groupingSets?: string[][];
|
|
1585
|
+
/**
|
|
1586
|
+
* HAVING clause - filter aggregated results
|
|
1587
|
+
* Supports all WHERE operators plus aggregation-specific conditions
|
|
1588
|
+
* @example
|
|
1589
|
+
* having: { count: { [Op.gt]: 5 } }
|
|
1590
|
+
* having: { count: { [Op.between]: [1, 10] } }
|
|
1591
|
+
* having: { $or: [{ count: { [Op.lt]: 2 } }, { totalViews: { [Op.gt]: 1000 } }] }
|
|
1592
|
+
*/
|
|
1593
|
+
having?: HavingOptions;
|
|
1594
|
+
raw?: boolean;
|
|
1595
|
+
transaction?: Transaction;
|
|
1596
|
+
/**
|
|
1597
|
+
* Row-level locking options
|
|
1598
|
+
* - true: FOR UPDATE (equivalent to 'UPDATE')
|
|
1599
|
+
* - 'UPDATE': FOR UPDATE - prevents other transactions from modifying the rows
|
|
1600
|
+
* - 'SHARE': FOR SHARE (PostgreSQL) / LOCK IN SHARE MODE (MySQL)
|
|
1601
|
+
* - 'KEY SHARE': FOR KEY SHARE (PostgreSQL only)
|
|
1602
|
+
* - { of: Model }: Lock only the specified table (PostgreSQL)
|
|
1603
|
+
*
|
|
1604
|
+
* @example
|
|
1605
|
+
* // Lock all rows with FOR UPDATE
|
|
1606
|
+
* User.findAll({ lock: 'UPDATE' })
|
|
1607
|
+
*
|
|
1608
|
+
* // Lock with transaction-level FOR UPDATE
|
|
1609
|
+
* User.findAll({ lock: true, transaction: t })
|
|
1610
|
+
*
|
|
1611
|
+
* // Lock only the User table (PostgreSQL)
|
|
1612
|
+
* User.findAll({ lock: { of: User } })
|
|
1613
|
+
*/
|
|
1614
|
+
lock?: LockOptions;
|
|
1615
|
+
benchmark?: boolean;
|
|
1616
|
+
logging?: boolean | ((sql: string, time?: number) => void);
|
|
1617
|
+
benchmarkMark?: string;
|
|
1618
|
+
/**
|
|
1619
|
+
* When true, includes soft-deleted records in query results.
|
|
1620
|
+
* When false or undefined, excludes soft-deleted records (default behavior for paranoid models).
|
|
1621
|
+
* @default false
|
|
1622
|
+
*/
|
|
1623
|
+
paranoid?: boolean;
|
|
1624
|
+
/**
|
|
1625
|
+
* UNION type for combining multiple queries
|
|
1626
|
+
* @default 'UNION'
|
|
1627
|
+
*/
|
|
1628
|
+
unionType?: UnionType;
|
|
1629
|
+
/**
|
|
1630
|
+
* Array of union queries to combine with the main query
|
|
1631
|
+
*/
|
|
1632
|
+
union?: UnionQueryOptions[];
|
|
1633
|
+
/**
|
|
1634
|
+
* Subquery support - allows using literal SQL in where clauses
|
|
1635
|
+
* Usage: { id: { [Op.in]: prorm.literal('(SELECT id FROM users)') } }
|
|
1636
|
+
*/
|
|
1637
|
+
subQuery?: boolean;
|
|
1638
|
+
/**
|
|
1639
|
+
* Whether to use subquery for includes.
|
|
1640
|
+
* When false, uses JOIN instead of IN (SELECT) for includes.
|
|
1641
|
+
* When true (default), uses subquery IN pattern for includes.
|
|
1642
|
+
* @default true
|
|
1643
|
+
* @example
|
|
1644
|
+
* // Use JOIN instead of IN (SELECT)
|
|
1645
|
+
* const users = await User.findAll({
|
|
1646
|
+
* include: [{ model: Post, where: { status: 'published' } }],
|
|
1647
|
+
* subquery: false
|
|
1648
|
+
* });
|
|
1649
|
+
* @example
|
|
1650
|
+
* // Use subquery IN pattern (default)
|
|
1651
|
+
* const users = await User.findAll({
|
|
1652
|
+
* include: [{ model: Post, where: { status: 'published' } }],
|
|
1653
|
+
* subquery: true
|
|
1654
|
+
* });
|
|
1655
|
+
*/
|
|
1656
|
+
subquery?: boolean;
|
|
1657
|
+
/**
|
|
1658
|
+
* When true, applies DISTINCT to the query to remove duplicate rows.
|
|
1659
|
+
* Useful when using aggregate functions with includes that may cause duplicates.
|
|
1660
|
+
* @default undefined
|
|
1661
|
+
* @example
|
|
1662
|
+
* // Count distinct users with posts
|
|
1663
|
+
* const count = await User.count({ distinct: true, include: Post })
|
|
1664
|
+
*/
|
|
1665
|
+
distinct?: boolean;
|
|
1666
|
+
/**
|
|
1667
|
+
* Common Table Expressions (CTEs) to use in the query
|
|
1668
|
+
* Supports both regular WITH and WITH RECURSIVE
|
|
1669
|
+
* @example
|
|
1670
|
+
* // Simple CTE
|
|
1671
|
+
* cte: [{ name: 'active_users', query: 'SELECT * FROM users WHERE active = true' }]
|
|
1672
|
+
* @example
|
|
1673
|
+
* // Recursive CTE for hierarchy
|
|
1674
|
+
* cte: [{
|
|
1675
|
+
* name: 'org_chart',
|
|
1676
|
+
* columns: ['id', 'name', 'manager_id'],
|
|
1677
|
+
* query: `SELECT id, name, manager_id FROM employees WHERE manager_id IS NULL
|
|
1678
|
+
* UNION ALL
|
|
1679
|
+
* SELECT e.id, e.name, e.manager_id FROM employees e
|
|
1680
|
+
* INNER JOIN org_chart o ON e.manager_id = o.id`,
|
|
1681
|
+
* recursive: true
|
|
1682
|
+
* }]
|
|
1683
|
+
*/
|
|
1684
|
+
cte?: CTEOptions[];
|
|
1685
|
+
/**
|
|
1686
|
+
* Enable streaming results for large datasets
|
|
1687
|
+
* When true, returns a ReadableStream instead of waiting for all results
|
|
1688
|
+
* @default false
|
|
1689
|
+
*/
|
|
1690
|
+
stream?: boolean;
|
|
1691
|
+
/**
|
|
1692
|
+
* Batch size for streaming results
|
|
1693
|
+
* @default 1000
|
|
1694
|
+
*/
|
|
1695
|
+
streamBatchSize?: number;
|
|
1696
|
+
/**
|
|
1697
|
+
* Transform function to apply to each record during streaming
|
|
1698
|
+
*/
|
|
1699
|
+
transform?: (record: any) => any;
|
|
1700
|
+
/**
|
|
1701
|
+
* High watermark for the stream (internal buffer size)
|
|
1702
|
+
* @default 1000
|
|
1703
|
+
*/
|
|
1704
|
+
streamHighWatermark?: number;
|
|
1705
|
+
}
|
|
1706
|
+
export interface FindOrCreateOptions<T = any> extends FindOptions {
|
|
1707
|
+
/** Default values to use when creating a new record if not found */
|
|
1708
|
+
defaults?: Partial<T>;
|
|
1709
|
+
/** Whether to run beforeCreate/afterCreate hooks (default: true) */
|
|
1710
|
+
hooks?: boolean;
|
|
1711
|
+
/** Whether to validate the model before creation (default: true) */
|
|
1712
|
+
validate?: boolean;
|
|
1713
|
+
}
|
|
1714
|
+
export type Order = OrderItem[] | string | [string, string][] | import('../operators').OrderExpression[];
|
|
1715
|
+
/**
|
|
1716
|
+
* Options for JSON path extraction
|
|
1717
|
+
*/
|
|
1718
|
+
export interface JsonPathOptions {
|
|
1719
|
+
/** The JSON path to extract (e.g., '$.settings.theme' or 'settings.theme') */
|
|
1720
|
+
path: string;
|
|
1721
|
+
/** Optional value to compare against the extracted path */
|
|
1722
|
+
value?: any;
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Options for JSON contains operation
|
|
1726
|
+
*/
|
|
1727
|
+
export interface JsonContainsOptions {
|
|
1728
|
+
/** The value or object that should be contained in the JSON column */
|
|
1729
|
+
value: any;
|
|
1730
|
+
/** Optional JSON path to check for containment at a specific location */
|
|
1731
|
+
path?: string;
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Options for JSON has key operation
|
|
1735
|
+
*/
|
|
1736
|
+
export interface JsonHasKeyOptions {
|
|
1737
|
+
/** The key to check for existence */
|
|
1738
|
+
key: string;
|
|
1739
|
+
/** Whether to check for all keys (true) or any key (false) */
|
|
1740
|
+
checkAll?: boolean;
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Legacy OrderItem interface (kept for backward compatibility)
|
|
1744
|
+
*/
|
|
1745
|
+
export interface OrderItem {
|
|
1746
|
+
0: ModelStatic<any> | string;
|
|
1747
|
+
1?: string;
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Geometry type for spatial data
|
|
1751
|
+
*/
|
|
1752
|
+
export type GeometryType = 'POINT' | 'LINESTRING' | 'POLYGON' | 'MULTIPOINT' | 'MULTILINESTRING' | 'MULTIPOLYGON' | 'GEOMETRYCOLLECTION' | 'GEOMETRY';
|
|
1753
|
+
/**
|
|
1754
|
+
* Options for GeoJSON input/output
|
|
1755
|
+
*/
|
|
1756
|
+
export interface GeoJSONOptions {
|
|
1757
|
+
/** Output as GeoJSON */
|
|
1758
|
+
asGeoJSON?: boolean;
|
|
1759
|
+
/** Input is GeoJSON */
|
|
1760
|
+
fromGeoJSON?: boolean;
|
|
1761
|
+
/** SRID for the geometry (default: 4326 for WGS84) */
|
|
1762
|
+
srid?: number;
|
|
1763
|
+
/** Geometry type if creating */
|
|
1764
|
+
type?: GeometryType;
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Options for distance calculations
|
|
1768
|
+
*/
|
|
1769
|
+
export interface DistanceOptions {
|
|
1770
|
+
/** The point/geometry to measure distance from */
|
|
1771
|
+
from: string | {
|
|
1772
|
+
type: GeometryType;
|
|
1773
|
+
coordinates: number[];
|
|
1774
|
+
};
|
|
1775
|
+
/** The maximum distance (in meters for geography, units depend on CRS for geometry) */
|
|
1776
|
+
distance: number;
|
|
1777
|
+
/** Use spheroidal calculation (PostgreSQL geography, default: true) */
|
|
1778
|
+
spheroid?: boolean;
|
|
1779
|
+
/** SRID for the calculation (default: 4326) */
|
|
1780
|
+
srid?: number;
|
|
1781
|
+
}
|
|
1782
|
+
/**
|
|
1783
|
+
* Options for within/contains queries
|
|
1784
|
+
*/
|
|
1785
|
+
export interface WithinOptions {
|
|
1786
|
+
/** The geometry to check against */
|
|
1787
|
+
geometry: string | {
|
|
1788
|
+
type: GeometryType;
|
|
1789
|
+
coordinates: number[];
|
|
1790
|
+
};
|
|
1791
|
+
/** SRID for the geometry (default: 4326) */
|
|
1792
|
+
srid?: number;
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Options for intersects/crosses/overlaps queries
|
|
1796
|
+
*/
|
|
1797
|
+
export interface IntersectsOptions {
|
|
1798
|
+
/** The geometry to check against */
|
|
1799
|
+
geometry: string | {
|
|
1800
|
+
type: GeometryType;
|
|
1801
|
+
coordinates: number[];
|
|
1802
|
+
};
|
|
1803
|
+
/** SRID for the geometry (default: 4326) */
|
|
1804
|
+
srid?: number;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Options for DWithin (distance within) queries
|
|
1808
|
+
*/
|
|
1809
|
+
export interface DWithinOptions {
|
|
1810
|
+
/** The point/geometry to measure distance from */
|
|
1811
|
+
from: string | {
|
|
1812
|
+
type: GeometryType;
|
|
1813
|
+
coordinates: number[];
|
|
1814
|
+
};
|
|
1815
|
+
/** The maximum distance */
|
|
1816
|
+
distance: number;
|
|
1817
|
+
/** Use spheroidal calculation (PostgreSQL geography, default: true) */
|
|
1818
|
+
spheroid?: boolean;
|
|
1819
|
+
/** SRID (default: 4326) */
|
|
1820
|
+
srid?: number;
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* GROUP BY clause format
|
|
1824
|
+
*/
|
|
1825
|
+
export type GroupBy = string | string[] | GroupByItem[];
|
|
1826
|
+
export interface GroupByItem {
|
|
1827
|
+
model?: ModelStatic<any>;
|
|
1828
|
+
as?: string;
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Lock types for row-level locking
|
|
1832
|
+
* - 'UPDATE': FOR UPDATE (PostgreSQL/MySQL) - prevents other transactions from modifying the rows
|
|
1833
|
+
* - 'SHARE': FOR SHARE (PostgreSQL) / LOCK IN SHARE MODE (MySQL) - allows other transactions to read but not modify
|
|
1834
|
+
* - 'KEY SHARE': FOR KEY SHARE (PostgreSQL only) - prevents key updates but allows row updates
|
|
1835
|
+
*/
|
|
1836
|
+
export declare enum LockLevel {
|
|
1837
|
+
Share = "SHARE",
|
|
1838
|
+
Update = "UPDATE",
|
|
1839
|
+
KeyShare = "KEY SHARE"
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Lock types for row-level locking
|
|
1843
|
+
*
|
|
1844
|
+
* Accepts either the raw string literals or the equivalent {@link LockLevel} enum member.
|
|
1845
|
+
*/
|
|
1846
|
+
export type LockType = 'SHARE' | 'UPDATE' | 'KEY SHARE' | LockLevel;
|
|
1847
|
+
/**
|
|
1848
|
+
* Lock options for row-level locking
|
|
1849
|
+
* @example
|
|
1850
|
+
* // Lock all rows with FOR UPDATE
|
|
1851
|
+
* User.findAll({ lock: 'UPDATE' })
|
|
1852
|
+
*
|
|
1853
|
+
* // Lock with transaction-level FOR UPDATE
|
|
1854
|
+
* User.findAll({ lock: true, transaction: t })
|
|
1855
|
+
*
|
|
1856
|
+
* // Lock only the User table (PostgreSQL)
|
|
1857
|
+
* User.findAll({ lock: { of: User } })
|
|
1858
|
+
*
|
|
1859
|
+
* // NOWAIT - return error if lock not available (PostgreSQL/MySQL 8.0+)
|
|
1860
|
+
* User.findAll({ lock: { level: 'UPDATE', nowait: true } })
|
|
1861
|
+
*
|
|
1862
|
+
* // SKIP LOCKED - skip locked rows (PostgreSQL/MySQL 8.0+)
|
|
1863
|
+
* User.findAll({ lock: { level: 'UPDATE', skipLocked: true } })
|
|
1864
|
+
*/
|
|
1865
|
+
export type LockOptions = LockType | boolean | {
|
|
1866
|
+
of: ModelStatic<any>;
|
|
1867
|
+
} | {
|
|
1868
|
+
level?: LockType;
|
|
1869
|
+
nowait?: boolean;
|
|
1870
|
+
skipLocked?: boolean;
|
|
1871
|
+
of?: ModelStatic<any>;
|
|
1872
|
+
};
|
|
1873
|
+
/**
|
|
1874
|
+
* Options for NOWAIT locking (PostgreSQL/MySQL 8.0+)
|
|
1875
|
+
* Causes the database to return an error instead of waiting for a lock
|
|
1876
|
+
*/
|
|
1877
|
+
export interface NowaitOptions {
|
|
1878
|
+
nowait: true;
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Options for SKIP LOCKED locking (PostgreSQL/MySQL 8.0+)
|
|
1882
|
+
* Causes the database to skip rows that are locked instead of waiting
|
|
1883
|
+
*/
|
|
1884
|
+
export interface SkipLockedOptions {
|
|
1885
|
+
skipLocked: true;
|
|
1886
|
+
}
|
|
1887
|
+
export interface Includeable {
|
|
1888
|
+
/** The model to include */
|
|
1889
|
+
model: ModelStatic<any>;
|
|
1890
|
+
/**
|
|
1891
|
+
* Alias for the included model.
|
|
1892
|
+
* Used as:
|
|
1893
|
+
* - The key in result objects (e.g., user.myPosts instead of user.Posts)
|
|
1894
|
+
* - The base name for association methods (e.g., user.getMyPosts(), user.setMyPosts())
|
|
1895
|
+
* - The table alias in SQL JOINs
|
|
1896
|
+
*
|
|
1897
|
+
* @example
|
|
1898
|
+
* // With 'as' alias
|
|
1899
|
+
* User.findAll({
|
|
1900
|
+
* include: [{ model: Post, as: 'myPosts' }]
|
|
1901
|
+
* })
|
|
1902
|
+
* // Result: { id: 1, name: 'John', myPosts: [...] }
|
|
1903
|
+
*
|
|
1904
|
+
* // Without 'as' - defaults to model name
|
|
1905
|
+
* User.findAll({
|
|
1906
|
+
* include: [{ model: Post }]
|
|
1907
|
+
* })
|
|
1908
|
+
* // Result: { id: 1, name: 'John', Posts: [...] }
|
|
1909
|
+
*/
|
|
1910
|
+
as?: string;
|
|
1911
|
+
}
|
|
1912
|
+
export interface IncludeOptions extends Includeable {
|
|
1913
|
+
where?: WhereOptions;
|
|
1914
|
+
attributes?: string[] | {
|
|
1915
|
+
include?: string[];
|
|
1916
|
+
exclude?: string[];
|
|
1917
|
+
};
|
|
1918
|
+
/** Schema to use for the included model */
|
|
1919
|
+
schema?: string;
|
|
1920
|
+
required?: boolean;
|
|
1921
|
+
/**
|
|
1922
|
+
* For many-to-many (belongsToMany) relationships, specify the junction table model.
|
|
1923
|
+
* This is required when including models through a join table.
|
|
1924
|
+
*/
|
|
1925
|
+
through?: {
|
|
1926
|
+
/** The junction/through model */
|
|
1927
|
+
model?: ModelStatic<any>;
|
|
1928
|
+
/** Alias for the through model in SQL */
|
|
1929
|
+
as?: string;
|
|
1930
|
+
/** Attributes to include from the through model */
|
|
1931
|
+
attributes?: string[] | {
|
|
1932
|
+
include?: string[];
|
|
1933
|
+
exclude?: string[];
|
|
1934
|
+
};
|
|
1935
|
+
/** Where conditions on the through model */
|
|
1936
|
+
where?: WhereOptions;
|
|
1937
|
+
/** Whether to require the join (INNER JOIN vs LEFT JOIN) */
|
|
1938
|
+
required?: boolean;
|
|
1939
|
+
};
|
|
1940
|
+
on?: WhereOptions;
|
|
1941
|
+
order?: Order;
|
|
1942
|
+
limit?: number;
|
|
1943
|
+
offset?: number;
|
|
1944
|
+
paranoid?: boolean;
|
|
1945
|
+
/** When true, includes nested associations recursively */
|
|
1946
|
+
nested?: boolean;
|
|
1947
|
+
/** Include all associations, or a string to filter by association name */
|
|
1948
|
+
all?: boolean | string;
|
|
1949
|
+
/** Ignore attributes from included models (default: true) */
|
|
1950
|
+
includeIgnoreAttributes?: boolean;
|
|
1951
|
+
/**
|
|
1952
|
+
* Custom foreign key for the join.
|
|
1953
|
+
* Can be a single string for simple foreign keys, or an array for composite foreign keys.
|
|
1954
|
+
* @example
|
|
1955
|
+
* foreignKey: 'userId' // Simple FK
|
|
1956
|
+
* foreignKey: ['orderId', 'customerId'] // Composite FK
|
|
1957
|
+
*/
|
|
1958
|
+
foreignKey?: string | string[] | {
|
|
1959
|
+
name?: string | string[];
|
|
1960
|
+
allowNull?: boolean;
|
|
1961
|
+
};
|
|
1962
|
+
/** Nested includes */
|
|
1963
|
+
include?: Includeable[] | IncludeOptions[];
|
|
1964
|
+
/** Whether to duplicate parent rows for each child (for hasMany) */
|
|
1965
|
+
duplicating?: boolean;
|
|
1966
|
+
/** Allow duplicate column names in the result. When true, uses table aliases to distinguish columns */
|
|
1967
|
+
duplicate?: boolean;
|
|
1968
|
+
/**
|
|
1969
|
+
* Target key for the association (defaults to primary key).
|
|
1970
|
+
* Can be a single string for simple keys, or an array for composite keys.
|
|
1971
|
+
* @example
|
|
1972
|
+
* targetKey: 'id' // Simple key
|
|
1973
|
+
* targetKey: ['id', 'customerId'] // Composite key
|
|
1974
|
+
*/
|
|
1975
|
+
targetKey?: string | string[];
|
|
1976
|
+
/**
|
|
1977
|
+
* Type of JOIN to use.
|
|
1978
|
+
* - 'INNER': INNER JOIN
|
|
1979
|
+
* - 'LEFT': LEFT JOIN (outer)
|
|
1980
|
+
* - 'RIGHT': RIGHT JOIN (outer)
|
|
1981
|
+
* - 'FULL': FULL OUTER JOIN
|
|
1982
|
+
* - 'CROSS': CROSS JOIN
|
|
1983
|
+
* @example
|
|
1984
|
+
* joinType: 'FULL' // Full outer join
|
|
1985
|
+
*/
|
|
1986
|
+
joinType?: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL' | 'CROSS';
|
|
1987
|
+
/**
|
|
1988
|
+
* Whether to use LATERAL JOIN (PostgreSQL only).
|
|
1989
|
+
* LATERAL allows subqueries to reference columns from preceding tables.
|
|
1990
|
+
* @example
|
|
1991
|
+
* lateral: true // LATERAL JOIN
|
|
1992
|
+
*/
|
|
1993
|
+
lateral?: boolean;
|
|
1994
|
+
/**
|
|
1995
|
+
* Whether to use anti-join pattern (NOT EXISTS or LEFT JOIN WHERE NULL).
|
|
1996
|
+
* This finds records that do not have related records in the included model.
|
|
1997
|
+
* @example
|
|
1998
|
+
* // Find users with no orders
|
|
1999
|
+
* User.findAll({
|
|
2000
|
+
* include: [{ model: Order, antiJoin: true }]
|
|
2001
|
+
* })
|
|
2002
|
+
* // SQL: SELECT users.* FROM users LEFT JOIN orders ON users.id = orders.user_id WHERE orders.id IS NULL
|
|
2003
|
+
*/
|
|
2004
|
+
antiJoin?: boolean;
|
|
2005
|
+
/**
|
|
2006
|
+
* Alias for antiJoin - when true, uses anti-join pattern.
|
|
2007
|
+
* @example
|
|
2008
|
+
* // Find users that are NOT in the banned_users table
|
|
2009
|
+
* User.findAll({
|
|
2010
|
+
* include: [{ model: BannedUser, exclude: true }]
|
|
2011
|
+
* })
|
|
2012
|
+
*/
|
|
2013
|
+
exclude?: boolean;
|
|
2014
|
+
/**
|
|
2015
|
+
* Type of anti-join to use.
|
|
2016
|
+
* - 'notExists': Uses NOT EXISTS subquery pattern
|
|
2017
|
+
* - 'notIn': Uses NOT IN subquery pattern
|
|
2018
|
+
* - 'leftJoinIsNull': Uses LEFT JOIN WHERE NULL pattern (default)
|
|
2019
|
+
* @example
|
|
2020
|
+
* // Find users with no orders using NOT EXISTS
|
|
2021
|
+
* User.findAll({
|
|
2022
|
+
* include: [{ model: Order, antiJoin: true, antiJoinType: 'notExists' }]
|
|
2023
|
+
* })
|
|
2024
|
+
*/
|
|
2025
|
+
antiJoinType?: 'notExists' | 'notIn' | 'leftJoinIsNull';
|
|
2026
|
+
/**
|
|
2027
|
+
* Whether to use CROSS APPLY or OUTER APPLY (SQL Server only).
|
|
2028
|
+
* - 'CROSS': CROSS APPLY - returns only matching rows
|
|
2029
|
+
* - 'OUTER': OUTER APPLY - returns all rows from left table (like LEFT JOIN)
|
|
2030
|
+
* @example
|
|
2031
|
+
* // SQL Server CROSS APPLY with a subquery
|
|
2032
|
+
* User.findAll({
|
|
2033
|
+
* include: [{
|
|
2034
|
+
* model: Order,
|
|
2035
|
+
* apply: 'CROSS',
|
|
2036
|
+
* where: { status: 'active' }
|
|
2037
|
+
* }]
|
|
2038
|
+
* })
|
|
2039
|
+
*/
|
|
2040
|
+
apply?: 'CROSS' | 'OUTER';
|
|
2041
|
+
/**
|
|
2042
|
+
* Inline lateral subquery for advanced use cases.
|
|
2043
|
+
* Allows defining an inline subquery that can reference columns from preceding tables.
|
|
2044
|
+
* @example
|
|
2045
|
+
* // PostgreSQL LATERAL subquery
|
|
2046
|
+
* User.findAll({
|
|
2047
|
+
* include: [{
|
|
2048
|
+
* lateralSubquery: {
|
|
2049
|
+
* model: Order,
|
|
2050
|
+
* where: { status: 'active' },
|
|
2051
|
+
* attributes: ['id', 'total']
|
|
2052
|
+
* }
|
|
2053
|
+
* }]
|
|
2054
|
+
* })
|
|
2055
|
+
*/
|
|
2056
|
+
lateralSubquery?: {
|
|
2057
|
+
/** The model for the lateral subquery */
|
|
2058
|
+
model: ModelStatic<any>;
|
|
2059
|
+
/** WHERE conditions on the subquery */
|
|
2060
|
+
where?: WhereOptions;
|
|
2061
|
+
/** Attributes to select from the subquery */
|
|
2062
|
+
attributes?: string[] | {
|
|
2063
|
+
include?: string[];
|
|
2064
|
+
exclude?: string[];
|
|
2065
|
+
};
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
/**
|
|
2069
|
+
* Options for anti-join queries
|
|
2070
|
+
* Used to find records that do not have related records
|
|
2071
|
+
*/
|
|
2072
|
+
export interface AntiJoinOptions {
|
|
2073
|
+
/** The model to check for absence of related records */
|
|
2074
|
+
model: ModelStatic<any>;
|
|
2075
|
+
/** Alias for the included model */
|
|
2076
|
+
as?: string;
|
|
2077
|
+
/** WHERE conditions on the related model (must NOT exist for anti-join) */
|
|
2078
|
+
where?: WhereOptions;
|
|
2079
|
+
/** Custom foreign key for the join */
|
|
2080
|
+
foreignKey?: string | string[] | {
|
|
2081
|
+
name?: string | string[];
|
|
2082
|
+
allowNull?: boolean;
|
|
2083
|
+
};
|
|
2084
|
+
/** Target key (defaults to primary key) */
|
|
2085
|
+
targetKey?: string | string[];
|
|
2086
|
+
/**
|
|
2087
|
+
* Type of anti-join to use.
|
|
2088
|
+
* - 'notExists': Uses NOT EXISTS subquery pattern
|
|
2089
|
+
* - 'notIn': Uses NOT IN subquery pattern
|
|
2090
|
+
* - 'leftJoinIsNull': Uses LEFT JOIN WHERE NULL pattern (default)
|
|
2091
|
+
*/
|
|
2092
|
+
type?: 'notExists' | 'notIn' | 'leftJoinIsNull';
|
|
2093
|
+
}
|
|
2094
|
+
export interface CreateOptions extends SaveOptions {
|
|
2095
|
+
include?: Includeable[] | IncludeOptions[];
|
|
2096
|
+
ignoreDuplicates?: boolean;
|
|
2097
|
+
validate?: boolean;
|
|
2098
|
+
fields?: string[];
|
|
2099
|
+
returning?: boolean | string[];
|
|
2100
|
+
raw?: boolean;
|
|
2101
|
+
isNewRecord?: boolean;
|
|
2102
|
+
/**
|
|
2103
|
+
* Connection name to use for this query
|
|
2104
|
+
* Allows querying a different database connection
|
|
2105
|
+
*/
|
|
2106
|
+
using?: string;
|
|
2107
|
+
}
|
|
2108
|
+
export interface UpdateOptions extends SaveOptions {
|
|
2109
|
+
where: WhereOptions;
|
|
2110
|
+
limit?: number;
|
|
2111
|
+
validate?: boolean;
|
|
2112
|
+
fields?: string[];
|
|
2113
|
+
returning?: boolean | string[];
|
|
2114
|
+
sideEffects?: boolean;
|
|
2115
|
+
omitNull?: boolean;
|
|
2116
|
+
hooks?: boolean;
|
|
2117
|
+
individualHooks?: boolean;
|
|
2118
|
+
benchmark?: boolean;
|
|
2119
|
+
logging?: boolean | ((sql: string, time?: number) => void);
|
|
2120
|
+
/**
|
|
2121
|
+
* Connection name to use for this query
|
|
2122
|
+
* Allows querying a different database connection
|
|
2123
|
+
*/
|
|
2124
|
+
using?: string;
|
|
2125
|
+
}
|
|
2126
|
+
export interface DestroyOptions extends HookOptions {
|
|
2127
|
+
where: WhereOptions;
|
|
2128
|
+
limit?: number;
|
|
2129
|
+
truncate?: boolean;
|
|
2130
|
+
cascade?: boolean;
|
|
2131
|
+
force?: boolean;
|
|
2132
|
+
restartIdentity?: boolean;
|
|
2133
|
+
returning?: boolean | string[];
|
|
2134
|
+
/**
|
|
2135
|
+
* When false, performs a soft delete by setting deletedAt instead of actually deleting
|
|
2136
|
+
* When true, actually deletes the record (bypasses paranoid mode)
|
|
2137
|
+
* @default false
|
|
2138
|
+
*/
|
|
2139
|
+
paranoid?: boolean;
|
|
2140
|
+
/** Logging options for the query */
|
|
2141
|
+
logging?: boolean | ((sql: string, time?: number) => void);
|
|
2142
|
+
/**
|
|
2143
|
+
* Connection name to use for this query
|
|
2144
|
+
* Allows querying a different database connection
|
|
2145
|
+
*/
|
|
2146
|
+
using?: string;
|
|
2147
|
+
}
|
|
2148
|
+
export interface SaveOptions {
|
|
2149
|
+
transaction?: Transaction;
|
|
2150
|
+
hooks?: boolean;
|
|
2151
|
+
validate?: boolean;
|
|
2152
|
+
fields?: string[];
|
|
2153
|
+
sideEffects?: boolean;
|
|
2154
|
+
logging?: boolean | ((sql: string, time?: number) => void);
|
|
2155
|
+
benchmark?: boolean;
|
|
2156
|
+
}
|
|
2157
|
+
export interface ReloadOptions extends FindOptions {
|
|
2158
|
+
/**
|
|
2159
|
+
* Specify attributes to select when reloading from the database.
|
|
2160
|
+
* If not provided, all attributes will be selected.
|
|
2161
|
+
*/
|
|
2162
|
+
attributes?: string[];
|
|
2163
|
+
/**
|
|
2164
|
+
* Run beforeReload and afterReload hooks (default: true)
|
|
2165
|
+
*/
|
|
2166
|
+
hooks?: boolean;
|
|
2167
|
+
}
|
|
2168
|
+
export interface AssociationOptions {
|
|
2169
|
+
as?: string;
|
|
2170
|
+
/**
|
|
2171
|
+
* Foreign key field name(s) for the association.
|
|
2172
|
+
* Can be a single string for simple foreign keys, or an array for composite foreign keys.
|
|
2173
|
+
* @example
|
|
2174
|
+
* foreignKey: 'userId' // Simple FK
|
|
2175
|
+
* foreignKey: ['orderId', 'customerId'] // Composite FK
|
|
2176
|
+
*/
|
|
2177
|
+
foreignKey?: string | string[] | AssociationForeignKeyOptions;
|
|
2178
|
+
/**
|
|
2179
|
+
* Source key(s) on the source model (the model defining the association).
|
|
2180
|
+
* Defaults to the primary key.
|
|
2181
|
+
* @example
|
|
2182
|
+
* sourceKey: 'id' // Simple key
|
|
2183
|
+
* sourceKey: ['id', 'tenantId'] // Composite key
|
|
2184
|
+
*/
|
|
2185
|
+
sourceKey?: string | string[];
|
|
2186
|
+
/**
|
|
2187
|
+
* Target key(s) on the target model (the model being associated).
|
|
2188
|
+
* Defaults to the primary key.
|
|
2189
|
+
* @example
|
|
2190
|
+
* targetKey: 'id' // Simple key
|
|
2191
|
+
* targetKey: ['id', 'customerId'] // Composite key
|
|
2192
|
+
*/
|
|
2193
|
+
targetKey?: string | string[];
|
|
2194
|
+
constraints?: boolean;
|
|
2195
|
+
/**
|
|
2196
|
+
* Referential action to take when the referenced row is deleted.
|
|
2197
|
+
* @example
|
|
2198
|
+
* onDelete: ReferentialAction.Cascade // or onDelete: 'CASCADE'
|
|
2199
|
+
*/
|
|
2200
|
+
onDelete?: ReferentialAction | 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT';
|
|
2201
|
+
/**
|
|
2202
|
+
* Referential action to take when the referenced row's key is updated.
|
|
2203
|
+
* @example
|
|
2204
|
+
* onUpdate: ReferentialAction.Cascade // or onUpdate: 'CASCADE'
|
|
2205
|
+
*/
|
|
2206
|
+
onUpdate?: ReferentialAction | 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT';
|
|
2207
|
+
foreignKeyConstraint?: boolean;
|
|
2208
|
+
through?: string | ThroughOptions;
|
|
2209
|
+
scope?: AssociationScope;
|
|
2210
|
+
}
|
|
2211
|
+
export interface AssociationForeignKeyOptions {
|
|
2212
|
+
/** Custom name for the foreign key constraint */
|
|
2213
|
+
name?: string;
|
|
2214
|
+
/** Allow null values in the foreign key column(s) */
|
|
2215
|
+
allowNull?: boolean;
|
|
2216
|
+
/** Validation options for the foreign key column */
|
|
2217
|
+
validate?: ModelValidationOptions;
|
|
2218
|
+
/**
|
|
2219
|
+
* Composite foreign key - array of field names that make up the composite key.
|
|
2220
|
+
* This is used when the foreign key consists of multiple columns.
|
|
2221
|
+
* @example
|
|
2222
|
+
* compositeKey: ['orderId', 'customerId']
|
|
2223
|
+
*/
|
|
2224
|
+
compositeKey?: string[];
|
|
2225
|
+
/** Custom constraint name for the foreign key (alternative to 'name') */
|
|
2226
|
+
constraintName?: string;
|
|
2227
|
+
}
|
|
2228
|
+
export interface ThroughOptions {
|
|
2229
|
+
model: string | ModelStatic<any>;
|
|
2230
|
+
as?: string;
|
|
2231
|
+
foreignKey?: string | AssociationForeignKeyOptions;
|
|
2232
|
+
otherKey?: string | AssociationForeignKeyOptions;
|
|
2233
|
+
scope?: AssociationScope;
|
|
2234
|
+
timestamps?: boolean;
|
|
2235
|
+
}
|
|
2236
|
+
export interface AssociationScope {
|
|
2237
|
+
[key: string]: any;
|
|
2238
|
+
}
|
|
2239
|
+
/**
|
|
2240
|
+
* Transaction class
|
|
2241
|
+
*/
|
|
2242
|
+
export declare class Transaction {
|
|
2243
|
+
id: string;
|
|
2244
|
+
finished: boolean;
|
|
2245
|
+
options: TransactionOptions;
|
|
2246
|
+
parent: Transaction | null;
|
|
2247
|
+
savepoints: string[];
|
|
2248
|
+
constructor(options?: TransactionOptions);
|
|
2249
|
+
commit(): Promise<void>;
|
|
2250
|
+
rollback(): Promise<void>;
|
|
2251
|
+
}
|
|
2252
|
+
export interface TransactionOptions {
|
|
2253
|
+
autocommit?: boolean;
|
|
2254
|
+
/**
|
|
2255
|
+
* ANSI SQL transaction isolation level. Accepts either the `IsolationLevel`
|
|
2256
|
+
* enum or the equivalent raw string literal (kept for backwards
|
|
2257
|
+
* compatibility with existing callers). Dialect-specific native values
|
|
2258
|
+
* that aren't part of the ANSI set (e.g. Db2's `UR`/`CS`/`RS`/`RR`
|
|
2259
|
+
* abbreviations or MSSQL's `SNAPSHOT`) are intentionally not part of the
|
|
2260
|
+
* `IsolationLevel` enum and continue to be accepted only as plain
|
|
2261
|
+
* strings by the dialects that support them.
|
|
2262
|
+
* @example
|
|
2263
|
+
* { isolationLevel: 'SERIALIZABLE' }
|
|
2264
|
+
* @example
|
|
2265
|
+
* { isolationLevel: IsolationLevel.Serializable }
|
|
2266
|
+
*/
|
|
2267
|
+
isolationLevel?: IsolationLevel | IsolationLevelString;
|
|
2268
|
+
type?: 'DEFERRED' | 'IMMEDIATE' | 'EXCLUSIVE';
|
|
2269
|
+
deferrable?: string;
|
|
2270
|
+
/**
|
|
2271
|
+
* Lock level for all queries within the transaction
|
|
2272
|
+
* - true: FOR UPDATE (equivalent to 'UPDATE')
|
|
2273
|
+
* - 'UPDATE': FOR UPDATE
|
|
2274
|
+
* - 'SHARE': FOR SHARE (PostgreSQL) / LOCK IN SHARE MODE (MySQL)
|
|
2275
|
+
* - 'KEY SHARE': FOR KEY SHARE (PostgreSQL only)
|
|
2276
|
+
* - { of: Model }: Lock only the specified table (PostgreSQL)
|
|
2277
|
+
*/
|
|
2278
|
+
lock?: LockOptions;
|
|
2279
|
+
}
|
|
2280
|
+
/**
|
|
2281
|
+
* ANSI SQL transaction isolation levels expressed as a string-literal union.
|
|
2282
|
+
* Kept as a standalone export (in addition to the `IsolationLevel` enum
|
|
2283
|
+
* below) so existing code that passes raw strings such as
|
|
2284
|
+
* `{ isolationLevel: 'SERIALIZABLE' }` keeps compiling without changes.
|
|
2285
|
+
*/
|
|
2286
|
+
export type IsolationLevelString = 'READ UNCOMMITTED' | 'READ COMMITTED' | 'REPEATABLE READ' | 'SERIALIZABLE';
|
|
2287
|
+
/**
|
|
2288
|
+
* ANSI SQL transaction isolation levels.
|
|
2289
|
+
*
|
|
2290
|
+
* This is a companion enum for `IsolationLevelString` / the
|
|
2291
|
+
* `TransactionOptions.isolationLevel` field. The field accepts both this
|
|
2292
|
+
* enum and the raw string literals for backwards compatibility, so either
|
|
2293
|
+
* of the following work:
|
|
2294
|
+
* @example
|
|
2295
|
+
* transaction.start({ isolationLevel: 'SERIALIZABLE' });
|
|
2296
|
+
* @example
|
|
2297
|
+
* transaction.start({ isolationLevel: IsolationLevel.Serializable });
|
|
2298
|
+
*/
|
|
2299
|
+
export declare enum IsolationLevel {
|
|
2300
|
+
ReadUncommitted = "READ UNCOMMITTED",
|
|
2301
|
+
ReadCommitted = "READ COMMITTED",
|
|
2302
|
+
RepeatableRead = "REPEATABLE READ",
|
|
2303
|
+
Serializable = "SERIALIZABLE"
|
|
2304
|
+
}
|
|
2305
|
+
export interface ModelStatic<T extends Model> {
|
|
2306
|
+
name: string;
|
|
2307
|
+
tableName: string;
|
|
2308
|
+
/** Schema the model belongs to */
|
|
2309
|
+
schema?: string;
|
|
2310
|
+
rawAttributes: Record<string, AttributeOptions>;
|
|
2311
|
+
associations: Record<string, Association>;
|
|
2312
|
+
/** Static property indicating this is a model class (always false for static check) */
|
|
2313
|
+
isNewRecord: false;
|
|
2314
|
+
/**
|
|
2315
|
+
* Build a WHERE condition using operator symbols
|
|
2316
|
+
*
|
|
2317
|
+
* @example
|
|
2318
|
+
* // Simple equality
|
|
2319
|
+
* User.where('status', 'active')
|
|
2320
|
+
* // => { status: 'active' }
|
|
2321
|
+
*
|
|
2322
|
+
* // With operator
|
|
2323
|
+
* User.where('age', Op.gte, 18)
|
|
2324
|
+
* // => { age: { $gte: 18 } }
|
|
2325
|
+
*
|
|
2326
|
+
* // Using with findAll
|
|
2327
|
+
* User.findAll({ where: User.where('status', 'active') })
|
|
2328
|
+
*/
|
|
2329
|
+
where(field: string, operator: string | symbol | unknown, value?: unknown): WhereOptions;
|
|
2330
|
+
findOne(options?: FindOptions): Promise<T | null>;
|
|
2331
|
+
findAll(options?: FindOptions): Promise<T[]>;
|
|
2332
|
+
/**
|
|
2333
|
+
* Find all records matching the given options and return both rows and total count
|
|
2334
|
+
* @param findOptions - Options for the query including limit and offset for pagination
|
|
2335
|
+
* @returns Object with rows array and count total
|
|
2336
|
+
*
|
|
2337
|
+
* @example
|
|
2338
|
+
* // Basic find and count all
|
|
2339
|
+
* const result = await User.findAndCountAll();
|
|
2340
|
+
* console.log(result.count); // total number of matching records
|
|
2341
|
+
* console.log(result.rows); // array of model instances
|
|
2342
|
+
*
|
|
2343
|
+
* @example
|
|
2344
|
+
* // With pagination - get 10 records starting from record 20
|
|
2345
|
+
* const result = await User.findAndCountAll({
|
|
2346
|
+
* limit: 10,
|
|
2347
|
+
* offset: 20,
|
|
2348
|
+
* where: { status: 'active' }
|
|
2349
|
+
* });
|
|
2350
|
+
*
|
|
2351
|
+
* @example
|
|
2352
|
+
* // With subquery optimization
|
|
2353
|
+
* const result = await User.findAndCountAll({
|
|
2354
|
+
* include: [{ model: Post, where: { status: 'published' } }],
|
|
2355
|
+
* subquery: false
|
|
2356
|
+
* });
|
|
2357
|
+
*/
|
|
2358
|
+
findAndCountAll(options?: FindOptions): Promise<{
|
|
2359
|
+
rows: T[];
|
|
2360
|
+
count: number;
|
|
2361
|
+
}>;
|
|
2362
|
+
create(values?: Partial<T>, options?: CreateOptions): Promise<T>;
|
|
2363
|
+
update(values: Partial<T>, options: UpdateOptions): Promise<[number, T[]]>;
|
|
2364
|
+
destroy(options: DestroyOptions): Promise<number>;
|
|
2365
|
+
bulkDestroy(options: DestroyOptions): Promise<number>;
|
|
2366
|
+
/**
|
|
2367
|
+
* Restore soft-deleted records (set deletedAt to NULL)
|
|
2368
|
+
* @param options Restore options with where clause
|
|
2369
|
+
*/
|
|
2370
|
+
restore(options?: RestoreOptions & {
|
|
2371
|
+
where?: WhereOptions;
|
|
2372
|
+
}): Promise<number>;
|
|
2373
|
+
bulkRestore(options?: RestoreOptions & {
|
|
2374
|
+
where?: WhereOptions;
|
|
2375
|
+
}): Promise<number>;
|
|
2376
|
+
bulkCreate(records: Partial<T>[], options?: BulkCreateOptions): Promise<T[]>;
|
|
2377
|
+
count(options?: CountOptions): Promise<number>;
|
|
2378
|
+
avg(attribute: string, options?: AggregateOptions): Promise<number>;
|
|
2379
|
+
max(attribute: string, options?: AggregateOptions): Promise<any>;
|
|
2380
|
+
min(attribute: string, options?: AggregateOptions): Promise<any>;
|
|
2381
|
+
sum(attribute: string, options?: AggregateOptions & {
|
|
2382
|
+
distinct?: boolean;
|
|
2383
|
+
}): Promise<number>;
|
|
2384
|
+
/**
|
|
2385
|
+
* ROW_NUMBER() - Returns the row number within the partition
|
|
2386
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2387
|
+
* @returns The row number
|
|
2388
|
+
*
|
|
2389
|
+
* @example
|
|
2390
|
+
* // Get row numbers partitioned by category
|
|
2391
|
+
* const users = await User.findAll({
|
|
2392
|
+
* attributes: [[User.rowNumber({ partitionBy: 'department', orderBy: ['createdAt', 'DESC'] }), 'rowNum']]
|
|
2393
|
+
* });
|
|
2394
|
+
*/
|
|
2395
|
+
rowNumber(options: WindowFunctionOptions): number;
|
|
2396
|
+
/**
|
|
2397
|
+
* RANK() - Returns the rank of the current row within the partition (with gaps)
|
|
2398
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2399
|
+
* @returns The rank value
|
|
2400
|
+
*
|
|
2401
|
+
* @example
|
|
2402
|
+
* const users = await User.findAll({
|
|
2403
|
+
* attributes: [[User.rank({ orderBy: ['score', 'DESC'] }), 'rank']]
|
|
2404
|
+
* });
|
|
2405
|
+
*/
|
|
2406
|
+
rank(options: WindowFunctionOptions): number;
|
|
2407
|
+
/**
|
|
2408
|
+
* DENSE_RANK() - Returns the rank of the current row within the partition (without gaps)
|
|
2409
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2410
|
+
* @returns The dense rank value
|
|
2411
|
+
*
|
|
2412
|
+
* @example
|
|
2413
|
+
* const users = await User.findAll({
|
|
2414
|
+
* attributes: [[User.denseRank({ orderBy: ['score', 'DESC'] }), 'denseRank']]
|
|
2415
|
+
* });
|
|
2416
|
+
*/
|
|
2417
|
+
denseRank(options: WindowFunctionOptions): number;
|
|
2418
|
+
/**
|
|
2419
|
+
* LAG() - Returns the value from the preceding row in the partition
|
|
2420
|
+
* @param field - The field to get value from
|
|
2421
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2422
|
+
* @returns The value from the preceding row
|
|
2423
|
+
*
|
|
2424
|
+
* @example
|
|
2425
|
+
* const users = await User.findAll({
|
|
2426
|
+
* attributes: [[User.lag('salary', { partitionBy: 'department', orderBy: 'hireDate' }), 'prevSalary']]
|
|
2427
|
+
* });
|
|
2428
|
+
*/
|
|
2429
|
+
lag(field: string, options?: WindowFunctionOptions): any;
|
|
2430
|
+
/**
|
|
2431
|
+
* LEAD() - Returns the value from the following row in the partition
|
|
2432
|
+
* @param field - The field to get value from
|
|
2433
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2434
|
+
* @returns The value from the following row
|
|
2435
|
+
*
|
|
2436
|
+
* @example
|
|
2437
|
+
* const users = await User.findAll({
|
|
2438
|
+
* attributes: [[User.lead('salary', { partitionBy: 'department', orderBy: 'hireDate' }), 'nextSalary']]
|
|
2439
|
+
* });
|
|
2440
|
+
*/
|
|
2441
|
+
lead(field: string, options?: WindowFunctionOptions): any;
|
|
2442
|
+
/**
|
|
2443
|
+
* FIRST_VALUE() - Returns the first value in the partition
|
|
2444
|
+
* @param field - The field to get first value from
|
|
2445
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2446
|
+
* @returns The first value in the partition
|
|
2447
|
+
*
|
|
2448
|
+
* @example
|
|
2449
|
+
* const users = await User.findAll({
|
|
2450
|
+
* attributes: [[User.firstValue('salary', { partitionBy: 'department', orderBy: 'hireDate' }), 'firstSalary']]
|
|
2451
|
+
* });
|
|
2452
|
+
*/
|
|
2453
|
+
firstValue(field: string, options?: WindowFunctionOptions): any;
|
|
2454
|
+
/**
|
|
2455
|
+
* LAST_VALUE() - Returns the last value in the partition
|
|
2456
|
+
* @param field - The field to get last value from
|
|
2457
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2458
|
+
* @returns The last value in the partition
|
|
2459
|
+
*
|
|
2460
|
+
* @example
|
|
2461
|
+
* const users = await User.findAll({
|
|
2462
|
+
* attributes: [[User.lastValue('salary', { partitionBy: 'department', orderBy: 'hireDate' }), 'lastSalary']]
|
|
2463
|
+
* });
|
|
2464
|
+
*/
|
|
2465
|
+
lastValue(field: string, options?: WindowFunctionOptions): any;
|
|
2466
|
+
/**
|
|
2467
|
+
* NTH_VALUE() - Returns the nth value in the partition
|
|
2468
|
+
* @param field - The field to get nth value from
|
|
2469
|
+
* @param n - The position (1-based)
|
|
2470
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2471
|
+
* @returns The nth value in the partition
|
|
2472
|
+
*
|
|
2473
|
+
* @example
|
|
2474
|
+
* const users = await User.findAll({
|
|
2475
|
+
* attributes: [[User.nthValue('salary', 2, { partitionBy: 'department', orderBy: 'hireDate' }), 'secondSalary']]
|
|
2476
|
+
* });
|
|
2477
|
+
*/
|
|
2478
|
+
nthValue(field: string, n: number, options?: WindowFunctionOptions): any;
|
|
2479
|
+
/**
|
|
2480
|
+
* NTILE() - Distributes rows into n buckets
|
|
2481
|
+
* @param n - Number of buckets
|
|
2482
|
+
* @param options - Window function options (partitionBy, orderBy)
|
|
2483
|
+
* @returns The bucket number (1 to n)
|
|
2484
|
+
*
|
|
2485
|
+
* @example
|
|
2486
|
+
* const users = await User.findAll({
|
|
2487
|
+
* attributes: [[User.ntile(4, { partitionBy: 'department', orderBy: 'salary' }), 'quartile']]
|
|
2488
|
+
* });
|
|
2489
|
+
*/
|
|
2490
|
+
ntile(n: number, options?: WindowFunctionOptions): any;
|
|
2491
|
+
/**
|
|
2492
|
+
* PERCENT_RANK() - Returns the relative rank of a row (0 to 1)
|
|
2493
|
+
* @param options - Window function options (partitionBy, orderBy)
|
|
2494
|
+
* @returns The percent rank value
|
|
2495
|
+
*
|
|
2496
|
+
* @example
|
|
2497
|
+
* const users = await User.findAll({
|
|
2498
|
+
* attributes: [[User.percentRank({ orderBy: ['score', 'DESC'] }), 'pctRank']]
|
|
2499
|
+
* });
|
|
2500
|
+
*/
|
|
2501
|
+
percentRank(options?: WindowFunctionOptions): any;
|
|
2502
|
+
/**
|
|
2503
|
+
* CUME_DIST() - Returns the cumulative distribution (0 to 1)
|
|
2504
|
+
* @param options - Window function options (partitionBy, orderBy)
|
|
2505
|
+
* @returns The cumulative distribution value
|
|
2506
|
+
*
|
|
2507
|
+
* @example
|
|
2508
|
+
* const users = await User.findAll({
|
|
2509
|
+
* attributes: [[User.cumeDist({ orderBy: ['score', 'DESC'] }), 'cumeDist']]
|
|
2510
|
+
* });
|
|
2511
|
+
*/
|
|
2512
|
+
cumeDist(options?: WindowFunctionOptions): any;
|
|
2513
|
+
/**
|
|
2514
|
+
* COUNT() as window function - counts rows or non-null values
|
|
2515
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame, countField)
|
|
2516
|
+
* @returns The count value
|
|
2517
|
+
*
|
|
2518
|
+
* @example
|
|
2519
|
+
* const users = await User.findAll({
|
|
2520
|
+
* attributes: [[User.count({ partitionBy: 'department' }), 'deptCount']]
|
|
2521
|
+
* });
|
|
2522
|
+
*/
|
|
2523
|
+
count(options?: WindowFunctionOptions & {
|
|
2524
|
+
countField?: string;
|
|
2525
|
+
}): any;
|
|
2526
|
+
/**
|
|
2527
|
+
* SUM() as window function - sums values in a partition
|
|
2528
|
+
* @param field - The field to sum
|
|
2529
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2530
|
+
* @returns The sum value
|
|
2531
|
+
*
|
|
2532
|
+
* @example
|
|
2533
|
+
* const orders = await Order.findAll({
|
|
2534
|
+
* attributes: [[Order.sum('amount', { partitionBy: 'customerId', orderBy: 'orderDate' }), 'runningTotal']]
|
|
2535
|
+
* });
|
|
2536
|
+
*/
|
|
2537
|
+
sum(field: string, options?: WindowFunctionOptions): any;
|
|
2538
|
+
/**
|
|
2539
|
+
* AVG() as window function - calculates average in a partition
|
|
2540
|
+
* @param field - The field to average
|
|
2541
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2542
|
+
* @returns The average value
|
|
2543
|
+
*
|
|
2544
|
+
* @example
|
|
2545
|
+
* const orders = await Order.findAll({
|
|
2546
|
+
* attributes: [[Order.avg('amount', { partitionBy: 'customerId' }), 'avgOrder']]
|
|
2547
|
+
* });
|
|
2548
|
+
*/
|
|
2549
|
+
avg(field: string, options?: WindowFunctionOptions): any;
|
|
2550
|
+
/**
|
|
2551
|
+
* MAX() as window function - returns maximum value in a partition
|
|
2552
|
+
* @param field - The field to find maximum
|
|
2553
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2554
|
+
* @returns The maximum value
|
|
2555
|
+
*
|
|
2556
|
+
* @example
|
|
2557
|
+
* const orders = await Order.findAll({
|
|
2558
|
+
* attributes: [[Order.max('amount', { partitionBy: 'customerId' }), 'maxOrder']]
|
|
2559
|
+
* });
|
|
2560
|
+
*/
|
|
2561
|
+
max(field: string, options?: WindowFunctionOptions): any;
|
|
2562
|
+
/**
|
|
2563
|
+
* MIN() as window function - returns minimum value in a partition
|
|
2564
|
+
* @param field - The field to find minimum
|
|
2565
|
+
* @param options - Window function options (partitionBy, orderBy, windowFrame)
|
|
2566
|
+
* @returns The minimum value
|
|
2567
|
+
*
|
|
2568
|
+
* @example
|
|
2569
|
+
* const orders = await Order.findAll({
|
|
2570
|
+
* attributes: [[Order.min('amount', { partitionBy: 'customerId' }), 'minOrder']]
|
|
2571
|
+
* });
|
|
2572
|
+
*/
|
|
2573
|
+
min(field: string, options?: WindowFunctionOptions): any;
|
|
2574
|
+
/**
|
|
2575
|
+
* Generate a window function SQL expression for use in queries
|
|
2576
|
+
* @param functionName - The window function name (ROW_NUMBER, RANK, etc.)
|
|
2577
|
+
* @param args - Arguments to the window function
|
|
2578
|
+
* @param options - Window function options
|
|
2579
|
+
* @returns Object with sql and values for the window function
|
|
2580
|
+
*
|
|
2581
|
+
* @example
|
|
2582
|
+
* const expr = User.windowFunction('ROW_NUMBER', [], { partitionBy: 'department', orderBy: ['createdAt', 'DESC'] });
|
|
2583
|
+
*/
|
|
2584
|
+
windowFunction(functionName: string, args: any[], options: WindowFunctionOptions): {
|
|
2585
|
+
sql: string;
|
|
2586
|
+
values: any[];
|
|
2587
|
+
};
|
|
2588
|
+
upsert(values: Partial<T>, options?: UpsertOptions): Promise<[T, boolean]>;
|
|
2589
|
+
/**
|
|
2590
|
+
* Find a record by the given where clause, or create it if not found
|
|
2591
|
+
* @param options - Find options with where clause and defaults for creation
|
|
2592
|
+
* @returns A tuple of [instance, created] where created is true if a new record was created
|
|
2593
|
+
*
|
|
2594
|
+
* @example
|
|
2595
|
+
* const [user, created] = await User.findOrCreate({
|
|
2596
|
+
* where: { email: 'test@test.com' },
|
|
2597
|
+
* defaults: { name: 'Test User' }
|
|
2598
|
+
* });
|
|
2599
|
+
*/
|
|
2600
|
+
findOrCreate(options: FindOptions & {
|
|
2601
|
+
defaults?: Partial<T>;
|
|
2602
|
+
}): Promise<[T, boolean]>;
|
|
2603
|
+
/**
|
|
2604
|
+
* Find a record by the given where clause, or build (but not save) it if not found
|
|
2605
|
+
* @param options - Find options with where clause and defaults for building
|
|
2606
|
+
* @returns A tuple of [instance, created] where created is true if a new instance was built
|
|
2607
|
+
*
|
|
2608
|
+
* @example
|
|
2609
|
+
* const [user, created] = await User.findOrBuild({
|
|
2610
|
+
* where: { email: 'test@test.com' },
|
|
2611
|
+
* defaults: { name: 'Test User' }
|
|
2612
|
+
* });
|
|
2613
|
+
*/
|
|
2614
|
+
findOrBuild(options: FindOptions & {
|
|
2615
|
+
defaults?: Partial<T>;
|
|
2616
|
+
}): Promise<[T, boolean]>;
|
|
2617
|
+
/**
|
|
2618
|
+
* Find a record by the given where clause, or build (but not save) it if not found
|
|
2619
|
+
* Alias for findOrBuild
|
|
2620
|
+
*/
|
|
2621
|
+
findOrInitialize(options: FindOptions & {
|
|
2622
|
+
defaults?: Partial<T>;
|
|
2623
|
+
}): Promise<[T, boolean]>;
|
|
2624
|
+
truncate(options?: TruncateOptions): Promise<void>;
|
|
2625
|
+
describe(): Promise<Record<string, AttributeOptions>>;
|
|
2626
|
+
drop(options?: DropOptions): Promise<void>;
|
|
2627
|
+
getTableName(): string;
|
|
2628
|
+
/**
|
|
2629
|
+
* Refresh a materialized view (PostgreSQL only)
|
|
2630
|
+
* @param options - Refresh options
|
|
2631
|
+
* @returns Promise<void>
|
|
2632
|
+
*
|
|
2633
|
+
* @example
|
|
2634
|
+
* // Simple refresh
|
|
2635
|
+
* await User.refresh();
|
|
2636
|
+
*
|
|
2637
|
+
* // Concurrent refresh (requires unique index)
|
|
2638
|
+
* await User.refresh({ concurrently: true });
|
|
2639
|
+
*
|
|
2640
|
+
* // Refresh without data
|
|
2641
|
+
* await User.refresh({ withNoData: true });
|
|
2642
|
+
*/
|
|
2643
|
+
refresh(options?: RefreshOptions): Promise<void>;
|
|
2644
|
+
/**
|
|
2645
|
+
* Check if this model is a materialized view
|
|
2646
|
+
* @returns True if the model is a materialized view
|
|
2647
|
+
*/
|
|
2648
|
+
isMaterializedView?: boolean;
|
|
2649
|
+
/**
|
|
2650
|
+
* Add a hook to the model
|
|
2651
|
+
* @param hookName - Name of the hook
|
|
2652
|
+
* @param handler - Hook handler function
|
|
2653
|
+
*/
|
|
2654
|
+
hook(hookName: string, handler: HookHandler): ModelStatic<T>;
|
|
2655
|
+
/**
|
|
2656
|
+
* Add a named hook to the model
|
|
2657
|
+
* @param hookName - Name of the hook
|
|
2658
|
+
* @param name - Hook name identifier
|
|
2659
|
+
* @param handler - Hook handler function
|
|
2660
|
+
*/
|
|
2661
|
+
addHook(hookName: string, name: string, handler: HookHandler): ModelStatic<T>;
|
|
2662
|
+
/**
|
|
2663
|
+
* Check if a hook is registered
|
|
2664
|
+
* @param hookName - Name of the hook
|
|
2665
|
+
* @returns True if hook is registered
|
|
2666
|
+
*/
|
|
2667
|
+
hasHook(hookName: string): boolean;
|
|
2668
|
+
/**
|
|
2669
|
+
* Remove a hook from the model
|
|
2670
|
+
* @param hookName - Name of the hook
|
|
2671
|
+
* @param hookOrHookId - Optional hook or hook ID to remove
|
|
2672
|
+
*/
|
|
2673
|
+
removeHook(hookName: string, hookOrHookId?: string | HookHandler): ModelStatic<T>;
|
|
2674
|
+
}
|
|
2675
|
+
/**
|
|
2676
|
+
* Options for toJSON method
|
|
2677
|
+
*/
|
|
2678
|
+
export interface ToJSONOptions {
|
|
2679
|
+
/**
|
|
2680
|
+
* Only include these attributes in the output
|
|
2681
|
+
*/
|
|
2682
|
+
attributes?: string[];
|
|
2683
|
+
/**
|
|
2684
|
+
* Exclude these attributes from the output
|
|
2685
|
+
*/
|
|
2686
|
+
exclude?: string[];
|
|
2687
|
+
/**
|
|
2688
|
+
* When true, bypass all transformations (no virtual fields, no hidden filtering)
|
|
2689
|
+
*/
|
|
2690
|
+
raw?: boolean;
|
|
2691
|
+
/**
|
|
2692
|
+
* Include nested associations
|
|
2693
|
+
*/
|
|
2694
|
+
include?: Includeable[] | IncludeOptions[];
|
|
2695
|
+
/**
|
|
2696
|
+
* Clone the result before returning (prevents mutation)
|
|
2697
|
+
*/
|
|
2698
|
+
clone?: boolean;
|
|
2699
|
+
}
|
|
2700
|
+
export interface Model {
|
|
2701
|
+
getDataValue(key: string): any;
|
|
2702
|
+
setDataValue(key: string, value: any): void;
|
|
2703
|
+
get(key: string): any;
|
|
2704
|
+
set(key: string, value: any): void;
|
|
2705
|
+
changed(key?: string): boolean | string[];
|
|
2706
|
+
previous(key?: string): any;
|
|
2707
|
+
isNewRecord: boolean;
|
|
2708
|
+
isDirty: boolean;
|
|
2709
|
+
primaryKey?: string;
|
|
2710
|
+
transaction?: Transaction;
|
|
2711
|
+
_previousDataValues: Record<string, any>;
|
|
2712
|
+
dataValues: Record<string, any>;
|
|
2713
|
+
validate(options?: ValidationOptions): Promise<ValidationError | {
|
|
2714
|
+
valid: boolean;
|
|
2715
|
+
errors: ValidationErrorItem[];
|
|
2716
|
+
} | null>;
|
|
2717
|
+
save(options?: SaveOptions): Promise<this>;
|
|
2718
|
+
destroy(options?: DestroyOptions): Promise<void>;
|
|
2719
|
+
restore(options?: RestoreOptions): Promise<void>;
|
|
2720
|
+
reload(options?: FindOptions): Promise<this>;
|
|
2721
|
+
toJSON(options?: ToJSONOptions): Record<string, any>;
|
|
2722
|
+
}
|
|
2723
|
+
export interface Association {
|
|
2724
|
+
source: ModelStatic<any>;
|
|
2725
|
+
target: ModelStatic<any>;
|
|
2726
|
+
foreignKey: string | string[];
|
|
2727
|
+
type: 'belongsTo' | 'hasOne' | 'hasMany' | 'belongsToMany';
|
|
2728
|
+
as: string;
|
|
2729
|
+
options: AssociationOptions;
|
|
2730
|
+
targetKey?: string | string[];
|
|
2731
|
+
sourceKey?: string | string[];
|
|
2732
|
+
}
|
|
2733
|
+
export interface BulkCreateOptions extends CreateOptions {
|
|
2734
|
+
ignoreDuplicates?: boolean;
|
|
2735
|
+
validate?: boolean;
|
|
2736
|
+
fields?: string[];
|
|
2737
|
+
hooks?: boolean;
|
|
2738
|
+
individualHooks?: boolean;
|
|
2739
|
+
returning?: boolean | string[];
|
|
2740
|
+
/** Perform upsert instead of insert (insert or update on conflict) */
|
|
2741
|
+
upsert?: boolean;
|
|
2742
|
+
/** Fields to use for conflict resolution in upsert */
|
|
2743
|
+
conflictFields?: string[];
|
|
2744
|
+
/** Fields to update on conflict in upsert */
|
|
2745
|
+
updateOnDuplicate?: string[];
|
|
2746
|
+
}
|
|
2747
|
+
export interface CountOptions extends FindOptions {
|
|
2748
|
+
distinct?: boolean;
|
|
2749
|
+
col?: string;
|
|
2750
|
+
}
|
|
2751
|
+
export interface AggregateOptions extends FindOptions {
|
|
2752
|
+
plain?: boolean;
|
|
2753
|
+
}
|
|
2754
|
+
/**
|
|
2755
|
+
* Window frame specification for window functions
|
|
2756
|
+
*/
|
|
2757
|
+
export interface WindowFrame {
|
|
2758
|
+
/** Type of window frame: ROWS, RANGE, or GROUPS */
|
|
2759
|
+
type: 'ROWS' | 'RANGE' | 'GROUPS';
|
|
2760
|
+
/** Starting offset (positive number for following, negative for preceding) */
|
|
2761
|
+
start?: number;
|
|
2762
|
+
/** Ending offset (positive number for following, negative for preceding) */
|
|
2763
|
+
end?: number;
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Options for window functions
|
|
2767
|
+
*/
|
|
2768
|
+
export interface WindowFunctionOptions {
|
|
2769
|
+
/** PARTITION BY clause - field(s) to partition by */
|
|
2770
|
+
partitionBy?: string | string[];
|
|
2771
|
+
/** ORDER BY clause - field(s) to order by */
|
|
2772
|
+
orderBy?: Order;
|
|
2773
|
+
/** Window frame specification */
|
|
2774
|
+
windowFrame?: WindowFrame;
|
|
2775
|
+
/** Number of buckets for NTILE() function */
|
|
2776
|
+
ntileBuckets?: number;
|
|
2777
|
+
/** Offset for LAG/LEAD functions (number of rows to look ahead/behind) */
|
|
2778
|
+
offset?: number;
|
|
2779
|
+
/** Default value for LAG/LEAD functions when the offset goes beyond the partition */
|
|
2780
|
+
defaultValue?: any;
|
|
2781
|
+
}
|
|
2782
|
+
export interface UpsertOptions extends Omit<UpdateOptions, 'where'>, CreateOptions {
|
|
2783
|
+
/** Fields to use for conflict resolution (ON CONFLICT for PostgreSQL/SQLite, ON DUPLICATE KEY for MySQL) */
|
|
2784
|
+
conflictFields?: string[];
|
|
2785
|
+
/** Fields to update on conflict. If not specified, all fields will be updated */
|
|
2786
|
+
updateOnDuplicate?: string[];
|
|
2787
|
+
/** Whether to return the record after upsert */
|
|
2788
|
+
returning?: boolean | string[];
|
|
2789
|
+
/** Use raw values instead of instances */
|
|
2790
|
+
raw?: boolean;
|
|
2791
|
+
/** Fields to include in the returned record */
|
|
2792
|
+
fields?: string[];
|
|
2793
|
+
/** Hooks configuration */
|
|
2794
|
+
hooks?: boolean;
|
|
2795
|
+
/** Validate before upsert */
|
|
2796
|
+
validate?: boolean;
|
|
2797
|
+
/** Transaction to use */
|
|
2798
|
+
transaction?: Transaction;
|
|
2799
|
+
/** Where clause for upsert (optional, can use primary key in values instead) */
|
|
2800
|
+
where?: WhereOptions;
|
|
2801
|
+
/** Whether to use paranoid mode when fetching the instance after upsert */
|
|
2802
|
+
paranoid?: boolean;
|
|
2803
|
+
}
|
|
2804
|
+
export interface TruncateOptions extends HookOptions {
|
|
2805
|
+
cascade?: boolean;
|
|
2806
|
+
restartIdentity?: boolean;
|
|
2807
|
+
}
|
|
2808
|
+
export interface DropOptions extends HookOptions {
|
|
2809
|
+
cascade?: boolean;
|
|
2810
|
+
}
|
|
2811
|
+
export interface ValidationOptions {
|
|
2812
|
+
fields?: string[];
|
|
2813
|
+
validate?: boolean;
|
|
2814
|
+
hooks?: boolean;
|
|
2815
|
+
}
|
|
2816
|
+
export interface RestoreOptions extends HookOptions {
|
|
2817
|
+
where?: WhereOptions;
|
|
2818
|
+
limit?: number;
|
|
2819
|
+
}
|
|
2820
|
+
export interface IncrementDecrementOptions extends HookOptions {
|
|
2821
|
+
/** Amount to increment/decrement by (default: 1) */
|
|
2822
|
+
by?: number;
|
|
2823
|
+
/** Additional where clause for the increment/decrement operation */
|
|
2824
|
+
where?: WhereOptions;
|
|
2825
|
+
/** Whether to reload the instance after the operation (default: true) */
|
|
2826
|
+
reload?: boolean;
|
|
2827
|
+
}
|
|
2828
|
+
export interface IncrementOptions extends IncrementDecrementOptions {
|
|
2829
|
+
}
|
|
2830
|
+
export interface DecrementOptions extends IncrementDecrementOptions {
|
|
2831
|
+
}
|
|
2832
|
+
export interface ValidationError extends Error {
|
|
2833
|
+
name: string;
|
|
2834
|
+
message: string;
|
|
2835
|
+
errors: ValidationErrorItem[];
|
|
2836
|
+
}
|
|
2837
|
+
export interface ValidationErrorItem {
|
|
2838
|
+
message: string;
|
|
2839
|
+
type: string;
|
|
2840
|
+
path: string;
|
|
2841
|
+
value: any;
|
|
2842
|
+
}
|
|
2843
|
+
export interface QueryResult {
|
|
2844
|
+
rows: any[];
|
|
2845
|
+
rowCount: number;
|
|
2846
|
+
fields: FieldInfo[];
|
|
2847
|
+
lastInsertRowid?: number;
|
|
2848
|
+
/**
|
|
2849
|
+
* Scalar OUT/INOUT parameter values returned by a stored procedure `CALL`
|
|
2850
|
+
* (e.g. HANA's `hdb` driver callback shape `cb(err, parameters, ...resultSets)`).
|
|
2851
|
+
* Present only when the query was a procedure call that declared such
|
|
2852
|
+
* parameters.
|
|
2853
|
+
*/
|
|
2854
|
+
outputParams?: Record<string, unknown>;
|
|
2855
|
+
/**
|
|
2856
|
+
* Additional result sets returned by a stored procedure `CALL` beyond the
|
|
2857
|
+
* primary `rows` (e.g. one array per table/cursor OUT parameter). Present
|
|
2858
|
+
* only when the procedure returned more than one additional result set.
|
|
2859
|
+
*/
|
|
2860
|
+
resultSets?: any[][];
|
|
2861
|
+
}
|
|
2862
|
+
export interface FieldInfo {
|
|
2863
|
+
name: string;
|
|
2864
|
+
type: string;
|
|
2865
|
+
length: number;
|
|
2866
|
+
tableID: number;
|
|
2867
|
+
columnID: number;
|
|
2868
|
+
nullable: boolean;
|
|
2869
|
+
isEnum: boolean;
|
|
2870
|
+
isPrimaryKey: boolean;
|
|
2871
|
+
}
|
|
2872
|
+
export interface RawQueryResult {
|
|
2873
|
+
rows: any[];
|
|
2874
|
+
count: number;
|
|
2875
|
+
isSelect: boolean;
|
|
2876
|
+
}
|
|
2877
|
+
/**
|
|
2878
|
+
* Enum for query types used in prorm.query()
|
|
2879
|
+
* @example
|
|
2880
|
+
* prorm.query('SELECT * FROM users', { type: QueryTypes.SELECT })
|
|
2881
|
+
* prorm.query('INSERT INTO users VALUES(...)', { type: QueryTypes.INSERT })
|
|
2882
|
+
*/
|
|
2883
|
+
export declare enum QueryTypes {
|
|
2884
|
+
SELECT = "SELECT",
|
|
2885
|
+
INSERT = "INSERT",
|
|
2886
|
+
UPDATE = "UPDATE",
|
|
2887
|
+
DELETE = "DELETE",
|
|
2888
|
+
BULKINSERT = "BULKINSERT",
|
|
2889
|
+
BULKUPDATE = "BULKUPDATE",
|
|
2890
|
+
BULKDELETE = "BULKDELETE",
|
|
2891
|
+
RAW = "RAW",
|
|
2892
|
+
CALL = "CALL"
|
|
2893
|
+
}
|
|
2894
|
+
export interface QueryOptions {
|
|
2895
|
+
plain?: boolean;
|
|
2896
|
+
raw?: boolean;
|
|
2897
|
+
type?: QueryTypes;
|
|
2898
|
+
nest?: boolean;
|
|
2899
|
+
replacements?: Record<string, any>;
|
|
2900
|
+
bind?: Record<string, any>;
|
|
2901
|
+
transaction?: Transaction;
|
|
2902
|
+
logging?: boolean | ((sql: string, time?: number) => void);
|
|
2903
|
+
using?: string;
|
|
2904
|
+
/**
|
|
2905
|
+
* Map raw query results to a model instance
|
|
2906
|
+
* When true, maps the result rows to ModelInstance objects using the provided model
|
|
2907
|
+
* @default false
|
|
2908
|
+
* @example
|
|
2909
|
+
* // Map raw results to model
|
|
2910
|
+
* const users = await prorm.query('SELECT * FROM users', {
|
|
2911
|
+
* model: User,
|
|
2912
|
+
* mapToModel: true
|
|
2913
|
+
* });
|
|
2914
|
+
*/
|
|
2915
|
+
mapToModel?: boolean;
|
|
2916
|
+
/**
|
|
2917
|
+
* Model to use for mapping raw results to model instances
|
|
2918
|
+
* Used together with mapToModel to create ModelInstance objects from raw query results
|
|
2919
|
+
*/
|
|
2920
|
+
model?: ModelStatic<any>;
|
|
2921
|
+
/**
|
|
2922
|
+
* Retry options for failed queries
|
|
2923
|
+
* Allows retrying queries that fail due to transient errors (e.g., connection issues)
|
|
2924
|
+
* @example
|
|
2925
|
+
* // Retry up to 3 times with default error matching
|
|
2926
|
+
* await prorm.query('SELECT * FROM users', {
|
|
2927
|
+
* retry: { max: 3 }
|
|
2928
|
+
* });
|
|
2929
|
+
* @example
|
|
2930
|
+
* // Retry only on specific error patterns
|
|
2931
|
+
* await prorm.query('SELECT * FROM users', {
|
|
2932
|
+
* retry: { max: 3, match: ['Connection refused', 'Too many connections'] }
|
|
2933
|
+
* });
|
|
2934
|
+
*/
|
|
2935
|
+
retry?: RetryOptions;
|
|
2936
|
+
/** Query timeout in milliseconds */
|
|
2937
|
+
timeout?: number;
|
|
2938
|
+
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Options for streaming query results
|
|
2941
|
+
*/
|
|
2942
|
+
export interface StreamOptions {
|
|
2943
|
+
/**
|
|
2944
|
+
* Batch size for fetching records
|
|
2945
|
+
* @default 1000
|
|
2946
|
+
*/
|
|
2947
|
+
batchSize?: number;
|
|
2948
|
+
/**
|
|
2949
|
+
* High watermark for the stream internal buffer
|
|
2950
|
+
* @default 1000
|
|
2951
|
+
*/
|
|
2952
|
+
highWaterMark?: number;
|
|
2953
|
+
/**
|
|
2954
|
+
* Model to use for mapping raw results to model instances
|
|
2955
|
+
*/
|
|
2956
|
+
model?: ModelStatic<any>;
|
|
2957
|
+
/**
|
|
2958
|
+
* Map raw query results to a model instance
|
|
2959
|
+
* @default false
|
|
2960
|
+
*/
|
|
2961
|
+
mapToModel?: boolean;
|
|
2962
|
+
/**
|
|
2963
|
+
* Transaction to use for the query
|
|
2964
|
+
*/
|
|
2965
|
+
transaction?: Transaction;
|
|
2966
|
+
/**
|
|
2967
|
+
* Logging function
|
|
2968
|
+
*/
|
|
2969
|
+
logging?: boolean | ((sql: string, time?: number) => void);
|
|
2970
|
+
}
|
|
2971
|
+
export interface QueryError extends Error {
|
|
2972
|
+
parent?: Error;
|
|
2973
|
+
original?: Error;
|
|
2974
|
+
sql?: string;
|
|
2975
|
+
parameters?: any[];
|
|
2976
|
+
}
|
|
2977
|
+
export interface SyncOptions {
|
|
2978
|
+
/**
|
|
2979
|
+
* If true, drop all tables first before recreating them.
|
|
2980
|
+
* WARNING: This will destroy all data in the tables!
|
|
2981
|
+
* @default false
|
|
2982
|
+
*/
|
|
2983
|
+
force?: boolean;
|
|
2984
|
+
/**
|
|
2985
|
+
* If true, alter tables to match model definitions.
|
|
2986
|
+
* This will add new columns, remove extra columns, and change column types as needed.
|
|
2987
|
+
* Preserves existing data in the table.
|
|
2988
|
+
* @default false
|
|
2989
|
+
*/
|
|
2990
|
+
alter?: boolean;
|
|
2991
|
+
/**
|
|
2992
|
+
* Regular expression to match the database name.
|
|
2993
|
+
* Sync will only proceed if the database name matches this pattern.
|
|
2994
|
+
* Useful for development vs production environments.
|
|
2995
|
+
* Example: /test/ - only syncs if database name contains "test"
|
|
2996
|
+
*/
|
|
2997
|
+
match?: RegExp;
|
|
2998
|
+
/**
|
|
2999
|
+
* Custom logging function
|
|
3000
|
+
*/
|
|
3001
|
+
logging?: boolean | ((sql: string, timing?: number) => void);
|
|
3002
|
+
/**
|
|
3003
|
+
* If true, run sync hooks (beforeSync, afterSync, etc.)
|
|
3004
|
+
* @default true
|
|
3005
|
+
*/
|
|
3006
|
+
hooks?: boolean;
|
|
3007
|
+
/**
|
|
3008
|
+
* If true, also sync indexes
|
|
3009
|
+
* @default true
|
|
3010
|
+
*/
|
|
3011
|
+
indexes?: boolean;
|
|
3012
|
+
/**
|
|
3013
|
+
* If true, also sync foreign key constraints
|
|
3014
|
+
* @default true
|
|
3015
|
+
*/
|
|
3016
|
+
constraints?: boolean;
|
|
3017
|
+
}
|
|
3018
|
+
/**
|
|
3019
|
+
* Routing strategy for selecting a replica
|
|
3020
|
+
*/
|
|
3021
|
+
export type RoutingStrategy = 'round-robin' | 'least-connections' | 'lowest-lag';
|
|
3022
|
+
/**
|
|
3023
|
+
* Replica status
|
|
3024
|
+
*/
|
|
3025
|
+
export interface ReplicaStatus {
|
|
3026
|
+
/** Replica name */
|
|
3027
|
+
name: string;
|
|
3028
|
+
/** Whether the replica is healthy */
|
|
3029
|
+
healthy: boolean;
|
|
3030
|
+
/** Replication lag in milliseconds */
|
|
3031
|
+
lag: number | null;
|
|
3032
|
+
/** Number of active connections */
|
|
3033
|
+
activeConnections: number;
|
|
3034
|
+
/** Last check timestamp */
|
|
3035
|
+
lastCheck: Date;
|
|
3036
|
+
/** Error message if unhealthy */
|
|
3037
|
+
error?: string;
|
|
3038
|
+
}
|
|
3039
|
+
/**
|
|
3040
|
+
* Configuration for connecting to a replica
|
|
3041
|
+
*/
|
|
3042
|
+
export interface ReplicaConnectionConfig {
|
|
3043
|
+
/** Unique name for this replica */
|
|
3044
|
+
name: string;
|
|
3045
|
+
/** Connection host */
|
|
3046
|
+
host: string;
|
|
3047
|
+
/** Connection port */
|
|
3048
|
+
port: number;
|
|
3049
|
+
/** Database name */
|
|
3050
|
+
database: string;
|
|
3051
|
+
/** Username */
|
|
3052
|
+
username: string;
|
|
3053
|
+
/** Password */
|
|
3054
|
+
password: string;
|
|
3055
|
+
/** Connection dialect (mysql, mariadb, postgres, mssql, sqlite, oracle) */
|
|
3056
|
+
dialect: string;
|
|
3057
|
+
/** Additional dialect-specific options */
|
|
3058
|
+
dialectOptions?: Record<string, any>;
|
|
3059
|
+
/** Pool options for this replica */
|
|
3060
|
+
pool?: {
|
|
3061
|
+
max?: number;
|
|
3062
|
+
min?: number;
|
|
3063
|
+
idle?: number;
|
|
3064
|
+
acquire?: number;
|
|
3065
|
+
};
|
|
3066
|
+
}
|
|
3067
|
+
/**
|
|
3068
|
+
* Configuration for lag detection
|
|
3069
|
+
*/
|
|
3070
|
+
export interface LagDetectionConfig {
|
|
3071
|
+
/** Enable lag detection */
|
|
3072
|
+
enabled: boolean;
|
|
3073
|
+
/** Interval in milliseconds between lag checks */
|
|
3074
|
+
interval: number;
|
|
3075
|
+
/** Query timeout in milliseconds */
|
|
3076
|
+
timeout: number;
|
|
3077
|
+
/** Maximum acceptable lag in milliseconds */
|
|
3078
|
+
maxAcceptableLag: number;
|
|
3079
|
+
/** Number of consecutive failures before marking replica as unhealthy */
|
|
3080
|
+
maxFailures: number;
|
|
3081
|
+
}
|
|
3082
|
+
/**
|
|
3083
|
+
* Options for configuring replication
|
|
3084
|
+
*/
|
|
3085
|
+
export interface ReplicationOptions {
|
|
3086
|
+
/** Enable replication support */
|
|
3087
|
+
enabled: boolean;
|
|
3088
|
+
/** The master connection configuration */
|
|
3089
|
+
master: ReplicaConnectionConfig;
|
|
3090
|
+
/** Array of replica configurations */
|
|
3091
|
+
replicas: ReplicaConnectionConfig[];
|
|
3092
|
+
/** Default lag detection configuration */
|
|
3093
|
+
lagDetection?: Partial<LagDetectionConfig>;
|
|
3094
|
+
/** Default routing strategy */
|
|
3095
|
+
defaultRoutingStrategy?: RoutingStrategy;
|
|
3096
|
+
/** Whether to automatically fail over to master on all replicas unhealthy */
|
|
3097
|
+
autoFailover?: boolean;
|
|
3098
|
+
}
|
|
3099
|
+
export type ModelInstance<T = any> = any;
|
|
3100
|
+
export interface RedisClusterNode {
|
|
3101
|
+
host: string;
|
|
3102
|
+
port: number;
|
|
3103
|
+
tls?: boolean;
|
|
3104
|
+
}
|
|
3105
|
+
export interface L1CacheOptions {
|
|
3106
|
+
maxItems: number;
|
|
3107
|
+
ttl: number;
|
|
3108
|
+
}
|
|
3109
|
+
export interface RedisClusterCacheOptions {
|
|
3110
|
+
nodes: RedisClusterNode[];
|
|
3111
|
+
maxRedirects?: number;
|
|
3112
|
+
keyPrefix?: string;
|
|
3113
|
+
defaultTtl?: number;
|
|
3114
|
+
readFromReplicas?: boolean;
|
|
3115
|
+
poolSize?: number;
|
|
3116
|
+
lazyConnect?: boolean;
|
|
3117
|
+
l1?: L1CacheOptions;
|
|
3118
|
+
}
|
|
3119
|
+
export interface CacheManagerOptions {
|
|
3120
|
+
keyPrefix?: string;
|
|
3121
|
+
defaultTtl?: number;
|
|
3122
|
+
l1?: L1CacheOptions;
|
|
3123
|
+
}
|