ts-prorm-orm 1.1.0 → 1.2.0
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 +83 -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 +711 -0
- package/dist/index.js +19 -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,2947 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operators for building queries
|
|
3
|
+
* Provides Symbol-based operators for type safety and flexible query building
|
|
4
|
+
*/
|
|
5
|
+
import type { FullTextSearchOptions } from './types';
|
|
6
|
+
import { SortDirection } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Usage Examples:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Basic operators with findAll
|
|
11
|
+
* User.findAll({ where: { age: { [Op.gte]: 18 } } })
|
|
12
|
+
* User.findAll({ where: { name: { [Op.like]: '%john%' } } })
|
|
13
|
+
* User.findAll({ where: { status: { [Op.in]: ['active', 'pending'] } } })
|
|
14
|
+
*
|
|
15
|
+
* // Using helper functions
|
|
16
|
+
* import { Op, where, and, or, eq, gte } from 'orm';
|
|
17
|
+
*
|
|
18
|
+
* // Simple equality
|
|
19
|
+
* User.findAll({ where: { name: 'John' } })
|
|
20
|
+
*
|
|
21
|
+
* // Using helpers for complex conditions
|
|
22
|
+
* User.findAll({ where: and({ name: 'John' }, { age: gte('age', 18) }) })
|
|
23
|
+
* User.findAll({ where: or({ status: 'active' }, { role: 'admin' }) })
|
|
24
|
+
*
|
|
25
|
+
* // Column comparison (e.g., WHERE column1 = column2)
|
|
26
|
+
* User.findAll({ where: { balance: { [Op.eq]: Op.col('credit_limit') } } })
|
|
27
|
+
*
|
|
28
|
+
* // Using Op.col in WHERE, ORDER BY, and UPDATE SET
|
|
29
|
+
* User.findAll({ where: { [Op.col('id')]: 1 } })
|
|
30
|
+
* User.findAll({ order: [[Op.col('name'), 'ASC']] })
|
|
31
|
+
* User.update({ count: Op.col('count') + 1 }, { where: { ... } })
|
|
32
|
+
*
|
|
33
|
+
* // JSON column queries
|
|
34
|
+
* User.findAll({ where: { settings: { [Op.json]: { theme: 'dark' } } } })
|
|
35
|
+
*
|
|
36
|
+
* // Using Op.where for explicit where clauses
|
|
37
|
+
* User.findAll({ where: Op.where(Op.col('username'), 'john') })
|
|
38
|
+
* User.findAll({ where: Op.where('status', 'active') })
|
|
39
|
+
* User.findAll({ where: Op.where(Op.col('balance'), '>', 1000) })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export interface ColumnReference {
|
|
43
|
+
$col: string;
|
|
44
|
+
}
|
|
45
|
+
export interface LiteralValue {
|
|
46
|
+
$literal: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if a value is a column reference
|
|
50
|
+
*/
|
|
51
|
+
export declare function isColumnReference(value: any): value is ColumnReference;
|
|
52
|
+
export declare const Op: {
|
|
53
|
+
readonly and: symbol;
|
|
54
|
+
readonly or: symbol;
|
|
55
|
+
readonly not: symbol;
|
|
56
|
+
readonly eq: symbol;
|
|
57
|
+
readonly is: symbol;
|
|
58
|
+
readonly ne: symbol;
|
|
59
|
+
readonly gt: symbol;
|
|
60
|
+
readonly gte: symbol;
|
|
61
|
+
readonly lt: symbol;
|
|
62
|
+
readonly lte: symbol;
|
|
63
|
+
readonly like: symbol;
|
|
64
|
+
readonly notLike: symbol;
|
|
65
|
+
readonly iLike: symbol;
|
|
66
|
+
readonly notILike: symbol;
|
|
67
|
+
readonly startsWith: symbol;
|
|
68
|
+
readonly notStartsWith: symbol;
|
|
69
|
+
readonly endsWith: symbol;
|
|
70
|
+
readonly notEndsWith: symbol;
|
|
71
|
+
readonly substring: symbol;
|
|
72
|
+
readonly notSubstring: symbol;
|
|
73
|
+
readonly col: symbol;
|
|
74
|
+
readonly in: symbol;
|
|
75
|
+
readonly notIn: symbol;
|
|
76
|
+
readonly between: symbol;
|
|
77
|
+
readonly notBetween: symbol;
|
|
78
|
+
readonly isNull: symbol;
|
|
79
|
+
readonly isNotNull: symbol;
|
|
80
|
+
readonly exists: symbol;
|
|
81
|
+
readonly notExists: symbol;
|
|
82
|
+
readonly regexp: symbol;
|
|
83
|
+
readonly notRegexp: symbol;
|
|
84
|
+
readonly iRegexp: symbol;
|
|
85
|
+
readonly notIRegexp: symbol;
|
|
86
|
+
readonly any: symbol;
|
|
87
|
+
readonly all: symbol;
|
|
88
|
+
readonly containsKey: symbol;
|
|
89
|
+
readonly containsKeyPath: symbol;
|
|
90
|
+
readonly containsPath: symbol;
|
|
91
|
+
readonly strictLeft: symbol;
|
|
92
|
+
readonly strictRight: symbol;
|
|
93
|
+
readonly noExtendRight: symbol;
|
|
94
|
+
readonly noExtendLeft: symbol;
|
|
95
|
+
readonly adj: symbol;
|
|
96
|
+
readonly notAdj: symbol;
|
|
97
|
+
/**
|
|
98
|
+
* Array contains - checks if an array contains all specified elements
|
|
99
|
+
* PostgreSQL: @>
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Find products where tags contains both 'electronics' and 'sale'
|
|
104
|
+
* Product.findAll({ where: { tags: { [Op.arrayContains]: ['electronics', 'sale'] } } })
|
|
105
|
+
* // SQL: WHERE tags @> ARRAY['electronics', 'sale']
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
readonly arrayContains: symbol;
|
|
109
|
+
/**
|
|
110
|
+
* Array contained by - checks if an array is contained by the specified elements
|
|
111
|
+
* PostgreSQL: <@
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* // Find products where tags is contained by ['electronics', 'sale', 'new']
|
|
116
|
+
* Product.findAll({ where: { tags: { [Op.arrayContainedBy]: ['electronics', 'sale'] } } })
|
|
117
|
+
* // SQL: WHERE tags <@ ARRAY['electronics', 'sale']
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
readonly arrayContainedBy: symbol;
|
|
121
|
+
/**
|
|
122
|
+
* Array overlaps - checks if arrays have common elements
|
|
123
|
+
* PostgreSQL: &&
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* // Find products where tags overlaps with ['electronics', 'sale']
|
|
128
|
+
* Product.findAll({ where: { tags: { [Op.arrayOverlaps]: ['electronics', 'sale'] } } })
|
|
129
|
+
* // SQL: WHERE tags && ARRAY['electronics', 'sale']
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
readonly arrayOverlaps: symbol;
|
|
133
|
+
/**
|
|
134
|
+
* Array ANY - checks if any element matches the condition
|
|
135
|
+
* PostgreSQL: ANY
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Find products where any tag equals 'electronics'
|
|
140
|
+
* Product.findAll({ where: { tags: { [Op.arrayAny]: 'electronics' } } })
|
|
141
|
+
* // SQL: WHERE 'electronics' = ANY(tags)
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
readonly arrayAny: symbol;
|
|
145
|
+
/**
|
|
146
|
+
* Array ALL - checks if all elements match the condition
|
|
147
|
+
* PostgreSQL: ALL
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* // Find products where all prices are greater than 100
|
|
152
|
+
* Product.findAll({ where: { prices: { [Op.arrayAll]: { [Op.gt]: 100 } } } })
|
|
153
|
+
* // SQL: WHERE 100 > ALL(prices)
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
readonly arrayAll: symbol;
|
|
157
|
+
/**
|
|
158
|
+
* Starts with - checks if a string starts with the given value
|
|
159
|
+
* SQL: LIKE 'value%'
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* // Find users whose name starts with 'John'
|
|
164
|
+
* User.findAll({ where: { name: { [Op.startsWith]: 'John' } } })
|
|
165
|
+
* // SQL: WHERE name LIKE 'John%'
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
/**
|
|
169
|
+
* Ends with - checks if a string ends with the given value
|
|
170
|
+
* SQL: LIKE '%value'
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // Find users whose email ends with '@gmail.com'
|
|
175
|
+
* User.findAll({ where: { email: { [Op.endsWith]: '@gmail.com' } } })
|
|
176
|
+
* // SQL: WHERE email LIKE '%@gmail.com'
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
/**
|
|
180
|
+
* JSON contains - checks if JSON document contains the specified value
|
|
181
|
+
* PostgreSQL: @>
|
|
182
|
+
* MySQL: JSON_CONTAINS
|
|
183
|
+
* SQLite: JSON_EXTRACT
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* // Find users where preferences contains { theme: 'dark' }
|
|
188
|
+
* User.findAll({ where: { preferences: { [Op.contains]: { theme: 'dark' } } } })
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
readonly contains: symbol;
|
|
192
|
+
/**
|
|
193
|
+
* JSON is contained in - checks if the value is contained in the JSON column
|
|
194
|
+
* PostgreSQL: <@
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* // Find users where settings is contained in the specified JSON
|
|
199
|
+
* User.findAll({ where: { settings: { [Op.containedBy]: { theme: 'dark', lang: 'en' } } } })
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
readonly containedBy: symbol;
|
|
203
|
+
/**
|
|
204
|
+
* JSON key exists - checks if a key (or array index) exists in a JSON object/array
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Find users where 'role' key exists in data column
|
|
209
|
+
* User.findAll({ where: { data: { [Op.keyExists]: 'role' } } })
|
|
210
|
+
*
|
|
211
|
+
* // Find users where array index 0 exists
|
|
212
|
+
* User.findAll({ where: { tags: { [Op.keyExists]: '0' } } })
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
readonly keyExists: symbol;
|
|
216
|
+
/**
|
|
217
|
+
* JSON overlap - checks if JSON arrays overlap (have common elements)
|
|
218
|
+
* PostgreSQL: &&
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* // Find users where tags overlaps with ['admin', 'vip']
|
|
223
|
+
* User.findAll({ where: { tags: { [Op.overlap]: ['admin', 'vip'] } } })
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
readonly overlap: symbol;
|
|
227
|
+
/**
|
|
228
|
+
* JSON key access - access a specific key in a JSON column
|
|
229
|
+
* PostgreSQL: ->> for text, -> for object
|
|
230
|
+
* MySQL: JSON_EXTRACT
|
|
231
|
+
* SQLite: JSON_EXTRACT
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // Find users where data->>'name' equals 'John'
|
|
236
|
+
* User.findAll({ where: { data: { [Op.key]: 'name' } } })
|
|
237
|
+
* // For nested: { field: { [Op.key]: 'profile.name' } }
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
/**
|
|
241
|
+
* Column reference - reference another column in a WHERE clause
|
|
242
|
+
* Used for comparing one column to another
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* // Find orders where quantity equals available stock
|
|
247
|
+
* Order.findAll({ where: { quantity: { [Op.col]: 'available_stock' } } })
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
readonly match: symbol;
|
|
251
|
+
readonly $json: symbol;
|
|
252
|
+
/**
|
|
253
|
+
* JSON path explicit operator - explicit JSON path with field and path separated
|
|
254
|
+
* Convenience method combining field and path in one call
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* // Query with field and path separated
|
|
259
|
+
* User.findAll({
|
|
260
|
+
* where: {
|
|
261
|
+
* data: { [Op.jsonPath('settings', 'theme')]: 'dark' }
|
|
262
|
+
* }
|
|
263
|
+
* })
|
|
264
|
+
* // SQLite/MySQL: WHERE json_extract(data, '$.settings.theme') = 'dark'
|
|
265
|
+
* // PostgreSQL: WHERE data->>'settings'->>'theme' = 'dark'
|
|
266
|
+
*
|
|
267
|
+
* // Check if path exists (no value comparison)
|
|
268
|
+
* User.findAll({
|
|
269
|
+
* where: {
|
|
270
|
+
* data: { [Op.jsonPath('settings', 'theme')]: { [Op.ne]: null } }
|
|
271
|
+
* }
|
|
272
|
+
* })
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
readonly jsonPath: symbol;
|
|
276
|
+
/**
|
|
277
|
+
* JSON contains - checks if a JSON column contains a specific value or object
|
|
278
|
+
* PostgreSQL: @> (contains), MySQL: JSON_CONTAINS, SQLite: json_each
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* // Find users where preferences contains { theme: 'dark' }
|
|
283
|
+
* User.findAll({ where: { preferences: { [Op.jsonContains]: { theme: 'dark' } } } })
|
|
284
|
+
* // SQL: WHERE preferences @> '{"theme":"dark"}' (PostgreSQL)
|
|
285
|
+
* // SQL: WHERE JSON_CONTAINS(preferences, '{"theme":"dark"}') (MySQL)
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
readonly jsonContains: symbol;
|
|
289
|
+
/**
|
|
290
|
+
* JSON has key - checks if a JSON column has a specific key
|
|
291
|
+
* PostgreSQL: ? (jsonb_exists), MySQL: JSON_CONTAINS_PATH, SQLite: json_each
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* // Find users where data column has 'role' key
|
|
296
|
+
* User.findAll({ where: { data: { [Op.jsonHasKey]: 'role' } } })
|
|
297
|
+
* // SQL: WHERE data ? 'role' (PostgreSQL)
|
|
298
|
+
* // SQL: WHERE JSON_CONTAINS_PATH(data, 'one', '$.role') (MySQL)
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
readonly jsonHasKey: symbol;
|
|
302
|
+
/**
|
|
303
|
+
* JSONB extract - extracts a JSON object field (returns JSON)
|
|
304
|
+
* PostgreSQL: -> operator
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* // Extract field as JSON: data -> 'key'
|
|
309
|
+
* User.findAll({ where: { data: { [Op.jsonbExtract]: { path: 'key' } } } })
|
|
310
|
+
* // SQL: WHERE data -> 'key'
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
readonly jsonbExtract: symbol;
|
|
314
|
+
/**
|
|
315
|
+
* JSONB extract text - extracts a JSON object field as text (returns text)
|
|
316
|
+
* PostgreSQL: ->> operator
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* // Extract field as text: data ->> 'key'
|
|
321
|
+
* User.findAll({ where: { data: { [Op.jsonbExtractText]: { path: 'key', value: 'someValue' } } } })
|
|
322
|
+
* // SQL: WHERE data ->> 'key' = 'someValue'
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
readonly jsonbExtractText: symbol;
|
|
326
|
+
/**
|
|
327
|
+
* JSONB extract path - extracts JSON by path (returns JSON)
|
|
328
|
+
* PostgreSQL: #> operator
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* // Extract nested path as JSON: data #> '{a, b}'
|
|
333
|
+
* User.findAll({ where: { data: { [Op.jsonbExtractPath]: { path: ['a', 'b'] } } } })
|
|
334
|
+
* // SQL: WHERE data #> '{a, b}'
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
readonly jsonbExtractPath: symbol;
|
|
338
|
+
/**
|
|
339
|
+
* JSONB extract path text - extracts JSON by path as text (returns text)
|
|
340
|
+
* PostgreSQL: #>> operator
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* // Extract nested path as text: data #>> '{a, b}'
|
|
345
|
+
* User.findAll({ where: { data: { [Op.jsonbExtractPathText]: { path: ['a', 'b'], value: 'someValue' } } } })
|
|
346
|
+
* // SQL: WHERE data #>> '{a, b}' = 'someValue'
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
readonly jsonbExtractPathText: symbol;
|
|
350
|
+
/**
|
|
351
|
+
* JSONB concatenation - concatenates two JSONB values
|
|
352
|
+
* PostgreSQL: || operator
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* // Concatenate JSONB values: data || '{"key": "value"}'
|
|
357
|
+
* User.findAll({ where: { data: { [Op.jsonConcat]: { key: 'value' } } } })
|
|
358
|
+
* // SQL: WHERE data || '{"key": "value"}'
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
readonly jsonConcat: symbol;
|
|
362
|
+
/**
|
|
363
|
+
* JSONB delete key - deletes a key from JSONB object
|
|
364
|
+
* PostgreSQL: - operator
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```typescript
|
|
368
|
+
* // Delete key from JSONB: data - 'key'
|
|
369
|
+
* User.findAll({ where: { data: { [Op.jsonDelete]: 'key' } } })
|
|
370
|
+
* // SQL: WHERE data - 'key'
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
readonly jsonDelete: symbol;
|
|
374
|
+
/**
|
|
375
|
+
* JSONB delete by path - deletes a key from JSONB by path
|
|
376
|
+
* PostgreSQL: #- operator
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* // Delete by path: data #- '{a, b}'
|
|
381
|
+
* User.findAll({ where: { data: { [Op.jsonDeletePath]: ['a', 'b'] } } })
|
|
382
|
+
* // SQL: WHERE data #- '{a, b}'
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
readonly jsonDeletePath: symbol;
|
|
386
|
+
/**
|
|
387
|
+
* JSON path exists - checks if a JSON path exists and returns boolean
|
|
388
|
+
* PostgreSQL: @? operator
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* // Check if path exists: data @? '$.key'
|
|
393
|
+
* User.findAll({ where: { data: { [Op.jsonPathExists]: '$.key' } } })
|
|
394
|
+
* // SQL: WHERE data @? '$.key'
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
readonly jsonPathExists: symbol;
|
|
398
|
+
/**
|
|
399
|
+
* JSON path query - evaluates JSON path and returns result
|
|
400
|
+
* PostgreSQL: @@ operator
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* // Query JSON path: data @@ '$.key'
|
|
405
|
+
* User.findAll({ where: { data: { [Op.jsonPathQuery]: '$.key' } } })
|
|
406
|
+
* // SQL: WHERE data @@ '$.key'
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
readonly jsonPathQuery: symbol;
|
|
410
|
+
/**
|
|
411
|
+
* JSON type of - returns the type of a JSON value
|
|
412
|
+
* PostgreSQL: json_typeof function
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* // Get JSON type: json_typeof(data)
|
|
417
|
+
* User.findAll({ where: { data: { [Op.jsonTypeOf]: 'object' } } })
|
|
418
|
+
* // SQL: WHERE json_typeof(data) = 'object'
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
readonly jsonTypeOf: symbol;
|
|
422
|
+
/**
|
|
423
|
+
* Create a JSON column path reference for querying
|
|
424
|
+
* Returns a Symbol that can be used as a computed property key
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* // Using as computed property key (recommended)
|
|
429
|
+
* User.findAll({
|
|
430
|
+
* where: {
|
|
431
|
+
* settings: { [Op.json('$.theme')]: 'dark' }
|
|
432
|
+
* }
|
|
433
|
+
* })
|
|
434
|
+
* // SQL: WHERE json_extract(settings, '$.theme') = 'dark'
|
|
435
|
+
*
|
|
436
|
+
* // Using with path prefix
|
|
437
|
+
* User.findAll({
|
|
438
|
+
* where: {
|
|
439
|
+
* data: { [Op.json('address.city')]: 'NYC' }
|
|
440
|
+
* }
|
|
441
|
+
* })
|
|
442
|
+
* // SQL: WHERE json_extract(data, '$.address.city') = 'NYC'
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
readonly json: (path: string) => symbol;
|
|
446
|
+
/**
|
|
447
|
+
* Create a JSON key path query
|
|
448
|
+
* Useful for accessing specific keys in a JSON/JSONB column
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```typescript
|
|
452
|
+
* // Access JSON key 'name' from data column
|
|
453
|
+
* User.findAll({
|
|
454
|
+
* where: {
|
|
455
|
+
* data: { [Op.key]: 'name' }
|
|
456
|
+
* }
|
|
457
|
+
* })
|
|
458
|
+
*
|
|
459
|
+
* // Compare JSON key to a value
|
|
460
|
+
* User.findAll({
|
|
461
|
+
* where: {
|
|
462
|
+
* data: { [Op.key]: { path: 'name', value: 'John' } }
|
|
463
|
+
* }
|
|
464
|
+
* })
|
|
465
|
+
*
|
|
466
|
+
* // Nested key access
|
|
467
|
+
* User.findAll({
|
|
468
|
+
* where: {
|
|
469
|
+
* data: { [Op.key]: { path: 'profile.settings.theme', value: 'dark' } }
|
|
470
|
+
* }
|
|
471
|
+
* })
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
readonly key: (pathOrOptions: string | {
|
|
475
|
+
path: string;
|
|
476
|
+
value?: any;
|
|
477
|
+
}) => Record<string, any>;
|
|
478
|
+
/**
|
|
479
|
+
* Create a raw SQL literal
|
|
480
|
+
* Useful for embedding raw SQL expressions like NOW(), CURRENT_TIMESTAMP, etc.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* // Use with update to set current timestamp
|
|
485
|
+
* User.update({ lastLogin: Op.literal('NOW()') }, { where: { ... } })
|
|
486
|
+
*
|
|
487
|
+
* // Use in where clause to compare with current time
|
|
488
|
+
* User.findAll({
|
|
489
|
+
* where: {
|
|
490
|
+
* createdAt: { [Op.lt]: Op.literal('NOW()') }
|
|
491
|
+
* }
|
|
492
|
+
* })
|
|
493
|
+
*
|
|
494
|
+
* // Compare column to a literal value
|
|
495
|
+
* User.findAll({
|
|
496
|
+
* where: {
|
|
497
|
+
* updatedAt: { [Op.gt]: Op.literal('createdAt') }
|
|
498
|
+
* }
|
|
499
|
+
* })
|
|
500
|
+
*
|
|
501
|
+
* // Use with Op.where
|
|
502
|
+
* User.findAll({ where: Op.where(Op.col('created_at'), '>', Op.literal('NOW()')) })
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
readonly literal: (value: string) => LiteralValue;
|
|
506
|
+
/**
|
|
507
|
+
* Create a CAST expression for type casting
|
|
508
|
+
* SQL: CAST(value AS type)
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```typescript
|
|
512
|
+
* // CAST('2023-01-01' AS DATE)
|
|
513
|
+
* User.findAll({
|
|
514
|
+
* attributes: [[Op.cast('2023-01-01', 'DATE'), 'dateOnly']]
|
|
515
|
+
* })
|
|
516
|
+
*
|
|
517
|
+
* // CAST(column AS INTEGER)
|
|
518
|
+
* User.findAll({
|
|
519
|
+
* attributes: [[Op.cast(col('createdAt'), 'INTEGER'), 'dateInt']]
|
|
520
|
+
* })
|
|
521
|
+
*
|
|
522
|
+
* // CAST to DECIMAL
|
|
523
|
+
* User.findAll({
|
|
524
|
+
* attributes: [[Op.cast(col('price'), 'DECIMAL(10,2)'), 'priceDecimal']]
|
|
525
|
+
* })
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
readonly cast: (value: any, type: string) => CastExpression;
|
|
529
|
+
/**
|
|
530
|
+
* Create an EXTRACT expression for extracting date parts
|
|
531
|
+
* SQL: EXTRACT(part FROM field)
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* // EXTRACT(YEAR FROM createdAt)
|
|
536
|
+
* User.findAll({
|
|
537
|
+
* attributes: [[Op.extract('createdAt', 'year'), 'year']]
|
|
538
|
+
* })
|
|
539
|
+
*
|
|
540
|
+
* // EXTRACT(MONTH FROM order_date)
|
|
541
|
+
* User.findAll({
|
|
542
|
+
* attributes: [[Op.extract('orderDate', 'month'), 'month']]
|
|
543
|
+
* })
|
|
544
|
+
*
|
|
545
|
+
* // EXTRACT(HOUR FROM timestamp)
|
|
546
|
+
* User.findAll({
|
|
547
|
+
* attributes: [[Op.extract('createdAt', 'hour'), 'hour']]
|
|
548
|
+
* })
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
readonly extract: (field: any, part: ExtractPart) => ExtractExpression;
|
|
552
|
+
/**
|
|
553
|
+
* Create a CONVERT expression for type conversion
|
|
554
|
+
* SQL: CONVERT(value, type) for MySQL, CAST for other dialects
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```typescript
|
|
558
|
+
* // CONVERT(value, type)
|
|
559
|
+
* User.findAll({
|
|
560
|
+
* attributes: [[Op.conv(col('value'), null, 'CHAR'), 'strValue']]
|
|
561
|
+
* })
|
|
562
|
+
*
|
|
563
|
+
* // MySQL charset conversion
|
|
564
|
+
* User.findAll({
|
|
565
|
+
* attributes: [[Op.conv(col('name'), null, 'utf8mb4'), 'utf8Name']]
|
|
566
|
+
* })
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
readonly conv: (value: any, from: string | null | undefined, to: string) => ConvExpression;
|
|
570
|
+
/**
|
|
571
|
+
* Create a where clause with a column reference
|
|
572
|
+
* Supports both simple equality (2 args) and explicit operator (3 args)
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```typescript
|
|
576
|
+
* // Simple equality (2 args) - defaults to =
|
|
577
|
+
* Op.where(Op.col('username'), 'john')
|
|
578
|
+
* // => { $where: { $col: 'username', $eq: 'john' } }
|
|
579
|
+
*
|
|
580
|
+
* // Compare column to a value with explicit operator
|
|
581
|
+
* Op.where(Op.col('user.id'), '=', 1)
|
|
582
|
+
* // => { $where: { $col: 'user.id', $eq: 1 } }
|
|
583
|
+
*
|
|
584
|
+
* // Compare column to another column
|
|
585
|
+
* Op.where(Op.col('balance'), '>', Op.col('credit_limit'))
|
|
586
|
+
* // => { $where: { $col: 'balance', $gt: { $col: 'credit_limit' } } }
|
|
587
|
+
*
|
|
588
|
+
* // Using with Op.eq symbol
|
|
589
|
+
* Op.where(Op.col('user.id'), Op.eq, 1)
|
|
590
|
+
* // => { $where: { $col: 'user.id', $eq: 1 } }
|
|
591
|
+
*
|
|
592
|
+
* // Using with findAll
|
|
593
|
+
* User.findAll({ where: Op.where(Op.col('username'), 'john') })
|
|
594
|
+
* User.findAll({ where: Op.where('status', 'active') })
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
readonly where: (column: {
|
|
598
|
+
$col: string;
|
|
599
|
+
} | string, operator: any, value?: any) => {
|
|
600
|
+
$where: {
|
|
601
|
+
$col: string;
|
|
602
|
+
[key: string]: any;
|
|
603
|
+
};
|
|
604
|
+
} | Record<string, any>;
|
|
605
|
+
/**
|
|
606
|
+
* Create an ascending order expression
|
|
607
|
+
* SQL: ORDER BY field ASC
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```typescript
|
|
611
|
+
* // Order by name ascending
|
|
612
|
+
* User.findAll({ order: [Op.asc('name')] })
|
|
613
|
+
* // SQL: ORDER BY name ASC
|
|
614
|
+
*
|
|
615
|
+
* // Multiple order conditions
|
|
616
|
+
* User.findAll({ order: [Op.asc('name'), Op.desc('createdAt')] })
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
619
|
+
readonly asc: (field: string) => OrderExpression;
|
|
620
|
+
/**
|
|
621
|
+
* Create a descending order expression
|
|
622
|
+
* SQL: ORDER BY field DESC
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```typescript
|
|
626
|
+
* // Order by createdAt descending (newest first)
|
|
627
|
+
* User.findAll({ order: [Op.desc('createdAt')] })
|
|
628
|
+
* // SQL: ORDER BY createdAt DESC
|
|
629
|
+
*
|
|
630
|
+
* // Combined with asc
|
|
631
|
+
* User.findAll({ order: [Op.asc('name'), Op.desc('createdAt')] })
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
readonly desc: (field: string) => OrderExpression;
|
|
635
|
+
/**
|
|
636
|
+
* Create a random order expression
|
|
637
|
+
* SQL: ORDER BY RANDOM() (SQLite/PostgreSQL) or ORDER BY RAND() (MySQL)
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* ```typescript
|
|
641
|
+
* // Random ordering (useful for sampling)
|
|
642
|
+
* User.findAll({ order: [Op.random()] })
|
|
643
|
+
* // SQLite: ORDER BY RANDOM()
|
|
644
|
+
* // MySQL: ORDER BY RAND()
|
|
645
|
+
* // PostgreSQL: ORDER BY RANDOM()
|
|
646
|
+
*
|
|
647
|
+
* // With limit for random sample
|
|
648
|
+
* User.findAll({ order: [Op.random()], limit: 5 })
|
|
649
|
+
* ```
|
|
650
|
+
*/
|
|
651
|
+
readonly random: () => OrderExpression;
|
|
652
|
+
/**
|
|
653
|
+
* Check if a value is not null
|
|
654
|
+
* Returns true if the value is not null or undefined
|
|
655
|
+
* Useful as a predicate for filtering arrays
|
|
656
|
+
*
|
|
657
|
+
* @example
|
|
658
|
+
* ```typescript
|
|
659
|
+
* // Filter out null values from an array
|
|
660
|
+
* const values = [1, null, 2, undefined, 3];
|
|
661
|
+
* const notNullValues = values.filter(Op.isNotNull);
|
|
662
|
+
* // => [1, 2, 3]
|
|
663
|
+
*
|
|
664
|
+
* // Using in array filter with objects
|
|
665
|
+
* const users = [{ name: 'John', age: null }, { name: 'Jane', age: 25 }];
|
|
666
|
+
* const withAge = users.filter(u => Op.isNotNull(u.age));
|
|
667
|
+
* // => [{ name: 'Jane', age: 25 }]
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
readonly isNotNullPredicate: (value: any) => boolean;
|
|
671
|
+
/**
|
|
672
|
+
* Create a full-text search MATCH AGAINST condition (MySQL)
|
|
673
|
+
* SQL: MATCH(columns) AGAINST(searchTerm [IN NATURAL LANGUAGE MODE | IN BOOLEAN MODE])
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* ```typescript
|
|
677
|
+
* // Natural language mode search
|
|
678
|
+
* Article.findAll({
|
|
679
|
+
* where: {
|
|
680
|
+
* [Op.matchAgainst(['title', 'body'])]: 'database'
|
|
681
|
+
* }
|
|
682
|
+
* })
|
|
683
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('database' IN NATURAL LANGUAGE MODE)
|
|
684
|
+
*
|
|
685
|
+
* // Boolean mode search
|
|
686
|
+
* Article.findAll({
|
|
687
|
+
* where: {
|
|
688
|
+
* [Op.matchAgainst(['title', 'body'], { mode: 'boolean' })]: '+mysql -oracle'
|
|
689
|
+
* }
|
|
690
|
+
* })
|
|
691
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('+mysql -oracle' IN BOOLEAN MODE)
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
readonly matchAgainst: (columns: string | string[], options?: {
|
|
695
|
+
mode?: "natural" | "boolean";
|
|
696
|
+
}) => {
|
|
697
|
+
$match: {
|
|
698
|
+
columns: string[];
|
|
699
|
+
mode: "natural" | "boolean";
|
|
700
|
+
};
|
|
701
|
+
};
|
|
702
|
+
/**
|
|
703
|
+
* Create a full-text search condition (alias for matchAgainst with explicit mode)
|
|
704
|
+
* SQL: MATCH(columns) AGAINST(searchTerm IN NATURAL LANGUAGE MODE)
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```typescript
|
|
708
|
+
* Article.findAll({
|
|
709
|
+
* where: {
|
|
710
|
+
* [Op.matchFulltext(['title', 'body'])]: 'database'
|
|
711
|
+
* }
|
|
712
|
+
* })
|
|
713
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('database' IN NATURAL LANGUAGE MODE)
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
readonly matchFulltext: (columns: string | string[]) => {
|
|
717
|
+
$match: {
|
|
718
|
+
columns: string[];
|
|
719
|
+
mode: "natural";
|
|
720
|
+
};
|
|
721
|
+
};
|
|
722
|
+
/**
|
|
723
|
+
* Create a PostgreSQL tsvector expression
|
|
724
|
+
* SQL: to_tsvector(config, column)
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* ```typescript
|
|
728
|
+
* Article.findAll({
|
|
729
|
+
* where: {
|
|
730
|
+
* [Op.toTsvector('title')]: { $tsquery: 'database' }
|
|
731
|
+
* }
|
|
732
|
+
* })
|
|
733
|
+
* // SQL: WHERE to_tsvector('english', title) @@ to_tsquery('english', 'database')
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
readonly toTsvector: (column: string, config?: string) => {
|
|
737
|
+
$tsvector: {
|
|
738
|
+
column: string;
|
|
739
|
+
config: string;
|
|
740
|
+
};
|
|
741
|
+
};
|
|
742
|
+
/**
|
|
743
|
+
* Create a PostgreSQL tsquery expression
|
|
744
|
+
* SQL: to_tsquery(config, query)
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```typescript
|
|
748
|
+
* Article.findAll({
|
|
749
|
+
* where: {
|
|
750
|
+
* body: { [Op.toTsquery('database')]: true }
|
|
751
|
+
* }
|
|
752
|
+
* })
|
|
753
|
+
* // SQL: WHERE body @@ to_tsquery('english', 'database')
|
|
754
|
+
* ```
|
|
755
|
+
*/
|
|
756
|
+
readonly toTsquery: (query: string, config?: string) => {
|
|
757
|
+
$tsquery: {
|
|
758
|
+
query: string;
|
|
759
|
+
config: string;
|
|
760
|
+
};
|
|
761
|
+
};
|
|
762
|
+
/**
|
|
763
|
+
* ST_Distance - calculate distance between two geometries
|
|
764
|
+
* MySQL: ST_Distance(geom1, geom2)
|
|
765
|
+
* PostgreSQL: ST_Distance(geom1, geom2) - for geometry, ST_Distance(geog1, geog2) for geography
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* // Find locations within 100 meters of a point
|
|
770
|
+
* Location.findAll({
|
|
771
|
+
* where: {
|
|
772
|
+
* location: { [Op.stDWithin]: { from: 'POINT(0 0)', distance: 100, srid: 4326 } }
|
|
773
|
+
* }
|
|
774
|
+
* })
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
777
|
+
readonly stDistance: symbol;
|
|
778
|
+
/**
|
|
779
|
+
* ST_Within - check if geometry A is within geometry B
|
|
780
|
+
* MySQL: ST_Within(geom1, geom2)
|
|
781
|
+
* PostgreSQL: ST_Within(geom1, geom2)
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* ```typescript
|
|
785
|
+
* // Find locations within a polygon
|
|
786
|
+
* Location.findAll({
|
|
787
|
+
* where: {
|
|
788
|
+
* location: { [Op.stWithin]: { geometry: 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', srid: 4326 } }
|
|
789
|
+
* }
|
|
790
|
+
* })
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
readonly stWithin: symbol;
|
|
794
|
+
/**
|
|
795
|
+
* ST_Contains - check if geometry A contains geometry B
|
|
796
|
+
* MySQL: ST_Contains(geom1, geom2)
|
|
797
|
+
* PostgreSQL: ST_Contains(geom1, geom2)
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* // Find areas that contain a point
|
|
802
|
+
* Area.findAll({
|
|
803
|
+
* where: {
|
|
804
|
+
* boundary: { [Op.stContains]: { geometry: 'POINT(5 5)', srid: 4326 } }
|
|
805
|
+
* }
|
|
806
|
+
* })
|
|
807
|
+
* ```
|
|
808
|
+
*/
|
|
809
|
+
readonly stContains: symbol;
|
|
810
|
+
/**
|
|
811
|
+
* ST_Intersects - check if two geometries intersect
|
|
812
|
+
* MySQL: ST_Intersects(geom1, geom2)
|
|
813
|
+
* PostgreSQL: ST_Intersects(geom1, geom2)
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```typescript
|
|
817
|
+
* // Find locations that intersect with a polygon
|
|
818
|
+
* Location.findAll({
|
|
819
|
+
* where: {
|
|
820
|
+
* location: { [Op.stIntersects]: { geometry: 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', srid: 4326 } }
|
|
821
|
+
* }
|
|
822
|
+
* })
|
|
823
|
+
* ```
|
|
824
|
+
*/
|
|
825
|
+
readonly stIntersects: symbol;
|
|
826
|
+
/**
|
|
827
|
+
* ST_DWithin - check if geometries are within a given distance
|
|
828
|
+
* PostgreSQL: ST_DWithin (for both geometry and geography)
|
|
829
|
+
* MySQL 8.0+: ST_Distance_Sphere or ST_DWithin (with care)
|
|
830
|
+
*
|
|
831
|
+
* @example
|
|
832
|
+
* ```typescript
|
|
833
|
+
* // Find locations within 1km of a point
|
|
834
|
+
* Location.findAll({
|
|
835
|
+
* where: {
|
|
836
|
+
* location: { [Op.stDWithin]: { from: 'POINT(-122.4194 37.7749)', distance: 1000, srid: 4326 } }
|
|
837
|
+
* }
|
|
838
|
+
* })
|
|
839
|
+
* ```
|
|
840
|
+
*/
|
|
841
|
+
readonly stDWithin: symbol;
|
|
842
|
+
/**
|
|
843
|
+
* ST_Crosses - check if two geometries cross
|
|
844
|
+
* MySQL: ST_Crosses(geom1, geom2)
|
|
845
|
+
* PostgreSQL: ST_Crosses(geom1, geom2)
|
|
846
|
+
*/
|
|
847
|
+
readonly stCrosses: symbol;
|
|
848
|
+
/**
|
|
849
|
+
* ST_Overlaps - check if two geometries overlap
|
|
850
|
+
* MySQL: ST_Overlaps(geom1, geom2)
|
|
851
|
+
* PostgreSQL: ST_Overlaps(geom1, geom2)
|
|
852
|
+
*/
|
|
853
|
+
readonly stOverlaps: symbol;
|
|
854
|
+
/**
|
|
855
|
+
* ST_Touches - check if two geometries touch
|
|
856
|
+
* MySQL: ST_Touches(geom1, geom2)
|
|
857
|
+
* PostgreSQL: ST_Touches(geom1, geom2)
|
|
858
|
+
*/
|
|
859
|
+
readonly stTouches: symbol;
|
|
860
|
+
/**
|
|
861
|
+
* ST_Equals - check if two geometries are equal
|
|
862
|
+
* MySQL: ST_Equals(geom1, geom2)
|
|
863
|
+
* PostgreSQL: ST_Equals(geom1, geom2)
|
|
864
|
+
*/
|
|
865
|
+
readonly stEquals: symbol;
|
|
866
|
+
/**
|
|
867
|
+
* ST_IsValid - check if a geometry is valid
|
|
868
|
+
* MySQL: ST_IsValid(geom)
|
|
869
|
+
* PostgreSQL: ST_IsValid(geom)
|
|
870
|
+
*/
|
|
871
|
+
readonly stIsValid: symbol;
|
|
872
|
+
};
|
|
873
|
+
export type OpType = typeof Op;
|
|
874
|
+
export type OperatorSymbol = (typeof Op)[keyof typeof Op];
|
|
875
|
+
/**
|
|
876
|
+
* Check if a value is a column reference or needs column reference handling
|
|
877
|
+
*/
|
|
878
|
+
export declare function isColOperator(value: any): boolean;
|
|
879
|
+
export declare const Operators: {
|
|
880
|
+
readonly and: symbol;
|
|
881
|
+
readonly or: symbol;
|
|
882
|
+
readonly not: symbol;
|
|
883
|
+
readonly eq: symbol;
|
|
884
|
+
readonly is: symbol;
|
|
885
|
+
readonly ne: symbol;
|
|
886
|
+
readonly gt: symbol;
|
|
887
|
+
readonly gte: symbol;
|
|
888
|
+
readonly lt: symbol;
|
|
889
|
+
readonly lte: symbol;
|
|
890
|
+
readonly like: symbol;
|
|
891
|
+
readonly notLike: symbol;
|
|
892
|
+
readonly iLike: symbol;
|
|
893
|
+
readonly notILike: symbol;
|
|
894
|
+
readonly startsWith: symbol;
|
|
895
|
+
readonly notStartsWith: symbol;
|
|
896
|
+
readonly endsWith: symbol;
|
|
897
|
+
readonly notEndsWith: symbol;
|
|
898
|
+
readonly substring: symbol;
|
|
899
|
+
readonly notSubstring: symbol;
|
|
900
|
+
readonly col: symbol;
|
|
901
|
+
readonly in: symbol;
|
|
902
|
+
readonly notIn: symbol;
|
|
903
|
+
readonly between: symbol;
|
|
904
|
+
readonly notBetween: symbol;
|
|
905
|
+
readonly isNull: symbol;
|
|
906
|
+
readonly isNotNull: symbol;
|
|
907
|
+
readonly exists: symbol;
|
|
908
|
+
readonly notExists: symbol;
|
|
909
|
+
readonly regexp: symbol;
|
|
910
|
+
readonly notRegexp: symbol;
|
|
911
|
+
readonly iRegexp: symbol;
|
|
912
|
+
readonly notIRegexp: symbol;
|
|
913
|
+
readonly any: symbol;
|
|
914
|
+
readonly all: symbol;
|
|
915
|
+
readonly containsKey: symbol;
|
|
916
|
+
readonly containsKeyPath: symbol;
|
|
917
|
+
readonly containsPath: symbol;
|
|
918
|
+
readonly strictLeft: symbol;
|
|
919
|
+
readonly strictRight: symbol;
|
|
920
|
+
readonly noExtendRight: symbol;
|
|
921
|
+
readonly noExtendLeft: symbol;
|
|
922
|
+
readonly adj: symbol;
|
|
923
|
+
readonly notAdj: symbol;
|
|
924
|
+
/**
|
|
925
|
+
* Array contains - checks if an array contains all specified elements
|
|
926
|
+
* PostgreSQL: @>
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```typescript
|
|
930
|
+
* // Find products where tags contains both 'electronics' and 'sale'
|
|
931
|
+
* Product.findAll({ where: { tags: { [Op.arrayContains]: ['electronics', 'sale'] } } })
|
|
932
|
+
* // SQL: WHERE tags @> ARRAY['electronics', 'sale']
|
|
933
|
+
* ```
|
|
934
|
+
*/
|
|
935
|
+
readonly arrayContains: symbol;
|
|
936
|
+
/**
|
|
937
|
+
* Array contained by - checks if an array is contained by the specified elements
|
|
938
|
+
* PostgreSQL: <@
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* ```typescript
|
|
942
|
+
* // Find products where tags is contained by ['electronics', 'sale', 'new']
|
|
943
|
+
* Product.findAll({ where: { tags: { [Op.arrayContainedBy]: ['electronics', 'sale'] } } })
|
|
944
|
+
* // SQL: WHERE tags <@ ARRAY['electronics', 'sale']
|
|
945
|
+
* ```
|
|
946
|
+
*/
|
|
947
|
+
readonly arrayContainedBy: symbol;
|
|
948
|
+
/**
|
|
949
|
+
* Array overlaps - checks if arrays have common elements
|
|
950
|
+
* PostgreSQL: &&
|
|
951
|
+
*
|
|
952
|
+
* @example
|
|
953
|
+
* ```typescript
|
|
954
|
+
* // Find products where tags overlaps with ['electronics', 'sale']
|
|
955
|
+
* Product.findAll({ where: { tags: { [Op.arrayOverlaps]: ['electronics', 'sale'] } } })
|
|
956
|
+
* // SQL: WHERE tags && ARRAY['electronics', 'sale']
|
|
957
|
+
* ```
|
|
958
|
+
*/
|
|
959
|
+
readonly arrayOverlaps: symbol;
|
|
960
|
+
/**
|
|
961
|
+
* Array ANY - checks if any element matches the condition
|
|
962
|
+
* PostgreSQL: ANY
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```typescript
|
|
966
|
+
* // Find products where any tag equals 'electronics'
|
|
967
|
+
* Product.findAll({ where: { tags: { [Op.arrayAny]: 'electronics' } } })
|
|
968
|
+
* // SQL: WHERE 'electronics' = ANY(tags)
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
971
|
+
readonly arrayAny: symbol;
|
|
972
|
+
/**
|
|
973
|
+
* Array ALL - checks if all elements match the condition
|
|
974
|
+
* PostgreSQL: ALL
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
* ```typescript
|
|
978
|
+
* // Find products where all prices are greater than 100
|
|
979
|
+
* Product.findAll({ where: { prices: { [Op.arrayAll]: { [Op.gt]: 100 } } } })
|
|
980
|
+
* // SQL: WHERE 100 > ALL(prices)
|
|
981
|
+
* ```
|
|
982
|
+
*/
|
|
983
|
+
readonly arrayAll: symbol;
|
|
984
|
+
/**
|
|
985
|
+
* Starts with - checks if a string starts with the given value
|
|
986
|
+
* SQL: LIKE 'value%'
|
|
987
|
+
*
|
|
988
|
+
* @example
|
|
989
|
+
* ```typescript
|
|
990
|
+
* // Find users whose name starts with 'John'
|
|
991
|
+
* User.findAll({ where: { name: { [Op.startsWith]: 'John' } } })
|
|
992
|
+
* // SQL: WHERE name LIKE 'John%'
|
|
993
|
+
* ```
|
|
994
|
+
*/
|
|
995
|
+
/**
|
|
996
|
+
* Ends with - checks if a string ends with the given value
|
|
997
|
+
* SQL: LIKE '%value'
|
|
998
|
+
*
|
|
999
|
+
* @example
|
|
1000
|
+
* ```typescript
|
|
1001
|
+
* // Find users whose email ends with '@gmail.com'
|
|
1002
|
+
* User.findAll({ where: { email: { [Op.endsWith]: '@gmail.com' } } })
|
|
1003
|
+
* // SQL: WHERE email LIKE '%@gmail.com'
|
|
1004
|
+
* ```
|
|
1005
|
+
*/
|
|
1006
|
+
/**
|
|
1007
|
+
* JSON contains - checks if JSON document contains the specified value
|
|
1008
|
+
* PostgreSQL: @>
|
|
1009
|
+
* MySQL: JSON_CONTAINS
|
|
1010
|
+
* SQLite: JSON_EXTRACT
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```typescript
|
|
1014
|
+
* // Find users where preferences contains { theme: 'dark' }
|
|
1015
|
+
* User.findAll({ where: { preferences: { [Op.contains]: { theme: 'dark' } } } })
|
|
1016
|
+
* ```
|
|
1017
|
+
*/
|
|
1018
|
+
readonly contains: symbol;
|
|
1019
|
+
/**
|
|
1020
|
+
* JSON is contained in - checks if the value is contained in the JSON column
|
|
1021
|
+
* PostgreSQL: <@
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* ```typescript
|
|
1025
|
+
* // Find users where settings is contained in the specified JSON
|
|
1026
|
+
* User.findAll({ where: { settings: { [Op.containedBy]: { theme: 'dark', lang: 'en' } } } })
|
|
1027
|
+
* ```
|
|
1028
|
+
*/
|
|
1029
|
+
readonly containedBy: symbol;
|
|
1030
|
+
/**
|
|
1031
|
+
* JSON key exists - checks if a key (or array index) exists in a JSON object/array
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* // Find users where 'role' key exists in data column
|
|
1036
|
+
* User.findAll({ where: { data: { [Op.keyExists]: 'role' } } })
|
|
1037
|
+
*
|
|
1038
|
+
* // Find users where array index 0 exists
|
|
1039
|
+
* User.findAll({ where: { tags: { [Op.keyExists]: '0' } } })
|
|
1040
|
+
* ```
|
|
1041
|
+
*/
|
|
1042
|
+
readonly keyExists: symbol;
|
|
1043
|
+
/**
|
|
1044
|
+
* JSON overlap - checks if JSON arrays overlap (have common elements)
|
|
1045
|
+
* PostgreSQL: &&
|
|
1046
|
+
*
|
|
1047
|
+
* @example
|
|
1048
|
+
* ```typescript
|
|
1049
|
+
* // Find users where tags overlaps with ['admin', 'vip']
|
|
1050
|
+
* User.findAll({ where: { tags: { [Op.overlap]: ['admin', 'vip'] } } })
|
|
1051
|
+
* ```
|
|
1052
|
+
*/
|
|
1053
|
+
readonly overlap: symbol;
|
|
1054
|
+
/**
|
|
1055
|
+
* JSON key access - access a specific key in a JSON column
|
|
1056
|
+
* PostgreSQL: ->> for text, -> for object
|
|
1057
|
+
* MySQL: JSON_EXTRACT
|
|
1058
|
+
* SQLite: JSON_EXTRACT
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* ```typescript
|
|
1062
|
+
* // Find users where data->>'name' equals 'John'
|
|
1063
|
+
* User.findAll({ where: { data: { [Op.key]: 'name' } } })
|
|
1064
|
+
* // For nested: { field: { [Op.key]: 'profile.name' } }
|
|
1065
|
+
* ```
|
|
1066
|
+
*/
|
|
1067
|
+
/**
|
|
1068
|
+
* Column reference - reference another column in a WHERE clause
|
|
1069
|
+
* Used for comparing one column to another
|
|
1070
|
+
*
|
|
1071
|
+
* @example
|
|
1072
|
+
* ```typescript
|
|
1073
|
+
* // Find orders where quantity equals available stock
|
|
1074
|
+
* Order.findAll({ where: { quantity: { [Op.col]: 'available_stock' } } })
|
|
1075
|
+
* ```
|
|
1076
|
+
*/
|
|
1077
|
+
readonly match: symbol;
|
|
1078
|
+
readonly $json: symbol;
|
|
1079
|
+
/**
|
|
1080
|
+
* JSON path explicit operator - explicit JSON path with field and path separated
|
|
1081
|
+
* Convenience method combining field and path in one call
|
|
1082
|
+
*
|
|
1083
|
+
* @example
|
|
1084
|
+
* ```typescript
|
|
1085
|
+
* // Query with field and path separated
|
|
1086
|
+
* User.findAll({
|
|
1087
|
+
* where: {
|
|
1088
|
+
* data: { [Op.jsonPath('settings', 'theme')]: 'dark' }
|
|
1089
|
+
* }
|
|
1090
|
+
* })
|
|
1091
|
+
* // SQLite/MySQL: WHERE json_extract(data, '$.settings.theme') = 'dark'
|
|
1092
|
+
* // PostgreSQL: WHERE data->>'settings'->>'theme' = 'dark'
|
|
1093
|
+
*
|
|
1094
|
+
* // Check if path exists (no value comparison)
|
|
1095
|
+
* User.findAll({
|
|
1096
|
+
* where: {
|
|
1097
|
+
* data: { [Op.jsonPath('settings', 'theme')]: { [Op.ne]: null } }
|
|
1098
|
+
* }
|
|
1099
|
+
* })
|
|
1100
|
+
* ```
|
|
1101
|
+
*/
|
|
1102
|
+
readonly jsonPath: symbol;
|
|
1103
|
+
/**
|
|
1104
|
+
* JSON contains - checks if a JSON column contains a specific value or object
|
|
1105
|
+
* PostgreSQL: @> (contains), MySQL: JSON_CONTAINS, SQLite: json_each
|
|
1106
|
+
*
|
|
1107
|
+
* @example
|
|
1108
|
+
* ```typescript
|
|
1109
|
+
* // Find users where preferences contains { theme: 'dark' }
|
|
1110
|
+
* User.findAll({ where: { preferences: { [Op.jsonContains]: { theme: 'dark' } } } })
|
|
1111
|
+
* // SQL: WHERE preferences @> '{"theme":"dark"}' (PostgreSQL)
|
|
1112
|
+
* // SQL: WHERE JSON_CONTAINS(preferences, '{"theme":"dark"}') (MySQL)
|
|
1113
|
+
* ```
|
|
1114
|
+
*/
|
|
1115
|
+
readonly jsonContains: symbol;
|
|
1116
|
+
/**
|
|
1117
|
+
* JSON has key - checks if a JSON column has a specific key
|
|
1118
|
+
* PostgreSQL: ? (jsonb_exists), MySQL: JSON_CONTAINS_PATH, SQLite: json_each
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```typescript
|
|
1122
|
+
* // Find users where data column has 'role' key
|
|
1123
|
+
* User.findAll({ where: { data: { [Op.jsonHasKey]: 'role' } } })
|
|
1124
|
+
* // SQL: WHERE data ? 'role' (PostgreSQL)
|
|
1125
|
+
* // SQL: WHERE JSON_CONTAINS_PATH(data, 'one', '$.role') (MySQL)
|
|
1126
|
+
* ```
|
|
1127
|
+
*/
|
|
1128
|
+
readonly jsonHasKey: symbol;
|
|
1129
|
+
/**
|
|
1130
|
+
* JSONB extract - extracts a JSON object field (returns JSON)
|
|
1131
|
+
* PostgreSQL: -> operator
|
|
1132
|
+
*
|
|
1133
|
+
* @example
|
|
1134
|
+
* ```typescript
|
|
1135
|
+
* // Extract field as JSON: data -> 'key'
|
|
1136
|
+
* User.findAll({ where: { data: { [Op.jsonbExtract]: { path: 'key' } } } })
|
|
1137
|
+
* // SQL: WHERE data -> 'key'
|
|
1138
|
+
* ```
|
|
1139
|
+
*/
|
|
1140
|
+
readonly jsonbExtract: symbol;
|
|
1141
|
+
/**
|
|
1142
|
+
* JSONB extract text - extracts a JSON object field as text (returns text)
|
|
1143
|
+
* PostgreSQL: ->> operator
|
|
1144
|
+
*
|
|
1145
|
+
* @example
|
|
1146
|
+
* ```typescript
|
|
1147
|
+
* // Extract field as text: data ->> 'key'
|
|
1148
|
+
* User.findAll({ where: { data: { [Op.jsonbExtractText]: { path: 'key', value: 'someValue' } } } })
|
|
1149
|
+
* // SQL: WHERE data ->> 'key' = 'someValue'
|
|
1150
|
+
* ```
|
|
1151
|
+
*/
|
|
1152
|
+
readonly jsonbExtractText: symbol;
|
|
1153
|
+
/**
|
|
1154
|
+
* JSONB extract path - extracts JSON by path (returns JSON)
|
|
1155
|
+
* PostgreSQL: #> operator
|
|
1156
|
+
*
|
|
1157
|
+
* @example
|
|
1158
|
+
* ```typescript
|
|
1159
|
+
* // Extract nested path as JSON: data #> '{a, b}'
|
|
1160
|
+
* User.findAll({ where: { data: { [Op.jsonbExtractPath]: { path: ['a', 'b'] } } } })
|
|
1161
|
+
* // SQL: WHERE data #> '{a, b}'
|
|
1162
|
+
* ```
|
|
1163
|
+
*/
|
|
1164
|
+
readonly jsonbExtractPath: symbol;
|
|
1165
|
+
/**
|
|
1166
|
+
* JSONB extract path text - extracts JSON by path as text (returns text)
|
|
1167
|
+
* PostgreSQL: #>> operator
|
|
1168
|
+
*
|
|
1169
|
+
* @example
|
|
1170
|
+
* ```typescript
|
|
1171
|
+
* // Extract nested path as text: data #>> '{a, b}'
|
|
1172
|
+
* User.findAll({ where: { data: { [Op.jsonbExtractPathText]: { path: ['a', 'b'], value: 'someValue' } } } })
|
|
1173
|
+
* // SQL: WHERE data #>> '{a, b}' = 'someValue'
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
readonly jsonbExtractPathText: symbol;
|
|
1177
|
+
/**
|
|
1178
|
+
* JSONB concatenation - concatenates two JSONB values
|
|
1179
|
+
* PostgreSQL: || operator
|
|
1180
|
+
*
|
|
1181
|
+
* @example
|
|
1182
|
+
* ```typescript
|
|
1183
|
+
* // Concatenate JSONB values: data || '{"key": "value"}'
|
|
1184
|
+
* User.findAll({ where: { data: { [Op.jsonConcat]: { key: 'value' } } } })
|
|
1185
|
+
* // SQL: WHERE data || '{"key": "value"}'
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
readonly jsonConcat: symbol;
|
|
1189
|
+
/**
|
|
1190
|
+
* JSONB delete key - deletes a key from JSONB object
|
|
1191
|
+
* PostgreSQL: - operator
|
|
1192
|
+
*
|
|
1193
|
+
* @example
|
|
1194
|
+
* ```typescript
|
|
1195
|
+
* // Delete key from JSONB: data - 'key'
|
|
1196
|
+
* User.findAll({ where: { data: { [Op.jsonDelete]: 'key' } } })
|
|
1197
|
+
* // SQL: WHERE data - 'key'
|
|
1198
|
+
* ```
|
|
1199
|
+
*/
|
|
1200
|
+
readonly jsonDelete: symbol;
|
|
1201
|
+
/**
|
|
1202
|
+
* JSONB delete by path - deletes a key from JSONB by path
|
|
1203
|
+
* PostgreSQL: #- operator
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* ```typescript
|
|
1207
|
+
* // Delete by path: data #- '{a, b}'
|
|
1208
|
+
* User.findAll({ where: { data: { [Op.jsonDeletePath]: ['a', 'b'] } } })
|
|
1209
|
+
* // SQL: WHERE data #- '{a, b}'
|
|
1210
|
+
* ```
|
|
1211
|
+
*/
|
|
1212
|
+
readonly jsonDeletePath: symbol;
|
|
1213
|
+
/**
|
|
1214
|
+
* JSON path exists - checks if a JSON path exists and returns boolean
|
|
1215
|
+
* PostgreSQL: @? operator
|
|
1216
|
+
*
|
|
1217
|
+
* @example
|
|
1218
|
+
* ```typescript
|
|
1219
|
+
* // Check if path exists: data @? '$.key'
|
|
1220
|
+
* User.findAll({ where: { data: { [Op.jsonPathExists]: '$.key' } } })
|
|
1221
|
+
* // SQL: WHERE data @? '$.key'
|
|
1222
|
+
* ```
|
|
1223
|
+
*/
|
|
1224
|
+
readonly jsonPathExists: symbol;
|
|
1225
|
+
/**
|
|
1226
|
+
* JSON path query - evaluates JSON path and returns result
|
|
1227
|
+
* PostgreSQL: @@ operator
|
|
1228
|
+
*
|
|
1229
|
+
* @example
|
|
1230
|
+
* ```typescript
|
|
1231
|
+
* // Query JSON path: data @@ '$.key'
|
|
1232
|
+
* User.findAll({ where: { data: { [Op.jsonPathQuery]: '$.key' } } })
|
|
1233
|
+
* // SQL: WHERE data @@ '$.key'
|
|
1234
|
+
* ```
|
|
1235
|
+
*/
|
|
1236
|
+
readonly jsonPathQuery: symbol;
|
|
1237
|
+
/**
|
|
1238
|
+
* JSON type of - returns the type of a JSON value
|
|
1239
|
+
* PostgreSQL: json_typeof function
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```typescript
|
|
1243
|
+
* // Get JSON type: json_typeof(data)
|
|
1244
|
+
* User.findAll({ where: { data: { [Op.jsonTypeOf]: 'object' } } })
|
|
1245
|
+
* // SQL: WHERE json_typeof(data) = 'object'
|
|
1246
|
+
* ```
|
|
1247
|
+
*/
|
|
1248
|
+
readonly jsonTypeOf: symbol;
|
|
1249
|
+
/**
|
|
1250
|
+
* Create a JSON column path reference for querying
|
|
1251
|
+
* Returns a Symbol that can be used as a computed property key
|
|
1252
|
+
*
|
|
1253
|
+
* @example
|
|
1254
|
+
* ```typescript
|
|
1255
|
+
* // Using as computed property key (recommended)
|
|
1256
|
+
* User.findAll({
|
|
1257
|
+
* where: {
|
|
1258
|
+
* settings: { [Op.json('$.theme')]: 'dark' }
|
|
1259
|
+
* }
|
|
1260
|
+
* })
|
|
1261
|
+
* // SQL: WHERE json_extract(settings, '$.theme') = 'dark'
|
|
1262
|
+
*
|
|
1263
|
+
* // Using with path prefix
|
|
1264
|
+
* User.findAll({
|
|
1265
|
+
* where: {
|
|
1266
|
+
* data: { [Op.json('address.city')]: 'NYC' }
|
|
1267
|
+
* }
|
|
1268
|
+
* })
|
|
1269
|
+
* // SQL: WHERE json_extract(data, '$.address.city') = 'NYC'
|
|
1270
|
+
* ```
|
|
1271
|
+
*/
|
|
1272
|
+
readonly json: (path: string) => symbol;
|
|
1273
|
+
/**
|
|
1274
|
+
* Create a JSON key path query
|
|
1275
|
+
* Useful for accessing specific keys in a JSON/JSONB column
|
|
1276
|
+
*
|
|
1277
|
+
* @example
|
|
1278
|
+
* ```typescript
|
|
1279
|
+
* // Access JSON key 'name' from data column
|
|
1280
|
+
* User.findAll({
|
|
1281
|
+
* where: {
|
|
1282
|
+
* data: { [Op.key]: 'name' }
|
|
1283
|
+
* }
|
|
1284
|
+
* })
|
|
1285
|
+
*
|
|
1286
|
+
* // Compare JSON key to a value
|
|
1287
|
+
* User.findAll({
|
|
1288
|
+
* where: {
|
|
1289
|
+
* data: { [Op.key]: { path: 'name', value: 'John' } }
|
|
1290
|
+
* }
|
|
1291
|
+
* })
|
|
1292
|
+
*
|
|
1293
|
+
* // Nested key access
|
|
1294
|
+
* User.findAll({
|
|
1295
|
+
* where: {
|
|
1296
|
+
* data: { [Op.key]: { path: 'profile.settings.theme', value: 'dark' } }
|
|
1297
|
+
* }
|
|
1298
|
+
* })
|
|
1299
|
+
* ```
|
|
1300
|
+
*/
|
|
1301
|
+
readonly key: (pathOrOptions: string | {
|
|
1302
|
+
path: string;
|
|
1303
|
+
value?: any;
|
|
1304
|
+
}) => Record<string, any>;
|
|
1305
|
+
/**
|
|
1306
|
+
* Create a raw SQL literal
|
|
1307
|
+
* Useful for embedding raw SQL expressions like NOW(), CURRENT_TIMESTAMP, etc.
|
|
1308
|
+
*
|
|
1309
|
+
* @example
|
|
1310
|
+
* ```typescript
|
|
1311
|
+
* // Use with update to set current timestamp
|
|
1312
|
+
* User.update({ lastLogin: Op.literal('NOW()') }, { where: { ... } })
|
|
1313
|
+
*
|
|
1314
|
+
* // Use in where clause to compare with current time
|
|
1315
|
+
* User.findAll({
|
|
1316
|
+
* where: {
|
|
1317
|
+
* createdAt: { [Op.lt]: Op.literal('NOW()') }
|
|
1318
|
+
* }
|
|
1319
|
+
* })
|
|
1320
|
+
*
|
|
1321
|
+
* // Compare column to a literal value
|
|
1322
|
+
* User.findAll({
|
|
1323
|
+
* where: {
|
|
1324
|
+
* updatedAt: { [Op.gt]: Op.literal('createdAt') }
|
|
1325
|
+
* }
|
|
1326
|
+
* })
|
|
1327
|
+
*
|
|
1328
|
+
* // Use with Op.where
|
|
1329
|
+
* User.findAll({ where: Op.where(Op.col('created_at'), '>', Op.literal('NOW()')) })
|
|
1330
|
+
* ```
|
|
1331
|
+
*/
|
|
1332
|
+
readonly literal: (value: string) => LiteralValue;
|
|
1333
|
+
/**
|
|
1334
|
+
* Create a CAST expression for type casting
|
|
1335
|
+
* SQL: CAST(value AS type)
|
|
1336
|
+
*
|
|
1337
|
+
* @example
|
|
1338
|
+
* ```typescript
|
|
1339
|
+
* // CAST('2023-01-01' AS DATE)
|
|
1340
|
+
* User.findAll({
|
|
1341
|
+
* attributes: [[Op.cast('2023-01-01', 'DATE'), 'dateOnly']]
|
|
1342
|
+
* })
|
|
1343
|
+
*
|
|
1344
|
+
* // CAST(column AS INTEGER)
|
|
1345
|
+
* User.findAll({
|
|
1346
|
+
* attributes: [[Op.cast(col('createdAt'), 'INTEGER'), 'dateInt']]
|
|
1347
|
+
* })
|
|
1348
|
+
*
|
|
1349
|
+
* // CAST to DECIMAL
|
|
1350
|
+
* User.findAll({
|
|
1351
|
+
* attributes: [[Op.cast(col('price'), 'DECIMAL(10,2)'), 'priceDecimal']]
|
|
1352
|
+
* })
|
|
1353
|
+
* ```
|
|
1354
|
+
*/
|
|
1355
|
+
readonly cast: (value: any, type: string) => CastExpression;
|
|
1356
|
+
/**
|
|
1357
|
+
* Create an EXTRACT expression for extracting date parts
|
|
1358
|
+
* SQL: EXTRACT(part FROM field)
|
|
1359
|
+
*
|
|
1360
|
+
* @example
|
|
1361
|
+
* ```typescript
|
|
1362
|
+
* // EXTRACT(YEAR FROM createdAt)
|
|
1363
|
+
* User.findAll({
|
|
1364
|
+
* attributes: [[Op.extract('createdAt', 'year'), 'year']]
|
|
1365
|
+
* })
|
|
1366
|
+
*
|
|
1367
|
+
* // EXTRACT(MONTH FROM order_date)
|
|
1368
|
+
* User.findAll({
|
|
1369
|
+
* attributes: [[Op.extract('orderDate', 'month'), 'month']]
|
|
1370
|
+
* })
|
|
1371
|
+
*
|
|
1372
|
+
* // EXTRACT(HOUR FROM timestamp)
|
|
1373
|
+
* User.findAll({
|
|
1374
|
+
* attributes: [[Op.extract('createdAt', 'hour'), 'hour']]
|
|
1375
|
+
* })
|
|
1376
|
+
* ```
|
|
1377
|
+
*/
|
|
1378
|
+
readonly extract: (field: any, part: ExtractPart) => ExtractExpression;
|
|
1379
|
+
/**
|
|
1380
|
+
* Create a CONVERT expression for type conversion
|
|
1381
|
+
* SQL: CONVERT(value, type) for MySQL, CAST for other dialects
|
|
1382
|
+
*
|
|
1383
|
+
* @example
|
|
1384
|
+
* ```typescript
|
|
1385
|
+
* // CONVERT(value, type)
|
|
1386
|
+
* User.findAll({
|
|
1387
|
+
* attributes: [[Op.conv(col('value'), null, 'CHAR'), 'strValue']]
|
|
1388
|
+
* })
|
|
1389
|
+
*
|
|
1390
|
+
* // MySQL charset conversion
|
|
1391
|
+
* User.findAll({
|
|
1392
|
+
* attributes: [[Op.conv(col('name'), null, 'utf8mb4'), 'utf8Name']]
|
|
1393
|
+
* })
|
|
1394
|
+
* ```
|
|
1395
|
+
*/
|
|
1396
|
+
readonly conv: (value: any, from: string | null | undefined, to: string) => ConvExpression;
|
|
1397
|
+
/**
|
|
1398
|
+
* Create a where clause with a column reference
|
|
1399
|
+
* Supports both simple equality (2 args) and explicit operator (3 args)
|
|
1400
|
+
*
|
|
1401
|
+
* @example
|
|
1402
|
+
* ```typescript
|
|
1403
|
+
* // Simple equality (2 args) - defaults to =
|
|
1404
|
+
* Op.where(Op.col('username'), 'john')
|
|
1405
|
+
* // => { $where: { $col: 'username', $eq: 'john' } }
|
|
1406
|
+
*
|
|
1407
|
+
* // Compare column to a value with explicit operator
|
|
1408
|
+
* Op.where(Op.col('user.id'), '=', 1)
|
|
1409
|
+
* // => { $where: { $col: 'user.id', $eq: 1 } }
|
|
1410
|
+
*
|
|
1411
|
+
* // Compare column to another column
|
|
1412
|
+
* Op.where(Op.col('balance'), '>', Op.col('credit_limit'))
|
|
1413
|
+
* // => { $where: { $col: 'balance', $gt: { $col: 'credit_limit' } } }
|
|
1414
|
+
*
|
|
1415
|
+
* // Using with Op.eq symbol
|
|
1416
|
+
* Op.where(Op.col('user.id'), Op.eq, 1)
|
|
1417
|
+
* // => { $where: { $col: 'user.id', $eq: 1 } }
|
|
1418
|
+
*
|
|
1419
|
+
* // Using with findAll
|
|
1420
|
+
* User.findAll({ where: Op.where(Op.col('username'), 'john') })
|
|
1421
|
+
* User.findAll({ where: Op.where('status', 'active') })
|
|
1422
|
+
* ```
|
|
1423
|
+
*/
|
|
1424
|
+
readonly where: (column: {
|
|
1425
|
+
$col: string;
|
|
1426
|
+
} | string, operator: any, value?: any) => {
|
|
1427
|
+
$where: {
|
|
1428
|
+
$col: string;
|
|
1429
|
+
[key: string]: any;
|
|
1430
|
+
};
|
|
1431
|
+
} | Record<string, any>;
|
|
1432
|
+
/**
|
|
1433
|
+
* Create an ascending order expression
|
|
1434
|
+
* SQL: ORDER BY field ASC
|
|
1435
|
+
*
|
|
1436
|
+
* @example
|
|
1437
|
+
* ```typescript
|
|
1438
|
+
* // Order by name ascending
|
|
1439
|
+
* User.findAll({ order: [Op.asc('name')] })
|
|
1440
|
+
* // SQL: ORDER BY name ASC
|
|
1441
|
+
*
|
|
1442
|
+
* // Multiple order conditions
|
|
1443
|
+
* User.findAll({ order: [Op.asc('name'), Op.desc('createdAt')] })
|
|
1444
|
+
* ```
|
|
1445
|
+
*/
|
|
1446
|
+
readonly asc: (field: string) => OrderExpression;
|
|
1447
|
+
/**
|
|
1448
|
+
* Create a descending order expression
|
|
1449
|
+
* SQL: ORDER BY field DESC
|
|
1450
|
+
*
|
|
1451
|
+
* @example
|
|
1452
|
+
* ```typescript
|
|
1453
|
+
* // Order by createdAt descending (newest first)
|
|
1454
|
+
* User.findAll({ order: [Op.desc('createdAt')] })
|
|
1455
|
+
* // SQL: ORDER BY createdAt DESC
|
|
1456
|
+
*
|
|
1457
|
+
* // Combined with asc
|
|
1458
|
+
* User.findAll({ order: [Op.asc('name'), Op.desc('createdAt')] })
|
|
1459
|
+
* ```
|
|
1460
|
+
*/
|
|
1461
|
+
readonly desc: (field: string) => OrderExpression;
|
|
1462
|
+
/**
|
|
1463
|
+
* Create a random order expression
|
|
1464
|
+
* SQL: ORDER BY RANDOM() (SQLite/PostgreSQL) or ORDER BY RAND() (MySQL)
|
|
1465
|
+
*
|
|
1466
|
+
* @example
|
|
1467
|
+
* ```typescript
|
|
1468
|
+
* // Random ordering (useful for sampling)
|
|
1469
|
+
* User.findAll({ order: [Op.random()] })
|
|
1470
|
+
* // SQLite: ORDER BY RANDOM()
|
|
1471
|
+
* // MySQL: ORDER BY RAND()
|
|
1472
|
+
* // PostgreSQL: ORDER BY RANDOM()
|
|
1473
|
+
*
|
|
1474
|
+
* // With limit for random sample
|
|
1475
|
+
* User.findAll({ order: [Op.random()], limit: 5 })
|
|
1476
|
+
* ```
|
|
1477
|
+
*/
|
|
1478
|
+
readonly random: () => OrderExpression;
|
|
1479
|
+
/**
|
|
1480
|
+
* Check if a value is not null
|
|
1481
|
+
* Returns true if the value is not null or undefined
|
|
1482
|
+
* Useful as a predicate for filtering arrays
|
|
1483
|
+
*
|
|
1484
|
+
* @example
|
|
1485
|
+
* ```typescript
|
|
1486
|
+
* // Filter out null values from an array
|
|
1487
|
+
* const values = [1, null, 2, undefined, 3];
|
|
1488
|
+
* const notNullValues = values.filter(Op.isNotNull);
|
|
1489
|
+
* // => [1, 2, 3]
|
|
1490
|
+
*
|
|
1491
|
+
* // Using in array filter with objects
|
|
1492
|
+
* const users = [{ name: 'John', age: null }, { name: 'Jane', age: 25 }];
|
|
1493
|
+
* const withAge = users.filter(u => Op.isNotNull(u.age));
|
|
1494
|
+
* // => [{ name: 'Jane', age: 25 }]
|
|
1495
|
+
* ```
|
|
1496
|
+
*/
|
|
1497
|
+
readonly isNotNullPredicate: (value: any) => boolean;
|
|
1498
|
+
/**
|
|
1499
|
+
* Create a full-text search MATCH AGAINST condition (MySQL)
|
|
1500
|
+
* SQL: MATCH(columns) AGAINST(searchTerm [IN NATURAL LANGUAGE MODE | IN BOOLEAN MODE])
|
|
1501
|
+
*
|
|
1502
|
+
* @example
|
|
1503
|
+
* ```typescript
|
|
1504
|
+
* // Natural language mode search
|
|
1505
|
+
* Article.findAll({
|
|
1506
|
+
* where: {
|
|
1507
|
+
* [Op.matchAgainst(['title', 'body'])]: 'database'
|
|
1508
|
+
* }
|
|
1509
|
+
* })
|
|
1510
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('database' IN NATURAL LANGUAGE MODE)
|
|
1511
|
+
*
|
|
1512
|
+
* // Boolean mode search
|
|
1513
|
+
* Article.findAll({
|
|
1514
|
+
* where: {
|
|
1515
|
+
* [Op.matchAgainst(['title', 'body'], { mode: 'boolean' })]: '+mysql -oracle'
|
|
1516
|
+
* }
|
|
1517
|
+
* })
|
|
1518
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('+mysql -oracle' IN BOOLEAN MODE)
|
|
1519
|
+
* ```
|
|
1520
|
+
*/
|
|
1521
|
+
readonly matchAgainst: (columns: string | string[], options?: {
|
|
1522
|
+
mode?: "natural" | "boolean";
|
|
1523
|
+
}) => {
|
|
1524
|
+
$match: {
|
|
1525
|
+
columns: string[];
|
|
1526
|
+
mode: "natural" | "boolean";
|
|
1527
|
+
};
|
|
1528
|
+
};
|
|
1529
|
+
/**
|
|
1530
|
+
* Create a full-text search condition (alias for matchAgainst with explicit mode)
|
|
1531
|
+
* SQL: MATCH(columns) AGAINST(searchTerm IN NATURAL LANGUAGE MODE)
|
|
1532
|
+
*
|
|
1533
|
+
* @example
|
|
1534
|
+
* ```typescript
|
|
1535
|
+
* Article.findAll({
|
|
1536
|
+
* where: {
|
|
1537
|
+
* [Op.matchFulltext(['title', 'body'])]: 'database'
|
|
1538
|
+
* }
|
|
1539
|
+
* })
|
|
1540
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('database' IN NATURAL LANGUAGE MODE)
|
|
1541
|
+
* ```
|
|
1542
|
+
*/
|
|
1543
|
+
readonly matchFulltext: (columns: string | string[]) => {
|
|
1544
|
+
$match: {
|
|
1545
|
+
columns: string[];
|
|
1546
|
+
mode: "natural";
|
|
1547
|
+
};
|
|
1548
|
+
};
|
|
1549
|
+
/**
|
|
1550
|
+
* Create a PostgreSQL tsvector expression
|
|
1551
|
+
* SQL: to_tsvector(config, column)
|
|
1552
|
+
*
|
|
1553
|
+
* @example
|
|
1554
|
+
* ```typescript
|
|
1555
|
+
* Article.findAll({
|
|
1556
|
+
* where: {
|
|
1557
|
+
* [Op.toTsvector('title')]: { $tsquery: 'database' }
|
|
1558
|
+
* }
|
|
1559
|
+
* })
|
|
1560
|
+
* // SQL: WHERE to_tsvector('english', title) @@ to_tsquery('english', 'database')
|
|
1561
|
+
* ```
|
|
1562
|
+
*/
|
|
1563
|
+
readonly toTsvector: (column: string, config?: string) => {
|
|
1564
|
+
$tsvector: {
|
|
1565
|
+
column: string;
|
|
1566
|
+
config: string;
|
|
1567
|
+
};
|
|
1568
|
+
};
|
|
1569
|
+
/**
|
|
1570
|
+
* Create a PostgreSQL tsquery expression
|
|
1571
|
+
* SQL: to_tsquery(config, query)
|
|
1572
|
+
*
|
|
1573
|
+
* @example
|
|
1574
|
+
* ```typescript
|
|
1575
|
+
* Article.findAll({
|
|
1576
|
+
* where: {
|
|
1577
|
+
* body: { [Op.toTsquery('database')]: true }
|
|
1578
|
+
* }
|
|
1579
|
+
* })
|
|
1580
|
+
* // SQL: WHERE body @@ to_tsquery('english', 'database')
|
|
1581
|
+
* ```
|
|
1582
|
+
*/
|
|
1583
|
+
readonly toTsquery: (query: string, config?: string) => {
|
|
1584
|
+
$tsquery: {
|
|
1585
|
+
query: string;
|
|
1586
|
+
config: string;
|
|
1587
|
+
};
|
|
1588
|
+
};
|
|
1589
|
+
/**
|
|
1590
|
+
* ST_Distance - calculate distance between two geometries
|
|
1591
|
+
* MySQL: ST_Distance(geom1, geom2)
|
|
1592
|
+
* PostgreSQL: ST_Distance(geom1, geom2) - for geometry, ST_Distance(geog1, geog2) for geography
|
|
1593
|
+
*
|
|
1594
|
+
* @example
|
|
1595
|
+
* ```typescript
|
|
1596
|
+
* // Find locations within 100 meters of a point
|
|
1597
|
+
* Location.findAll({
|
|
1598
|
+
* where: {
|
|
1599
|
+
* location: { [Op.stDWithin]: { from: 'POINT(0 0)', distance: 100, srid: 4326 } }
|
|
1600
|
+
* }
|
|
1601
|
+
* })
|
|
1602
|
+
* ```
|
|
1603
|
+
*/
|
|
1604
|
+
readonly stDistance: symbol;
|
|
1605
|
+
/**
|
|
1606
|
+
* ST_Within - check if geometry A is within geometry B
|
|
1607
|
+
* MySQL: ST_Within(geom1, geom2)
|
|
1608
|
+
* PostgreSQL: ST_Within(geom1, geom2)
|
|
1609
|
+
*
|
|
1610
|
+
* @example
|
|
1611
|
+
* ```typescript
|
|
1612
|
+
* // Find locations within a polygon
|
|
1613
|
+
* Location.findAll({
|
|
1614
|
+
* where: {
|
|
1615
|
+
* location: { [Op.stWithin]: { geometry: 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', srid: 4326 } }
|
|
1616
|
+
* }
|
|
1617
|
+
* })
|
|
1618
|
+
* ```
|
|
1619
|
+
*/
|
|
1620
|
+
readonly stWithin: symbol;
|
|
1621
|
+
/**
|
|
1622
|
+
* ST_Contains - check if geometry A contains geometry B
|
|
1623
|
+
* MySQL: ST_Contains(geom1, geom2)
|
|
1624
|
+
* PostgreSQL: ST_Contains(geom1, geom2)
|
|
1625
|
+
*
|
|
1626
|
+
* @example
|
|
1627
|
+
* ```typescript
|
|
1628
|
+
* // Find areas that contain a point
|
|
1629
|
+
* Area.findAll({
|
|
1630
|
+
* where: {
|
|
1631
|
+
* boundary: { [Op.stContains]: { geometry: 'POINT(5 5)', srid: 4326 } }
|
|
1632
|
+
* }
|
|
1633
|
+
* })
|
|
1634
|
+
* ```
|
|
1635
|
+
*/
|
|
1636
|
+
readonly stContains: symbol;
|
|
1637
|
+
/**
|
|
1638
|
+
* ST_Intersects - check if two geometries intersect
|
|
1639
|
+
* MySQL: ST_Intersects(geom1, geom2)
|
|
1640
|
+
* PostgreSQL: ST_Intersects(geom1, geom2)
|
|
1641
|
+
*
|
|
1642
|
+
* @example
|
|
1643
|
+
* ```typescript
|
|
1644
|
+
* // Find locations that intersect with a polygon
|
|
1645
|
+
* Location.findAll({
|
|
1646
|
+
* where: {
|
|
1647
|
+
* location: { [Op.stIntersects]: { geometry: 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', srid: 4326 } }
|
|
1648
|
+
* }
|
|
1649
|
+
* })
|
|
1650
|
+
* ```
|
|
1651
|
+
*/
|
|
1652
|
+
readonly stIntersects: symbol;
|
|
1653
|
+
/**
|
|
1654
|
+
* ST_DWithin - check if geometries are within a given distance
|
|
1655
|
+
* PostgreSQL: ST_DWithin (for both geometry and geography)
|
|
1656
|
+
* MySQL 8.0+: ST_Distance_Sphere or ST_DWithin (with care)
|
|
1657
|
+
*
|
|
1658
|
+
* @example
|
|
1659
|
+
* ```typescript
|
|
1660
|
+
* // Find locations within 1km of a point
|
|
1661
|
+
* Location.findAll({
|
|
1662
|
+
* where: {
|
|
1663
|
+
* location: { [Op.stDWithin]: { from: 'POINT(-122.4194 37.7749)', distance: 1000, srid: 4326 } }
|
|
1664
|
+
* }
|
|
1665
|
+
* })
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
readonly stDWithin: symbol;
|
|
1669
|
+
/**
|
|
1670
|
+
* ST_Crosses - check if two geometries cross
|
|
1671
|
+
* MySQL: ST_Crosses(geom1, geom2)
|
|
1672
|
+
* PostgreSQL: ST_Crosses(geom1, geom2)
|
|
1673
|
+
*/
|
|
1674
|
+
readonly stCrosses: symbol;
|
|
1675
|
+
/**
|
|
1676
|
+
* ST_Overlaps - check if two geometries overlap
|
|
1677
|
+
* MySQL: ST_Overlaps(geom1, geom2)
|
|
1678
|
+
* PostgreSQL: ST_Overlaps(geom1, geom2)
|
|
1679
|
+
*/
|
|
1680
|
+
readonly stOverlaps: symbol;
|
|
1681
|
+
/**
|
|
1682
|
+
* ST_Touches - check if two geometries touch
|
|
1683
|
+
* MySQL: ST_Touches(geom1, geom2)
|
|
1684
|
+
* PostgreSQL: ST_Touches(geom1, geom2)
|
|
1685
|
+
*/
|
|
1686
|
+
readonly stTouches: symbol;
|
|
1687
|
+
/**
|
|
1688
|
+
* ST_Equals - check if two geometries are equal
|
|
1689
|
+
* MySQL: ST_Equals(geom1, geom2)
|
|
1690
|
+
* PostgreSQL: ST_Equals(geom1, geom2)
|
|
1691
|
+
*/
|
|
1692
|
+
readonly stEquals: symbol;
|
|
1693
|
+
/**
|
|
1694
|
+
* ST_IsValid - check if a geometry is valid
|
|
1695
|
+
* MySQL: ST_IsValid(geom)
|
|
1696
|
+
* PostgreSQL: ST_IsValid(geom)
|
|
1697
|
+
*/
|
|
1698
|
+
readonly stIsValid: symbol;
|
|
1699
|
+
};
|
|
1700
|
+
/**
|
|
1701
|
+
* Check if a value is a symbol operator
|
|
1702
|
+
*/
|
|
1703
|
+
export declare function isOperator(value: any): value is OperatorSymbol;
|
|
1704
|
+
/**
|
|
1705
|
+
* Get the string representation of an operator symbol
|
|
1706
|
+
*/
|
|
1707
|
+
export declare function getOperatorString(op: OperatorSymbol): string;
|
|
1708
|
+
/**
|
|
1709
|
+
* Create a where condition using an operator
|
|
1710
|
+
*/
|
|
1711
|
+
export interface WhereConditionOptions {
|
|
1712
|
+
column: string;
|
|
1713
|
+
operator: OperatorSymbol;
|
|
1714
|
+
value: any;
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* Convert operator symbol to where clause key
|
|
1718
|
+
*/
|
|
1719
|
+
export declare function operatorToWhereKey(op: OperatorSymbol): string;
|
|
1720
|
+
/**
|
|
1721
|
+
* Type for where condition object (plain object with field conditions)
|
|
1722
|
+
*/
|
|
1723
|
+
export type WhereConditionObject = Record<string, any>;
|
|
1724
|
+
/**
|
|
1725
|
+
* Helper to create where conditions
|
|
1726
|
+
* Supports multiple call signatures:
|
|
1727
|
+
* - where({ status: 'active', age: { $gte: 18 } }) - create WHERE from object
|
|
1728
|
+
* - where('age', Op.gte, 18) - create WHERE with operator
|
|
1729
|
+
* - where({ OR: [...] }) or where({ AND: [...] }) - nested conditions
|
|
1730
|
+
*
|
|
1731
|
+
* @example
|
|
1732
|
+
* // Object form - simple conditions
|
|
1733
|
+
* where({ status: 'active' })
|
|
1734
|
+
* // => { status: 'active' }
|
|
1735
|
+
*
|
|
1736
|
+
* // Object form - with operators
|
|
1737
|
+
* where({ age: { $gte: 18 }, status: 'active' })
|
|
1738
|
+
* // => { age: { $gte: 18 }, status: 'active' }
|
|
1739
|
+
*
|
|
1740
|
+
* // Three-argument form
|
|
1741
|
+
* where('age', Op.gte, 18)
|
|
1742
|
+
* // => { age: { $gte: 18 } }
|
|
1743
|
+
*
|
|
1744
|
+
* // Nested OR
|
|
1745
|
+
* where({ OR: [{ status: 'active' }, { role: 'admin' }] })
|
|
1746
|
+
* // => { $or: [{ status: 'active' }, { role: 'admin' }] }
|
|
1747
|
+
*
|
|
1748
|
+
* // Nested AND
|
|
1749
|
+
* where({ AND: [{ age: { $gte: 18 } }, { status: 'active' }] })
|
|
1750
|
+
* // => { $and: [{ age: { $gte: 18 } }, { status: 'active' }] }
|
|
1751
|
+
*/
|
|
1752
|
+
export declare function where(condition: WhereConditionObject): WhereConditionObject;
|
|
1753
|
+
export declare function where(column: string, operator: OperatorSymbol, value: any): Record<string, any>;
|
|
1754
|
+
/**
|
|
1755
|
+
* Helper to create AND conditions
|
|
1756
|
+
*/
|
|
1757
|
+
export declare function and(...conditions: any[]): {
|
|
1758
|
+
$and: any[];
|
|
1759
|
+
};
|
|
1760
|
+
/**
|
|
1761
|
+
* Helper to create OR conditions
|
|
1762
|
+
*/
|
|
1763
|
+
export declare function or(...conditions: any[]): {
|
|
1764
|
+
$or: any[];
|
|
1765
|
+
};
|
|
1766
|
+
/**
|
|
1767
|
+
* Helper to create NOT conditions
|
|
1768
|
+
*/
|
|
1769
|
+
export declare function not(condition: any): {
|
|
1770
|
+
$not: any;
|
|
1771
|
+
};
|
|
1772
|
+
/**
|
|
1773
|
+
* Helper to create equality condition
|
|
1774
|
+
*/
|
|
1775
|
+
export declare function eq(column: string, value: any): Record<string, any>;
|
|
1776
|
+
/**
|
|
1777
|
+
* Helper to create not equal condition
|
|
1778
|
+
*/
|
|
1779
|
+
export declare function ne(column: string, value: any): Record<string, any>;
|
|
1780
|
+
/**
|
|
1781
|
+
* Helper to create greater than condition
|
|
1782
|
+
*/
|
|
1783
|
+
export declare function gt(column: string, value: any): Record<string, any>;
|
|
1784
|
+
/**
|
|
1785
|
+
* Helper to create greater than or equal condition
|
|
1786
|
+
*/
|
|
1787
|
+
export declare function gte(column: string, value: any): Record<string, any>;
|
|
1788
|
+
/**
|
|
1789
|
+
* Helper to create less than condition
|
|
1790
|
+
*/
|
|
1791
|
+
export declare function lt(column: string, value: any): Record<string, any>;
|
|
1792
|
+
/**
|
|
1793
|
+
* Helper to create less than or equal condition
|
|
1794
|
+
*/
|
|
1795
|
+
export declare function lte(column: string, value: any): Record<string, any>;
|
|
1796
|
+
/**
|
|
1797
|
+
* Helper to create LIKE condition
|
|
1798
|
+
* Wraps the value with % on both sides for contains matching
|
|
1799
|
+
*/
|
|
1800
|
+
export declare function like(column: string, value: any): Record<string, any>;
|
|
1801
|
+
/**
|
|
1802
|
+
* Helper to create NOT LIKE condition
|
|
1803
|
+
*/
|
|
1804
|
+
export declare function notLike(column: string, value: any): Record<string, any>;
|
|
1805
|
+
/**
|
|
1806
|
+
* Helper to create IN condition
|
|
1807
|
+
*/
|
|
1808
|
+
export declare function inOp(column: string, values: any[]): Record<string, any>;
|
|
1809
|
+
/**
|
|
1810
|
+
* Helper to create NOT IN condition
|
|
1811
|
+
*/
|
|
1812
|
+
export declare function notIn(column: string, values: any[]): Record<string, any>;
|
|
1813
|
+
/**
|
|
1814
|
+
* Helper to create BETWEEN condition
|
|
1815
|
+
*/
|
|
1816
|
+
export declare function between(column: string, start: any, end: any): Record<string, any>;
|
|
1817
|
+
/**
|
|
1818
|
+
* Helper to create NOT BETWEEN condition
|
|
1819
|
+
*/
|
|
1820
|
+
export declare function notBetween(column: string, start: any, end: any): Record<string, any>;
|
|
1821
|
+
/**
|
|
1822
|
+
* Helper to create IS NULL condition
|
|
1823
|
+
*/
|
|
1824
|
+
export declare function isNull(column: string): Record<string, any>;
|
|
1825
|
+
/**
|
|
1826
|
+
* Helper to create IS NOT NULL condition
|
|
1827
|
+
*/
|
|
1828
|
+
export declare function isNotNull(column: string): Record<string, any>;
|
|
1829
|
+
/**
|
|
1830
|
+
* Helper to create NOT EXISTS condition for anti-joins
|
|
1831
|
+
* Returns records where the subquery returns no rows
|
|
1832
|
+
*
|
|
1833
|
+
* @example
|
|
1834
|
+
* // Find users with no orders
|
|
1835
|
+
* User.findAll({
|
|
1836
|
+
* where: notExists('SELECT 1 FROM orders WHERE orders.user_id = users.id')
|
|
1837
|
+
* })
|
|
1838
|
+
*/
|
|
1839
|
+
export declare function notExists(subquery: string | {
|
|
1840
|
+
$literal: string;
|
|
1841
|
+
}): Record<string, any>;
|
|
1842
|
+
/**
|
|
1843
|
+
* Helper to create EXISTS condition
|
|
1844
|
+
* Returns records where the subquery returns at least one row
|
|
1845
|
+
*
|
|
1846
|
+
* @example
|
|
1847
|
+
* // Find users with at least one order
|
|
1848
|
+
* User.findAll({
|
|
1849
|
+
* where: exists('SELECT 1 FROM orders WHERE orders.user_id = users.id')
|
|
1850
|
+
* })
|
|
1851
|
+
*/
|
|
1852
|
+
export declare function exists(subquery: string | {
|
|
1853
|
+
$literal: string;
|
|
1854
|
+
}): Record<string, any>;
|
|
1855
|
+
/**
|
|
1856
|
+
* Helper to create NOT IN with subquery condition for anti-joins
|
|
1857
|
+
* Returns records where the column value is not in the subquery result
|
|
1858
|
+
*
|
|
1859
|
+
* @example
|
|
1860
|
+
* // Find users not in the banned users list
|
|
1861
|
+
* User.findAll({
|
|
1862
|
+
* where: notInSubquery('id', 'SELECT user_id FROM banned_users')
|
|
1863
|
+
* })
|
|
1864
|
+
*/
|
|
1865
|
+
export declare function notInSubquery(column: string, subquery: string | {
|
|
1866
|
+
$literal: string;
|
|
1867
|
+
}): Record<string, any>;
|
|
1868
|
+
/**
|
|
1869
|
+
* Helper to create IN with subquery condition
|
|
1870
|
+
* Returns records where the column value is in the subquery result
|
|
1871
|
+
*
|
|
1872
|
+
* @example
|
|
1873
|
+
* // Find users that have placed orders
|
|
1874
|
+
* User.findAll({
|
|
1875
|
+
* where: inSubquery('id', 'SELECT user_id FROM orders')
|
|
1876
|
+
* })
|
|
1877
|
+
*/
|
|
1878
|
+
export declare function inSubquery(column: string, subquery: string | {
|
|
1879
|
+
$literal: string;
|
|
1880
|
+
}): Record<string, any>;
|
|
1881
|
+
/**
|
|
1882
|
+
* Helper to create an anti-join condition using LEFT JOIN WHERE NULL pattern
|
|
1883
|
+
* This is useful for finding records that don't have related records
|
|
1884
|
+
*
|
|
1885
|
+
* @example
|
|
1886
|
+
* // Find users with no orders - using LEFT JOIN WHERE NULL pattern
|
|
1887
|
+
* User.findAll({
|
|
1888
|
+
* include: [{
|
|
1889
|
+
* model: Order,
|
|
1890
|
+
* where: { userId: { [Op.col]: 'User.id' } },
|
|
1891
|
+
* antiJoin: true
|
|
1892
|
+
* }]
|
|
1893
|
+
* })
|
|
1894
|
+
*/
|
|
1895
|
+
export declare function antiJoin(model: any, options?: {
|
|
1896
|
+
as?: string;
|
|
1897
|
+
foreignKey?: string;
|
|
1898
|
+
where?: Record<string, any>;
|
|
1899
|
+
antiJoinType?: 'notExists' | 'notIn' | 'leftJoinIsNull';
|
|
1900
|
+
}): Record<string, any>;
|
|
1901
|
+
/**
|
|
1902
|
+
* Helper to create an exclude condition (alias for antiJoin)
|
|
1903
|
+
* Returns records that are NOT in the specified model/table
|
|
1904
|
+
*
|
|
1905
|
+
* @example
|
|
1906
|
+
* // Find users not in the banned users table
|
|
1907
|
+
* User.findAll({
|
|
1908
|
+
* include: [{ model: BannedUser, exclude: true }]
|
|
1909
|
+
* })
|
|
1910
|
+
*/
|
|
1911
|
+
export declare function exclude(model: any, options?: {
|
|
1912
|
+
as?: string;
|
|
1913
|
+
foreignKey?: string;
|
|
1914
|
+
where?: Record<string, any>;
|
|
1915
|
+
antiJoinType?: 'notExists' | 'notIn' | 'leftJoinIsNull';
|
|
1916
|
+
}): Record<string, any>;
|
|
1917
|
+
/**
|
|
1918
|
+
* Helper to create ILIKE (case-insensitive LIKE) condition
|
|
1919
|
+
*/
|
|
1920
|
+
export declare function iLike(column: string, value: any): Record<string, any>;
|
|
1921
|
+
/**
|
|
1922
|
+
* Helper to create NOT ILIKE (case-insensitive NOT LIKE) condition
|
|
1923
|
+
*/
|
|
1924
|
+
export declare function notILike(column: string, value: any): Record<string, any>;
|
|
1925
|
+
/**
|
|
1926
|
+
* Helper to create REGEXP condition
|
|
1927
|
+
*/
|
|
1928
|
+
export declare function regexp(column: string, pattern: string | RegExp): Record<string, any>;
|
|
1929
|
+
/**
|
|
1930
|
+
* Helper to create NOT REGEXP condition
|
|
1931
|
+
*/
|
|
1932
|
+
export declare function notRegexp(column: string, pattern: string | RegExp): Record<string, any>;
|
|
1933
|
+
/**
|
|
1934
|
+
* Helper to create IREGEXP (case-insensitive REGEXP) condition
|
|
1935
|
+
*/
|
|
1936
|
+
export declare function iRegexp(column: string, pattern: string | RegExp): Record<string, any>;
|
|
1937
|
+
/**
|
|
1938
|
+
* Helper to create NOT IREGEXP (case-insensitive NOT REGEXP) condition
|
|
1939
|
+
*/
|
|
1940
|
+
export declare function notIRegexp(column: string, pattern: string | RegExp): Record<string, any>;
|
|
1941
|
+
/**
|
|
1942
|
+
* Helper to create CONTAINS condition (for arrays/JSON)
|
|
1943
|
+
*/
|
|
1944
|
+
export declare function contains(column: string, value: any): Record<string, any>;
|
|
1945
|
+
/**
|
|
1946
|
+
* Helper to create OVERLAP condition (for arrays)
|
|
1947
|
+
*/
|
|
1948
|
+
export declare function overlap(column: string, value: any[]): Record<string, any>;
|
|
1949
|
+
/**
|
|
1950
|
+
* Helper to create array contains condition
|
|
1951
|
+
* PostgreSQL: @> operator
|
|
1952
|
+
*
|
|
1953
|
+
* @example
|
|
1954
|
+
* ```typescript
|
|
1955
|
+
* // Find products where tags contains both 'electronics' and 'sale'
|
|
1956
|
+
* Product.findAll({ where: arrayContains('tags', ['electronics', 'sale']) })
|
|
1957
|
+
* // SQL: WHERE tags @> ARRAY['electronics', 'sale']
|
|
1958
|
+
* ```
|
|
1959
|
+
*/
|
|
1960
|
+
export declare function arrayContains(column: string, value: any[]): Record<string, any>;
|
|
1961
|
+
/**
|
|
1962
|
+
* Helper to create array contained by condition
|
|
1963
|
+
* PostgreSQL: <@ operator
|
|
1964
|
+
*
|
|
1965
|
+
* @example
|
|
1966
|
+
* ```typescript
|
|
1967
|
+
* // Find products where tags is contained by ['electronics', 'sale']
|
|
1968
|
+
* Product.findAll({ where: arrayContainedBy('tags', ['electronics', 'sale']) })
|
|
1969
|
+
* // SQL: WHERE tags <@ ARRAY['electronics', 'sale']
|
|
1970
|
+
* ```
|
|
1971
|
+
*/
|
|
1972
|
+
export declare function arrayContainedBy(column: string, value: any[]): Record<string, any>;
|
|
1973
|
+
/**
|
|
1974
|
+
* Helper to create array overlaps condition
|
|
1975
|
+
* PostgreSQL: && operator
|
|
1976
|
+
*
|
|
1977
|
+
* @example
|
|
1978
|
+
* ```typescript
|
|
1979
|
+
* // Find products where tags overlaps with ['electronics', 'sale']
|
|
1980
|
+
* Product.findAll({ where: arrayOverlaps('tags', ['electronics', 'sale']) })
|
|
1981
|
+
* // SQL: WHERE tags && ARRAY['electronics', 'sale']
|
|
1982
|
+
* ```
|
|
1983
|
+
*/
|
|
1984
|
+
export declare function arrayOverlaps(column: string, value: any[]): Record<string, any>;
|
|
1985
|
+
/**
|
|
1986
|
+
* Helper to create array ANY condition
|
|
1987
|
+
* PostgreSQL: = ANY() operator
|
|
1988
|
+
*
|
|
1989
|
+
* @example
|
|
1990
|
+
* ```typescript
|
|
1991
|
+
* // Find products where any tag equals 'electronics'
|
|
1992
|
+
* Product.findAll({ where: arrayAny('tags', 'electronics') })
|
|
1993
|
+
* // SQL: WHERE 'electronics' = ANY(tags)
|
|
1994
|
+
* ```
|
|
1995
|
+
*/
|
|
1996
|
+
export declare function arrayAny(column: string, value: any): Record<string, any>;
|
|
1997
|
+
/**
|
|
1998
|
+
* Helper to create array ALL condition
|
|
1999
|
+
* PostgreSQL: ALL() operator
|
|
2000
|
+
*
|
|
2001
|
+
* @example
|
|
2002
|
+
* ```typescript
|
|
2003
|
+
* // Find products where all prices are greater than 100
|
|
2004
|
+
* Product.findAll({ where: arrayAll('prices', 100) })
|
|
2005
|
+
* // SQL: WHERE 100 > ALL(prices)
|
|
2006
|
+
* ```
|
|
2007
|
+
*/
|
|
2008
|
+
export declare function arrayAll(column: string, value: any): Record<string, any>;
|
|
2009
|
+
/**
|
|
2010
|
+
* Helper to create startsWith condition
|
|
2011
|
+
* Creates a LIKE 'value%' pattern
|
|
2012
|
+
*
|
|
2013
|
+
* @example
|
|
2014
|
+
* ```typescript
|
|
2015
|
+
* // Find users whose name starts with 'John'
|
|
2016
|
+
* User.findAll({ where: startsWith('name', 'John') })
|
|
2017
|
+
* // SQL: WHERE name LIKE 'John%'
|
|
2018
|
+
* ```
|
|
2019
|
+
*/
|
|
2020
|
+
export declare function startsWith(column: string, value: any): Record<string, any>;
|
|
2021
|
+
/**
|
|
2022
|
+
* Helper to create notStartsWith condition
|
|
2023
|
+
* Creates a NOT LIKE 'value%' pattern
|
|
2024
|
+
*/
|
|
2025
|
+
export declare function notStartsWith(column: string, value: any): Record<string, any>;
|
|
2026
|
+
/**
|
|
2027
|
+
* Helper to create endsWith condition
|
|
2028
|
+
* Creates a LIKE '%value' pattern
|
|
2029
|
+
*
|
|
2030
|
+
* @example
|
|
2031
|
+
* ```typescript
|
|
2032
|
+
* // Find users whose email ends with '@gmail.com'
|
|
2033
|
+
* User.findAll({ where: endsWith('email', '@gmail.com') })
|
|
2034
|
+
* // SQL: WHERE email LIKE '%@gmail.com'
|
|
2035
|
+
* ```
|
|
2036
|
+
*/
|
|
2037
|
+
export declare function endsWith(column: string, value: any): Record<string, any>;
|
|
2038
|
+
/**
|
|
2039
|
+
* Helper to create notEndsWith condition
|
|
2040
|
+
* Creates a NOT LIKE '%value' pattern
|
|
2041
|
+
*/
|
|
2042
|
+
export declare function notEndsWith(column: string, value: any): Record<string, any>;
|
|
2043
|
+
/**
|
|
2044
|
+
* Helper to create substring/contains condition
|
|
2045
|
+
* Creates a LIKE '%value%' pattern
|
|
2046
|
+
*
|
|
2047
|
+
* @example
|
|
2048
|
+
* ```typescript
|
|
2049
|
+
* // Find users whose name contains 'john'
|
|
2050
|
+
* User.findAll({ where: substring('name', 'john') })
|
|
2051
|
+
* // SQL: WHERE name LIKE '%john%'
|
|
2052
|
+
* ```
|
|
2053
|
+
*/
|
|
2054
|
+
export declare function substring(column: string, value: any): Record<string, any>;
|
|
2055
|
+
/**
|
|
2056
|
+
* Helper to create notSubstring condition
|
|
2057
|
+
* Creates a NOT LIKE '%value%' pattern
|
|
2058
|
+
*/
|
|
2059
|
+
export declare function notSubstring(column: string, value: any): Record<string, any>;
|
|
2060
|
+
/**
|
|
2061
|
+
* Helper to create ANY condition for array queries
|
|
2062
|
+
* PostgreSQL: column = ANY(array_column)
|
|
2063
|
+
*
|
|
2064
|
+
* @example
|
|
2065
|
+
* ```typescript
|
|
2066
|
+
* // Find users where role matches any value in the roles array
|
|
2067
|
+
* User.findAll({ where: { roles: { [Op.any]: ['admin', 'moderator'] } } })
|
|
2068
|
+
* ```
|
|
2069
|
+
*/
|
|
2070
|
+
export declare function anyOp(column: string, values: any[]): Record<string, any>;
|
|
2071
|
+
/**
|
|
2072
|
+
* Helper to create ALL condition for array queries
|
|
2073
|
+
* PostgreSQL: column = ALL(array_column)
|
|
2074
|
+
*
|
|
2075
|
+
* @example
|
|
2076
|
+
* ```typescript
|
|
2077
|
+
* // Find users where role matches all values in the roles array
|
|
2078
|
+
* User.findAll({ where: { roles: { [Op.all]: ['admin', 'moderator'] } } })
|
|
2079
|
+
* ```
|
|
2080
|
+
*/
|
|
2081
|
+
export declare function allOp(column: string, values: any[]): Record<string, any>;
|
|
2082
|
+
/**
|
|
2083
|
+
* Helper to create MATCH condition for full-text search
|
|
2084
|
+
* Database-specific: uses MATCH AGAINST in MySQL, @@ in PostgreSQL
|
|
2085
|
+
*
|
|
2086
|
+
* @example
|
|
2087
|
+
* ```typescript
|
|
2088
|
+
* // Full-text search
|
|
2089
|
+
* User.findAll({ where: match('bio', 'javascript programming') })
|
|
2090
|
+
* // MySQL: WHERE MATCH(bio) AGAINST('javascript programming')
|
|
2091
|
+
* // PostgreSQL: WHERE bio @@ to_tsquery('javascript')
|
|
2092
|
+
* ```
|
|
2093
|
+
*/
|
|
2094
|
+
export declare function match(column: string, pattern: string): Record<string, any>;
|
|
2095
|
+
export { inOp as in };
|
|
2096
|
+
export { anyOp as any };
|
|
2097
|
+
export { allOp as all };
|
|
2098
|
+
/**
|
|
2099
|
+
* Sort direction for `ORDER BY` clauses.
|
|
2100
|
+
*
|
|
2101
|
+
* Companion enum for the string-literal union that `OrderExpression.direction`
|
|
2102
|
+
* (and other order-direction fields across the public API) accepts. Passing the raw
|
|
2103
|
+
* string literals `'ASC'` / `'DESC'` continues to work unchanged — the enum is purely
|
|
2104
|
+
* an additive, opt-in convenience. Re-exported here from `./types` so it can be
|
|
2105
|
+
* imported from either module.
|
|
2106
|
+
*
|
|
2107
|
+
* @example
|
|
2108
|
+
* ```typescript
|
|
2109
|
+
* // Using raw string literals (still supported)
|
|
2110
|
+
* User.findAll({ order: [['name', 'ASC']] });
|
|
2111
|
+
*
|
|
2112
|
+
* // Using the SortDirection enum
|
|
2113
|
+
* import { SortDirection } from 'prorm';
|
|
2114
|
+
* User.findAll({ order: [['name', SortDirection.ASC]] });
|
|
2115
|
+
* ```
|
|
2116
|
+
*/
|
|
2117
|
+
export { SortDirection } from './types';
|
|
2118
|
+
/**
|
|
2119
|
+
* Represents an ORDER BY expression
|
|
2120
|
+
*/
|
|
2121
|
+
export interface OrderExpression {
|
|
2122
|
+
__type: 'order';
|
|
2123
|
+
field: string;
|
|
2124
|
+
direction: SortDirection | 'ASC' | 'DESC' | 'RANDOM';
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* Check if a value is an order expression
|
|
2128
|
+
*/
|
|
2129
|
+
export declare function isOrderExpression(value: any): value is OrderExpression;
|
|
2130
|
+
/**
|
|
2131
|
+
* Create an ascending order expression
|
|
2132
|
+
* SQL: ORDER BY field ASC
|
|
2133
|
+
*
|
|
2134
|
+
* @example
|
|
2135
|
+
* ```typescript
|
|
2136
|
+
* // Order by name ascending
|
|
2137
|
+
* User.findAll({ order: [asc('name')] })
|
|
2138
|
+
* // SQL: ORDER BY name ASC
|
|
2139
|
+
*
|
|
2140
|
+
* // Multiple order conditions
|
|
2141
|
+
* User.findAll({ order: [asc('name'), desc('createdAt')] })
|
|
2142
|
+
*
|
|
2143
|
+
* // Equivalent using the SortDirection enum directly (no helper function)
|
|
2144
|
+
* import { SortDirection } from 'prorm';
|
|
2145
|
+
* User.findAll({ order: [['name', SortDirection.ASC]] })
|
|
2146
|
+
* ```
|
|
2147
|
+
*/
|
|
2148
|
+
export declare function asc(field: string): OrderExpression;
|
|
2149
|
+
/**
|
|
2150
|
+
* Create a descending order expression
|
|
2151
|
+
* SQL: ORDER BY field DESC
|
|
2152
|
+
*
|
|
2153
|
+
* @example
|
|
2154
|
+
* ```typescript
|
|
2155
|
+
* // Order by createdAt descending (newest first)
|
|
2156
|
+
* User.findAll({ order: [desc('createdAt')] })
|
|
2157
|
+
* // SQL: ORDER BY createdAt DESC
|
|
2158
|
+
*
|
|
2159
|
+
* // Combined with asc
|
|
2160
|
+
* User.findAll({ order: [asc('name'), desc('createdAt')] })
|
|
2161
|
+
* ```
|
|
2162
|
+
*/
|
|
2163
|
+
export declare function desc(field: string): OrderExpression;
|
|
2164
|
+
/**
|
|
2165
|
+
* Create a random order expression
|
|
2166
|
+
* SQL: ORDER BY RANDOM() (SQLite/PostgreSQL) or ORDER BY RAND() (MySQL)
|
|
2167
|
+
*
|
|
2168
|
+
* @example
|
|
2169
|
+
* ```typescript
|
|
2170
|
+
* // Random ordering (useful for sampling)
|
|
2171
|
+
* User.findAll({ order: [random()] })
|
|
2172
|
+
* // SQLite: ORDER BY RANDOM()
|
|
2173
|
+
* // MySQL: ORDER BY RAND()
|
|
2174
|
+
* // PostgreSQL: ORDER BY RANDOM()
|
|
2175
|
+
*
|
|
2176
|
+
* // With limit for random sample
|
|
2177
|
+
* User.findAll({ order: [random()], limit: 5 })
|
|
2178
|
+
* ```
|
|
2179
|
+
*/
|
|
2180
|
+
export declare function random(): OrderExpression;
|
|
2181
|
+
/**
|
|
2182
|
+
* Create a full-text search MATCH AGAINST condition (MySQL)
|
|
2183
|
+
* SQL: MATCH(columns) AGAINST(searchTerm [IN NATURAL LANGUAGE MODE | IN BOOLEAN MODE])
|
|
2184
|
+
*
|
|
2185
|
+
* @example
|
|
2186
|
+
* ```typescript
|
|
2187
|
+
* // Natural language mode search
|
|
2188
|
+
* import { matchAgainst } from 'orm';
|
|
2189
|
+
* Article.findAll({
|
|
2190
|
+
* where: {
|
|
2191
|
+
* [matchAgainst(['title', 'body'])]: 'database'
|
|
2192
|
+
* }
|
|
2193
|
+
* })
|
|
2194
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('database' IN NATURAL LANGUAGE MODE)
|
|
2195
|
+
*
|
|
2196
|
+
* // Boolean mode search
|
|
2197
|
+
* Article.findAll({
|
|
2198
|
+
* where: {
|
|
2199
|
+
* [matchAgainst(['title', 'body'], { mode: 'boolean' })]: '+mysql -oracle'
|
|
2200
|
+
* }
|
|
2201
|
+
* })
|
|
2202
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('+mysql -oracle' IN BOOLEAN MODE)
|
|
2203
|
+
* ```
|
|
2204
|
+
*/
|
|
2205
|
+
export declare function matchAgainst(columns: string | string[], options?: FullTextSearchOptions): {
|
|
2206
|
+
$match: {
|
|
2207
|
+
columns: string[];
|
|
2208
|
+
mode: 'natural' | 'boolean';
|
|
2209
|
+
};
|
|
2210
|
+
};
|
|
2211
|
+
/**
|
|
2212
|
+
* Create an explicit full-text search condition (alias for natural language mode)
|
|
2213
|
+
* SQL: MATCH(columns) AGAINST(searchTerm IN NATURAL LANGUAGE MODE)
|
|
2214
|
+
*
|
|
2215
|
+
* @example
|
|
2216
|
+
* ```typescript
|
|
2217
|
+
* import { matchFulltext } from 'orm';
|
|
2218
|
+
* Article.findAll({
|
|
2219
|
+
* where: {
|
|
2220
|
+
* [matchFulltext(['title', 'body'])]: 'database'
|
|
2221
|
+
* }
|
|
2222
|
+
* })
|
|
2223
|
+
* // SQL: WHERE MATCH(title, body) AGAINST('database' IN NATURAL LANGUAGE MODE)
|
|
2224
|
+
* ```
|
|
2225
|
+
*/
|
|
2226
|
+
export declare function matchFulltext(columns: string | string[]): {
|
|
2227
|
+
$match: {
|
|
2228
|
+
columns: string[];
|
|
2229
|
+
mode: 'natural';
|
|
2230
|
+
};
|
|
2231
|
+
};
|
|
2232
|
+
/**
|
|
2233
|
+
* Create a PostgreSQL to_tsvector expression
|
|
2234
|
+
* SQL: to_tsvector(config, column)
|
|
2235
|
+
*
|
|
2236
|
+
* @example
|
|
2237
|
+
* ```typescript
|
|
2238
|
+
* import { toTsvector } from 'orm';
|
|
2239
|
+
* // Using with to_tsquery
|
|
2240
|
+
* Article.findAll({
|
|
2241
|
+
* where: {
|
|
2242
|
+
* [toTsvector('title')]: { $tsquery: 'database' }
|
|
2243
|
+
* }
|
|
2244
|
+
* })
|
|
2245
|
+
* // SQL: WHERE to_tsvector('english', title) @@ to_tsquery('english', 'database')
|
|
2246
|
+
* ```
|
|
2247
|
+
*/
|
|
2248
|
+
export declare function toTsvector(column: string, config?: string): {
|
|
2249
|
+
$tsvector: {
|
|
2250
|
+
column: string;
|
|
2251
|
+
config: string;
|
|
2252
|
+
};
|
|
2253
|
+
};
|
|
2254
|
+
/**
|
|
2255
|
+
* Create a PostgreSQL to_tsquery expression
|
|
2256
|
+
* SQL: to_tsquery(config, query)
|
|
2257
|
+
*
|
|
2258
|
+
* @example
|
|
2259
|
+
* ```typescript
|
|
2260
|
+
* import { toTsquery } from 'orm';
|
|
2261
|
+
* Article.findAll({
|
|
2262
|
+
* where: {
|
|
2263
|
+
* body: { [toTsquery('database')]: true }
|
|
2264
|
+
* }
|
|
2265
|
+
* })
|
|
2266
|
+
* // SQL: WHERE body @@ to_tsquery('english', 'database')
|
|
2267
|
+
* ```
|
|
2268
|
+
*/
|
|
2269
|
+
export declare function toTsquery(query: string, config?: string): {
|
|
2270
|
+
$tsquery: {
|
|
2271
|
+
query: string;
|
|
2272
|
+
config: string;
|
|
2273
|
+
};
|
|
2274
|
+
};
|
|
2275
|
+
/**
|
|
2276
|
+
* Create a PostgreSQL plainto_tsquery expression (for phrase searching)
|
|
2277
|
+
* SQL: plainto_tsquery(config, query)
|
|
2278
|
+
*
|
|
2279
|
+
* @example
|
|
2280
|
+
* ```typescript
|
|
2281
|
+
* import { plainToTsquery } from 'orm';
|
|
2282
|
+
* Article.findAll({
|
|
2283
|
+
* where: {
|
|
2284
|
+
* body: { [plainToTsquery('database systems')]: true }
|
|
2285
|
+
* }
|
|
2286
|
+
* })
|
|
2287
|
+
* // SQL: WHERE body @@ plainto_tsquery('english', 'database systems')
|
|
2288
|
+
* ```
|
|
2289
|
+
*/
|
|
2290
|
+
export declare function plainToTsquery(query: string, config?: string): {
|
|
2291
|
+
$plainTsquery: {
|
|
2292
|
+
query: string;
|
|
2293
|
+
config: string;
|
|
2294
|
+
};
|
|
2295
|
+
};
|
|
2296
|
+
/**
|
|
2297
|
+
* Create a PostgreSQL phraseto_tsquery expression (for exact phrase matching)
|
|
2298
|
+
* SQL: phraseto_tsquery(config, query)
|
|
2299
|
+
*
|
|
2300
|
+
* @example
|
|
2301
|
+
* ```typescript
|
|
2302
|
+
* import { phraseToTsquery } from 'orm';
|
|
2303
|
+
* Article.findAll({
|
|
2304
|
+
* where: {
|
|
2305
|
+
* body: { [phraseToTsquery('database')]: true }
|
|
2306
|
+
* }
|
|
2307
|
+
* })
|
|
2308
|
+
* // SQL: WHERE body @@ phraseto_tsquery('english', 'database')
|
|
2309
|
+
* ```
|
|
2310
|
+
*/
|
|
2311
|
+
export declare function phraseToTsquery(query: string, config?: string): {
|
|
2312
|
+
$phraseTsquery: {
|
|
2313
|
+
query: string;
|
|
2314
|
+
config: string;
|
|
2315
|
+
};
|
|
2316
|
+
};
|
|
2317
|
+
export default Op;
|
|
2318
|
+
/**
|
|
2319
|
+
* Helper to create CONTAINED condition (for JSON/arrays)
|
|
2320
|
+
* Checks if the JSON column is contained in the specified value
|
|
2321
|
+
*/
|
|
2322
|
+
export declare function contained(column: string, value: any): Record<string, any>;
|
|
2323
|
+
/**
|
|
2324
|
+
* Helper to create JSON key access condition
|
|
2325
|
+
* Access a specific key in a JSON column for comparison
|
|
2326
|
+
*/
|
|
2327
|
+
export declare function jsonKey(column: string, path: string, value?: any): Record<string, any>;
|
|
2328
|
+
/**
|
|
2329
|
+
* Helper to create JSON path extraction condition
|
|
2330
|
+
* Used for querying JSON/JSONB columns with path-based extraction
|
|
2331
|
+
*
|
|
2332
|
+
* @example
|
|
2333
|
+
* ```typescript
|
|
2334
|
+
* // Simple JSON path query
|
|
2335
|
+
* User.findAll({ where: json('settings', 'theme', 'dark') })
|
|
2336
|
+
* // SQL: WHERE json_extract(settings, '$.theme') = 'dark'
|
|
2337
|
+
*
|
|
2338
|
+
* // Nested path
|
|
2339
|
+
* User.findAll({ where: json('data', 'address.city', 'NYC') })
|
|
2340
|
+
* // SQL: WHERE json_extract(data, '$.address.city') = 'NYC'
|
|
2341
|
+
*
|
|
2342
|
+
* // With dot notation path (auto-prepended with $)
|
|
2343
|
+
* User.findAll({ where: json('preferences', 'notifications.enabled', true) })
|
|
2344
|
+
* // SQL: WHERE json_extract(preferences, '$.notifications.enabled') = true
|
|
2345
|
+
*
|
|
2346
|
+
* // Using with Op.json symbol directly in object
|
|
2347
|
+
* User.findAll({
|
|
2348
|
+
* where: {
|
|
2349
|
+
* settings: { [Op.json('theme')]: 'dark' }
|
|
2350
|
+
* }
|
|
2351
|
+
* })
|
|
2352
|
+
* // SQL: WHERE json_extract(settings, '$.theme') = 'dark'
|
|
2353
|
+
* ```
|
|
2354
|
+
*/
|
|
2355
|
+
export declare function json(column: string, path: string, value?: any): Record<string, any>;
|
|
2356
|
+
/**
|
|
2357
|
+
* Helper to create JSON contains condition
|
|
2358
|
+
* Checks if JSON column contains a specific value or object
|
|
2359
|
+
*
|
|
2360
|
+
* @example
|
|
2361
|
+
* ```typescript
|
|
2362
|
+
* // Find users where preferences contains { theme: 'dark' }
|
|
2363
|
+
* User.findAll({ where: { preferences: { [Op.jsonContains]: { theme: 'dark' } } } })
|
|
2364
|
+
* // SQL (PostgreSQL): WHERE preferences @> '{"theme":"dark"}'
|
|
2365
|
+
* // SQL (MySQL): WHERE JSON_CONTAINS(preferences, '{"theme":"dark"}')
|
|
2366
|
+
*
|
|
2367
|
+
* // Check if JSON array contains a value
|
|
2368
|
+
* User.findAll({ where: { tags: { [Op.jsonContains]: 'admin' } } })
|
|
2369
|
+
* ```
|
|
2370
|
+
*/
|
|
2371
|
+
export declare function jsonContains(column: string, value: any): Record<string, any>;
|
|
2372
|
+
/**
|
|
2373
|
+
* Helper to create JSON has key condition
|
|
2374
|
+
* Checks if JSON column has a specific key
|
|
2375
|
+
*
|
|
2376
|
+
* @example
|
|
2377
|
+
* ```typescript
|
|
2378
|
+
* // Find users where data column has 'role' key
|
|
2379
|
+
* User.findAll({ where: { data: { [Op.jsonHasKey]: 'role' } } })
|
|
2380
|
+
* // SQL (PostgreSQL): WHERE data ? 'role'
|
|
2381
|
+
* // SQL (MySQL): WHERE JSON_CONTAINS_PATH(data, 'one', '$.role')
|
|
2382
|
+
*
|
|
2383
|
+
* // Nested key
|
|
2384
|
+
* User.findAll({ where: { data: { [Op.jsonHasKey]: 'settings.theme' } } })
|
|
2385
|
+
* ```
|
|
2386
|
+
*/
|
|
2387
|
+
export declare function jsonHasKey(column: string, key: string): Record<string, any>;
|
|
2388
|
+
/**
|
|
2389
|
+
* Helper to create JSONB concatenation condition
|
|
2390
|
+
* Concatenates two JSONB values (PostgreSQL || operator)
|
|
2391
|
+
*
|
|
2392
|
+
* @example
|
|
2393
|
+
* ```typescript
|
|
2394
|
+
* // Concatenate JSONB values
|
|
2395
|
+
* User.findAll({ where: jsonConcat('data', { key: 'value' }) })
|
|
2396
|
+
* // SQL: WHERE data || '{"key": "value"}'
|
|
2397
|
+
* ```
|
|
2398
|
+
*/
|
|
2399
|
+
export declare function jsonConcat(column: string, jsonValue: object | any[]): Record<string, any>;
|
|
2400
|
+
/**
|
|
2401
|
+
* Helper to create JSONB delete key condition
|
|
2402
|
+
* Deletes a key from JSONB object (PostgreSQL - operator)
|
|
2403
|
+
*
|
|
2404
|
+
* @example
|
|
2405
|
+
* ```typescript
|
|
2406
|
+
* // Delete key from JSONB
|
|
2407
|
+
* User.findAll({ where: jsonDelete('data', 'key') })
|
|
2408
|
+
* // SQL: WHERE data - 'key'
|
|
2409
|
+
* ```
|
|
2410
|
+
*/
|
|
2411
|
+
export declare function jsonDelete(column: string, key: string): Record<string, any>;
|
|
2412
|
+
/**
|
|
2413
|
+
* Helper to create JSONB delete by path condition
|
|
2414
|
+
* Deletes a key from JSONB by path (PostgreSQL #- operator)
|
|
2415
|
+
*
|
|
2416
|
+
* @example
|
|
2417
|
+
* ```typescript
|
|
2418
|
+
* // Delete by path
|
|
2419
|
+
* User.findAll({ where: jsonDeletePath('data', ['a', 'b']) })
|
|
2420
|
+
* // SQL: WHERE data #- '{a, b}'
|
|
2421
|
+
* ```
|
|
2422
|
+
*/
|
|
2423
|
+
export declare function jsonDeletePath(column: string, path: string | string[]): Record<string, any>;
|
|
2424
|
+
/**
|
|
2425
|
+
* Helper to create JSON path exists condition
|
|
2426
|
+
* Checks if a JSON path exists and returns boolean (PostgreSQL @? operator)
|
|
2427
|
+
*
|
|
2428
|
+
* @example
|
|
2429
|
+
* ```typescript
|
|
2430
|
+
* // Check if path exists
|
|
2431
|
+
* User.findAll({ where: jsonPathExists('data', '$.key') })
|
|
2432
|
+
* // SQL: WHERE data @? '$.key'
|
|
2433
|
+
* ```
|
|
2434
|
+
*/
|
|
2435
|
+
export declare function jsonPathExists(column: string, path: string): Record<string, any>;
|
|
2436
|
+
/**
|
|
2437
|
+
* Helper to create JSON path query condition
|
|
2438
|
+
* Evaluates JSON path and returns result (PostgreSQL @@ operator)
|
|
2439
|
+
*
|
|
2440
|
+
* @example
|
|
2441
|
+
* ```typescript
|
|
2442
|
+
* // Query JSON path
|
|
2443
|
+
* User.findAll({ where: jsonPathQuery('data', '$.key') })
|
|
2444
|
+
* // SQL: WHERE data @@ '$.key'
|
|
2445
|
+
* ```
|
|
2446
|
+
*/
|
|
2447
|
+
export declare function jsonPathQuery(column: string, path: string): Record<string, any>;
|
|
2448
|
+
/**
|
|
2449
|
+
* Represents a SQL function expression
|
|
2450
|
+
* Used in attributes to create aggregate queries
|
|
2451
|
+
*
|
|
2452
|
+
* @example
|
|
2453
|
+
* ```typescript
|
|
2454
|
+
* // Count all records
|
|
2455
|
+
* User.findAll({
|
|
2456
|
+
* attributes: [[fn('COUNT', col('id')), 'count']]
|
|
2457
|
+
* })
|
|
2458
|
+
*
|
|
2459
|
+
* // Count distinct values
|
|
2460
|
+
* User.findAll({
|
|
2461
|
+
* attributes: [[fn('COUNT', fn('DISTINCT', col('role'))), 'uniqueRoles']]
|
|
2462
|
+
* })
|
|
2463
|
+
*
|
|
2464
|
+
* // Sum with group by
|
|
2465
|
+
* User.findAll({
|
|
2466
|
+
* attributes: ['role', [fn('SUM', col('score')), 'totalScore']],
|
|
2467
|
+
* group: ['role']
|
|
2468
|
+
* })
|
|
2469
|
+
* ```
|
|
2470
|
+
*/
|
|
2471
|
+
export interface FnExpression {
|
|
2472
|
+
__type: 'fn';
|
|
2473
|
+
fn: string;
|
|
2474
|
+
args: any[];
|
|
2475
|
+
}
|
|
2476
|
+
/**
|
|
2477
|
+
* Type for extract parts
|
|
2478
|
+
*/
|
|
2479
|
+
export type ExtractPart = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second';
|
|
2480
|
+
/**
|
|
2481
|
+
* Represents a CAST expression for type casting
|
|
2482
|
+
* SQL: CAST(value AS type)
|
|
2483
|
+
*
|
|
2484
|
+
* @example
|
|
2485
|
+
* ```typescript
|
|
2486
|
+
* // CAST('2023-01-01' AS DATE)
|
|
2487
|
+
* cast('2023-01-01', 'DATE')
|
|
2488
|
+
*
|
|
2489
|
+
* // CAST(column AS INTEGER)
|
|
2490
|
+
* cast(col('amount'), 'INTEGER')
|
|
2491
|
+
* ```
|
|
2492
|
+
*/
|
|
2493
|
+
export interface CastExpression {
|
|
2494
|
+
__type: 'cast';
|
|
2495
|
+
value: any;
|
|
2496
|
+
type: string;
|
|
2497
|
+
}
|
|
2498
|
+
/**
|
|
2499
|
+
* Represents an EXTRACT expression for extracting date parts
|
|
2500
|
+
* SQL: EXTRACT(part FROM field)
|
|
2501
|
+
*
|
|
2502
|
+
* @example
|
|
2503
|
+
* ```typescript
|
|
2504
|
+
* // EXTRACT(YEAR FROM createdAt)
|
|
2505
|
+
* extract('createdAt', 'year')
|
|
2506
|
+
*
|
|
2507
|
+
* // EXTRACT(MONTH FROM order_date)
|
|
2508
|
+
* extract(col('order_date'), 'month')
|
|
2509
|
+
* ```
|
|
2510
|
+
*/
|
|
2511
|
+
export interface ExtractExpression {
|
|
2512
|
+
__type: 'extract';
|
|
2513
|
+
field: any;
|
|
2514
|
+
part: ExtractPart;
|
|
2515
|
+
}
|
|
2516
|
+
/**
|
|
2517
|
+
* Represents a CONVERT expression for type conversion (MySQL)
|
|
2518
|
+
* SQL: CONVERT(value, type) or CONVERT(value USING charset)
|
|
2519
|
+
*
|
|
2520
|
+
* @example
|
|
2521
|
+
* ```typescript
|
|
2522
|
+
* // CONVERT(value, type)
|
|
2523
|
+
* conv(value, 'INTEGER', 'UNSIGNED')
|
|
2524
|
+
*
|
|
2525
|
+
* // CONVERT(value USING utf8mb4)
|
|
2526
|
+
* conv(value, null, 'utf8mb4')
|
|
2527
|
+
* ```
|
|
2528
|
+
*/
|
|
2529
|
+
export interface ConvExpression {
|
|
2530
|
+
__type: 'conv';
|
|
2531
|
+
value: any;
|
|
2532
|
+
from?: string | null;
|
|
2533
|
+
to: string;
|
|
2534
|
+
}
|
|
2535
|
+
/**
|
|
2536
|
+
* Create a SQL function expression
|
|
2537
|
+
* @param fnName - The SQL function name (e.g., 'COUNT', 'SUM', 'AVG', 'MAX', 'MIN')
|
|
2538
|
+
* @param args - Function arguments (can include col() expressions)
|
|
2539
|
+
*/
|
|
2540
|
+
export declare function fn(fnName: string, ...args: any[]): FnExpression;
|
|
2541
|
+
/**
|
|
2542
|
+
* Represents a column reference expression
|
|
2543
|
+
*/
|
|
2544
|
+
export interface ColExpression {
|
|
2545
|
+
__type: 'col';
|
|
2546
|
+
col: string;
|
|
2547
|
+
}
|
|
2548
|
+
/**
|
|
2549
|
+
* Create a column reference for use in SQL functions
|
|
2550
|
+
* @param colName - The column name (supports 'table.column' format)
|
|
2551
|
+
*
|
|
2552
|
+
* @example
|
|
2553
|
+
* ```typescript
|
|
2554
|
+
* col('id') // -> "id"
|
|
2555
|
+
* col('user.id') // -> "user.id"
|
|
2556
|
+
* col('users.name') // -> "users.name"
|
|
2557
|
+
* ```
|
|
2558
|
+
*/
|
|
2559
|
+
export declare function col(colName: string): ColExpression;
|
|
2560
|
+
/**
|
|
2561
|
+
* Represents a literal SQL expression
|
|
2562
|
+
*/
|
|
2563
|
+
export interface LiteralExpression {
|
|
2564
|
+
__type: 'literal';
|
|
2565
|
+
sql: string;
|
|
2566
|
+
/**
|
|
2567
|
+
* Values substituted into the `?` placeholders in `sql`.
|
|
2568
|
+
*
|
|
2569
|
+
* Without this the only escape hatch for an expression the typed API can't
|
|
2570
|
+
* build was string concatenation, which is an injection surface precisely
|
|
2571
|
+
* where user input is most likely to appear. Prefer:
|
|
2572
|
+
*
|
|
2573
|
+
* literalExpr('price * ? + ?', [rate, fee])
|
|
2574
|
+
*
|
|
2575
|
+
* over building the string yourself. Values are escaped by the dialect.
|
|
2576
|
+
*/
|
|
2577
|
+
bindings?: unknown[];
|
|
2578
|
+
}
|
|
2579
|
+
/**
|
|
2580
|
+
* Substitute a literal expression's bindings into its `?` placeholders.
|
|
2581
|
+
*
|
|
2582
|
+
* Dialects call this with their own `escape` so values are quoted according to
|
|
2583
|
+
* the target database's rules. Exported so every dialect shares one
|
|
2584
|
+
* implementation rather than re-deriving the placeholder scan.
|
|
2585
|
+
*/
|
|
2586
|
+
export declare function expandLiteralBindings(expr: {
|
|
2587
|
+
sql: string;
|
|
2588
|
+
bindings?: unknown[];
|
|
2589
|
+
}, escape: (value: unknown) => string): string;
|
|
2590
|
+
/**
|
|
2591
|
+
* Create a literal SQL expression (inserted as-is into the query)
|
|
2592
|
+
* Returns { $literal: value } format for raw SQL expressions
|
|
2593
|
+
* Use with caution - this can lead to SQL injection if user input is included
|
|
2594
|
+
*
|
|
2595
|
+
* @example
|
|
2596
|
+
* ```typescript
|
|
2597
|
+
* // Use with update to set current timestamp
|
|
2598
|
+
* User.update({ lastLogin: literal('NOW()') }, { where: { ... } })
|
|
2599
|
+
*
|
|
2600
|
+
* // Use in where clause to compare with current time
|
|
2601
|
+
* User.findAll({
|
|
2602
|
+
* where: {
|
|
2603
|
+
* createdAt: { [Op.lt]: literal('NOW()') }
|
|
2604
|
+
* }
|
|
2605
|
+
* })
|
|
2606
|
+
*
|
|
2607
|
+
* // Compare column to a literal value
|
|
2608
|
+
* User.findAll({
|
|
2609
|
+
* where: {
|
|
2610
|
+
* updatedAt: { [Op.gt]: literal('createdAt') }
|
|
2611
|
+
* }
|
|
2612
|
+
* })
|
|
2613
|
+
* ```
|
|
2614
|
+
*/
|
|
2615
|
+
export declare function literal(value: string): {
|
|
2616
|
+
$literal: string;
|
|
2617
|
+
};
|
|
2618
|
+
/**
|
|
2619
|
+
* Create a literal SQL expression (inserted as-is into the query)
|
|
2620
|
+
* Returns { __type: 'literal', sql: string } format
|
|
2621
|
+
* Use with caution - this can lead to SQL injection if user input is included
|
|
2622
|
+
*
|
|
2623
|
+
* @example
|
|
2624
|
+
* ```typescript
|
|
2625
|
+
* literalExpr('COUNT(*)') // -> { __type: 'literal', sql: 'COUNT(*)' }
|
|
2626
|
+
* literalExpr('NOW()') // -> { __type: 'literal', sql: 'NOW()' }
|
|
2627
|
+
* literalExpr('1 + 1') // -> { __type: 'literal', sql: '1 + 1' }
|
|
2628
|
+
* ```
|
|
2629
|
+
*/
|
|
2630
|
+
export declare function literalExpr(sql: string, bindings?: unknown[]): LiteralExpression;
|
|
2631
|
+
/**
|
|
2632
|
+
* Check if a value is a function expression
|
|
2633
|
+
*/
|
|
2634
|
+
export declare function isFnExpression(value: any): value is FnExpression;
|
|
2635
|
+
/**
|
|
2636
|
+
* Check if a value is a column expression
|
|
2637
|
+
*/
|
|
2638
|
+
export declare function isColExpression(value: any): value is ColExpression;
|
|
2639
|
+
/**
|
|
2640
|
+
* Check if a value is a literal expression
|
|
2641
|
+
* Supports both { $literal: value } and { __type: 'literal', sql } formats
|
|
2642
|
+
*/
|
|
2643
|
+
export declare function isLiteralExpression(value: any): value is LiteralExpression | {
|
|
2644
|
+
$literal: string;
|
|
2645
|
+
};
|
|
2646
|
+
/**
|
|
2647
|
+
* Check if a value is a raw SQL literal ({ $literal: value } format)
|
|
2648
|
+
*/
|
|
2649
|
+
export declare function isRawLiteral(value: any): value is {
|
|
2650
|
+
$literal: string;
|
|
2651
|
+
};
|
|
2652
|
+
/**
|
|
2653
|
+
* Check if a value is a CAST expression
|
|
2654
|
+
*/
|
|
2655
|
+
export declare function isCastExpression(value: any): value is CastExpression;
|
|
2656
|
+
/**
|
|
2657
|
+
* Check if a value is an EXTRACT expression
|
|
2658
|
+
*/
|
|
2659
|
+
export declare function isExtractExpression(value: any): value is ExtractExpression;
|
|
2660
|
+
/**
|
|
2661
|
+
* Check if a value is a CONVERT expression
|
|
2662
|
+
*/
|
|
2663
|
+
export declare function isConvExpression(value: any): value is ConvExpression;
|
|
2664
|
+
/**
|
|
2665
|
+
* Create a CAST expression for type casting
|
|
2666
|
+
* SQL: CAST(value AS type)
|
|
2667
|
+
*
|
|
2668
|
+
* @example
|
|
2669
|
+
* ```typescript
|
|
2670
|
+
* // CAST('2023-01-01' AS DATE)
|
|
2671
|
+
* User.findAll({
|
|
2672
|
+
* attributes: [[cast('2023-01-01', 'DATE'), 'dateOnly']]
|
|
2673
|
+
* })
|
|
2674
|
+
*
|
|
2675
|
+
* // CAST(column AS INTEGER)
|
|
2676
|
+
* User.findAll({
|
|
2677
|
+
* attributes: [[cast(col('amount'), 'INTEGER'), 'amountInt']]
|
|
2678
|
+
* })
|
|
2679
|
+
*
|
|
2680
|
+
* // CAST with different types
|
|
2681
|
+
* cast(col('price'), 'DECIMAL(10,2)')
|
|
2682
|
+
* cast(col('text'), 'CHAR(100)')
|
|
2683
|
+
* cast(col('json_data'), 'JSON')
|
|
2684
|
+
* ```
|
|
2685
|
+
*/
|
|
2686
|
+
export declare function cast(value: any, type: string): CastExpression;
|
|
2687
|
+
/**
|
|
2688
|
+
* Type coercion helpers for common SQL types
|
|
2689
|
+
* Provides convenience methods for casting values to specific types
|
|
2690
|
+
*
|
|
2691
|
+
* @example
|
|
2692
|
+
* ```typescript
|
|
2693
|
+
* import { Cast, col } from 'orm';
|
|
2694
|
+
*
|
|
2695
|
+
* // Cast.string - CAST(value AS VARCHAR)
|
|
2696
|
+
* User.findAll({
|
|
2697
|
+
* attributes: [[Cast.string(col('age')), 'ageStr']]
|
|
2698
|
+
* })
|
|
2699
|
+
*
|
|
2700
|
+
* // Cast.integer - CAST(value AS INTEGER)
|
|
2701
|
+
* User.findAll({
|
|
2702
|
+
* attributes: [[Cast.integer(col('price')), 'priceInt']]
|
|
2703
|
+
* })
|
|
2704
|
+
*
|
|
2705
|
+
* // Cast.date - CAST(value AS DATE)
|
|
2706
|
+
* User.findAll({
|
|
2707
|
+
* attributes: [[Cast.date(col('timestamp')), 'dateOnly']]
|
|
2708
|
+
* })
|
|
2709
|
+
*
|
|
2710
|
+
* // Cast.boolean - CAST(value AS BOOLEAN)
|
|
2711
|
+
* User.findAll({
|
|
2712
|
+
* attributes: [[Cast.boolean(col('flag')), 'flagBool']]
|
|
2713
|
+
* })
|
|
2714
|
+
*
|
|
2715
|
+
* // Cast.float - CAST(value AS FLOAT)
|
|
2716
|
+
* User.findAll({
|
|
2717
|
+
* attributes: [[Cast.float(col('amount')), 'amountFloat']]
|
|
2718
|
+
* })
|
|
2719
|
+
*
|
|
2720
|
+
* // Cast.decimal - CAST(value AS DECIMAL)
|
|
2721
|
+
* User.findAll({
|
|
2722
|
+
* attributes: [[Cast.decimal(col('price'), 10, 2), 'priceDecimal']]
|
|
2723
|
+
* })
|
|
2724
|
+
*
|
|
2725
|
+
* // Cast.json - CAST(value AS JSON)
|
|
2726
|
+
* User.findAll({
|
|
2727
|
+
* attributes: [[Cast.json(col('data')), 'dataJson']]
|
|
2728
|
+
* })
|
|
2729
|
+
* ```
|
|
2730
|
+
*/
|
|
2731
|
+
export declare const Cast: {
|
|
2732
|
+
/**
|
|
2733
|
+
* Cast to VARCHAR/string type
|
|
2734
|
+
*/
|
|
2735
|
+
readonly string: (value: any) => CastExpression;
|
|
2736
|
+
/**
|
|
2737
|
+
* Cast to CHAR type
|
|
2738
|
+
*/
|
|
2739
|
+
readonly char: (value: any, length?: number) => CastExpression;
|
|
2740
|
+
/**
|
|
2741
|
+
* Cast to TEXT type
|
|
2742
|
+
*/
|
|
2743
|
+
readonly text: (value: any) => CastExpression;
|
|
2744
|
+
/**
|
|
2745
|
+
* Cast to INTEGER type
|
|
2746
|
+
*/
|
|
2747
|
+
readonly integer: (value: any) => CastExpression;
|
|
2748
|
+
/**
|
|
2749
|
+
* Cast to BIGINT type
|
|
2750
|
+
*/
|
|
2751
|
+
readonly bigint: (value: any) => CastExpression;
|
|
2752
|
+
/**
|
|
2753
|
+
* Cast to FLOAT type
|
|
2754
|
+
*/
|
|
2755
|
+
readonly float: (value: any) => CastExpression;
|
|
2756
|
+
/**
|
|
2757
|
+
* Cast to DOUBLE type
|
|
2758
|
+
*/
|
|
2759
|
+
readonly double: (value: any) => CastExpression;
|
|
2760
|
+
/**
|
|
2761
|
+
* Cast to DECIMAL type
|
|
2762
|
+
*/
|
|
2763
|
+
readonly decimal: (value: any, precision?: number, scale?: number) => CastExpression;
|
|
2764
|
+
/**
|
|
2765
|
+
* Cast to BOOLEAN type
|
|
2766
|
+
*/
|
|
2767
|
+
readonly boolean: (value: any) => CastExpression;
|
|
2768
|
+
/**
|
|
2769
|
+
* Cast to DATE type
|
|
2770
|
+
*/
|
|
2771
|
+
readonly date: (value: any) => CastExpression;
|
|
2772
|
+
/**
|
|
2773
|
+
* Cast to DATETIME type
|
|
2774
|
+
*/
|
|
2775
|
+
readonly datetime: (value: any) => CastExpression;
|
|
2776
|
+
/**
|
|
2777
|
+
* Cast to TIME type
|
|
2778
|
+
*/
|
|
2779
|
+
readonly time: (value: any) => CastExpression;
|
|
2780
|
+
/**
|
|
2781
|
+
* Cast to TIMESTAMP type
|
|
2782
|
+
*/
|
|
2783
|
+
readonly timestamp: (value: any) => CastExpression;
|
|
2784
|
+
/**
|
|
2785
|
+
* Cast to JSON type
|
|
2786
|
+
*/
|
|
2787
|
+
readonly json: (value: any) => CastExpression;
|
|
2788
|
+
/**
|
|
2789
|
+
* Cast to BLOB type
|
|
2790
|
+
*/
|
|
2791
|
+
readonly blob: (value: any) => CastExpression;
|
|
2792
|
+
/**
|
|
2793
|
+
* Cast to UUID type
|
|
2794
|
+
*/
|
|
2795
|
+
readonly uuid: (value: any) => CastExpression;
|
|
2796
|
+
/**
|
|
2797
|
+
* Cast to specific type
|
|
2798
|
+
*/
|
|
2799
|
+
readonly valueOf: (value: any, type: string) => CastExpression;
|
|
2800
|
+
};
|
|
2801
|
+
/**
|
|
2802
|
+
* Type for Cast object
|
|
2803
|
+
*/
|
|
2804
|
+
export type CastType = typeof Cast;
|
|
2805
|
+
/**
|
|
2806
|
+
* Create an EXTRACT expression for extracting date parts
|
|
2807
|
+
* SQL: EXTRACT(part FROM field)
|
|
2808
|
+
*
|
|
2809
|
+
* @example
|
|
2810
|
+
* ```typescript
|
|
2811
|
+
* // EXTRACT(YEAR FROM createdAt)
|
|
2812
|
+
* User.findAll({
|
|
2813
|
+
* attributes: [[extract('createdAt', 'year'), 'year']]
|
|
2814
|
+
* })
|
|
2815
|
+
*
|
|
2816
|
+
* // EXTRACT(MONTH FROM order_date)
|
|
2817
|
+
* User.findAll({
|
|
2818
|
+
* attributes: [[extract(col('order_date'), 'month'), 'month']]
|
|
2819
|
+
* })
|
|
2820
|
+
*
|
|
2821
|
+
* // Use in WHERE clause
|
|
2822
|
+
* User.findAll({
|
|
2823
|
+
* where: {
|
|
2824
|
+
* [extract('createdAt', 'year')]: 2024
|
|
2825
|
+
* }
|
|
2826
|
+
* })
|
|
2827
|
+
*
|
|
2828
|
+
* // Available parts: year, month, day, hour, minute, second
|
|
2829
|
+
* ```
|
|
2830
|
+
*/
|
|
2831
|
+
export declare function extract(field: any, part: ExtractPart): ExtractExpression;
|
|
2832
|
+
/**
|
|
2833
|
+
* Create a CONVERT expression for type conversion
|
|
2834
|
+
* SQL: CONVERT(value, type) for MySQL, or CAST for other dialects
|
|
2835
|
+
*
|
|
2836
|
+
* @example
|
|
2837
|
+
* ```typescript
|
|
2838
|
+
* // CONVERT(value, to_type)
|
|
2839
|
+
* User.findAll({
|
|
2840
|
+
* attributes: [[conv(col('value'), null, 'CHAR'), 'strValue']]
|
|
2841
|
+
* })
|
|
2842
|
+
*
|
|
2843
|
+
* // CONVERT with charset (MySQL)
|
|
2844
|
+
* conv(col('name'), null, 'CHAR(255) CHARACTER SET utf8mb4')
|
|
2845
|
+
*
|
|
2846
|
+
* // Base type conversion
|
|
2847
|
+
* conv(col('text'), 'CHAR', 'INTEGER')
|
|
2848
|
+
* ```
|
|
2849
|
+
*/
|
|
2850
|
+
export declare function conv(value: any, from: string | null | undefined, to: string): ConvExpression;
|
|
2851
|
+
/**
|
|
2852
|
+
* Create a SUM aggregate function expression
|
|
2853
|
+
* SQL: SUM(column)
|
|
2854
|
+
*
|
|
2855
|
+
* @example
|
|
2856
|
+
* ```typescript
|
|
2857
|
+
* // Sum all scores
|
|
2858
|
+
* User.findAll({
|
|
2859
|
+
* attributes: [[SUM(col('score')), 'totalScore']]
|
|
2860
|
+
* })
|
|
2861
|
+
*
|
|
2862
|
+
* // Sum with condition
|
|
2863
|
+
* User.findAll({
|
|
2864
|
+
* attributes: [[SUM(col('amount')), 'totalAmount']],
|
|
2865
|
+
* where: { status: 'completed' }
|
|
2866
|
+
* })
|
|
2867
|
+
* ```
|
|
2868
|
+
*/
|
|
2869
|
+
export declare function SUM(column: any): FnExpression;
|
|
2870
|
+
/**
|
|
2871
|
+
* Create an AVG aggregate function expression
|
|
2872
|
+
* SQL: AVG(column)
|
|
2873
|
+
*
|
|
2874
|
+
* @example
|
|
2875
|
+
* ```typescript
|
|
2876
|
+
* // Average score
|
|
2877
|
+
* User.findAll({
|
|
2878
|
+
* attributes: [[AVG(col('score')), 'averageScore']]
|
|
2879
|
+
* })
|
|
2880
|
+
*
|
|
2881
|
+
* // Average with group by
|
|
2882
|
+
* User.findAll({
|
|
2883
|
+
* attributes: ['department', [AVG(col('salary')), 'avgSalary']],
|
|
2884
|
+
* group: ['department']
|
|
2885
|
+
* })
|
|
2886
|
+
* ```
|
|
2887
|
+
*/
|
|
2888
|
+
export declare function AVG(column: any): FnExpression;
|
|
2889
|
+
/**
|
|
2890
|
+
* Create a COUNT aggregate function expression
|
|
2891
|
+
* SQL: COUNT(column)
|
|
2892
|
+
*
|
|
2893
|
+
* @example
|
|
2894
|
+
* ```typescript
|
|
2895
|
+
* // Count all records
|
|
2896
|
+
* User.findAll({
|
|
2897
|
+
* attributes: [[COUNT(col('id')), 'totalCount']]
|
|
2898
|
+
* })
|
|
2899
|
+
*
|
|
2900
|
+
* // Count distinct values
|
|
2901
|
+
* User.findAll({
|
|
2902
|
+
* attributes: [[COUNT(col('email')), 'uniqueEmails']]
|
|
2903
|
+
* })
|
|
2904
|
+
*
|
|
2905
|
+
* // Count with DISTINCT
|
|
2906
|
+
* User.findAll({
|
|
2907
|
+
* attributes: [[COUNT(fn('DISTINCT', col('role'))), 'uniqueRoles']]
|
|
2908
|
+
* })
|
|
2909
|
+
* ```
|
|
2910
|
+
*/
|
|
2911
|
+
export declare function COUNT(column?: any): FnExpression;
|
|
2912
|
+
/**
|
|
2913
|
+
* Create a MAX aggregate function expression
|
|
2914
|
+
* SQL: MAX(column)
|
|
2915
|
+
*
|
|
2916
|
+
* @example
|
|
2917
|
+
* ```typescript
|
|
2918
|
+
* // Maximum score
|
|
2919
|
+
* User.findAll({
|
|
2920
|
+
* attributes: [[MAX(col('score')), 'highestScore']]
|
|
2921
|
+
* })
|
|
2922
|
+
*
|
|
2923
|
+
* // Latest date
|
|
2924
|
+
* User.findAll({
|
|
2925
|
+
* attributes: [[MAX(col('createdAt')), 'latestDate']]
|
|
2926
|
+
* })
|
|
2927
|
+
* ```
|
|
2928
|
+
*/
|
|
2929
|
+
export declare function MAX(column: any): FnExpression;
|
|
2930
|
+
/**
|
|
2931
|
+
* Create a MIN aggregate function expression
|
|
2932
|
+
* SQL: MIN(column)
|
|
2933
|
+
*
|
|
2934
|
+
* @example
|
|
2935
|
+
* ```typescript
|
|
2936
|
+
* // Minimum score
|
|
2937
|
+
* User.findAll({
|
|
2938
|
+
* attributes: [[MIN(col('score')), 'lowestScore']]
|
|
2939
|
+
* })
|
|
2940
|
+
*
|
|
2941
|
+
* // Earliest date
|
|
2942
|
+
* User.findAll({
|
|
2943
|
+
* attributes: [[MIN(col('createdAt')), 'earliestDate']]
|
|
2944
|
+
* })
|
|
2945
|
+
* ```
|
|
2946
|
+
*/
|
|
2947
|
+
export declare function MIN(column: any): FnExpression;
|