ts-prorm-orm 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -0
- package/README.md +194 -72
- package/dist/audit/history-query.d.ts +35 -0
- package/dist/audit/index.d.ts +16 -0
- package/dist/audit/logger.d.ts +126 -0
- package/dist/cache/cache-manager.d.ts +341 -0
- package/dist/cache/index.d.ts +8 -0
- package/dist/cache/redis-cluster-cache.d.ts +164 -0
- package/dist/cache/redis-cluster-cache.js +19 -36
- package/dist/cli/cloud.d.ts +55 -0
- package/dist/cli/cloud.js +318 -0
- package/dist/cli/commands/auth.d.ts +2 -0
- package/dist/cli/commands/auth.js +345 -0
- package/dist/cli/commands/billing.d.ts +2 -0
- package/dist/cli/commands/billing.js +135 -0
- package/dist/cli/commands/code.d.ts +2 -0
- package/dist/cli/commands/code.js +168 -0
- package/dist/cli/commands/config.d.ts +2 -0
- package/dist/cli/commands/config.js +154 -0
- package/dist/cli/commands/db.d.ts +2 -0
- package/dist/cli/commands/db.js +189 -0
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.js +22 -0
- package/dist/cli/commands/keys.d.ts +2 -0
- package/dist/cli/commands/keys.js +100 -0
- package/dist/cli/commands/misc.d.ts +2 -0
- package/dist/cli/commands/misc.js +282 -0
- package/dist/cli/commands/pull.d.ts +2 -0
- package/dist/cli/commands/pull.js +306 -0
- package/dist/cli/commands/runners.d.ts +2 -0
- package/dist/cli/commands/runners.js +218 -0
- package/dist/cli/commands/scaffold.d.ts +2 -0
- package/dist/cli/commands/scaffold.js +383 -0
- package/dist/cli/commands/secrets.d.ts +2 -0
- package/dist/cli/commands/secrets.js +162 -0
- package/dist/cli/commands/store.d.ts +2 -0
- package/dist/cli/commands/store.js +274 -0
- package/dist/cli/commands/system.d.ts +10 -0
- package/dist/cli/commands/system.js +169 -0
- package/dist/cli/commands/teams.d.ts +2 -0
- package/dist/cli/commands/teams.js +189 -0
- package/dist/cli/commands/user.d.ts +2 -0
- package/dist/cli/commands/user.js +171 -0
- package/dist/cli/framework.d.ts +103 -0
- package/dist/cli/framework.js +436 -0
- package/dist/cli/io.d.ts +26 -0
- package/dist/cli/io.js +181 -0
- package/dist/cli/keychain.d.ts +10 -0
- package/dist/cli/keychain.js +101 -0
- package/dist/cli/prompt.d.ts +20 -0
- package/dist/cli/prompt.js +111 -0
- package/dist/cli.d.ts +214 -0
- package/dist/cli.js +72 -5
- package/dist/compliance/audit-trail.d.ts +66 -0
- package/dist/compliance/backup-verification.d.ts +279 -0
- package/dist/compliance/breach-detector.d.ts +197 -0
- package/dist/compliance/consent-record.d.ts +107 -0
- package/dist/compliance/consent-versioning.d.ts +169 -0
- package/dist/compliance/cross-border-log.d.ts +254 -0
- package/dist/compliance/data-classifier.d.ts +127 -0
- package/dist/compliance/data-lineage.d.ts +268 -0
- package/dist/compliance/data-masker.d.ts +110 -0
- package/dist/compliance/data-portability.d.ts +98 -0
- package/dist/compliance/data-retention.d.ts +108 -0
- package/dist/compliance/dsar-workflow.d.ts +175 -0
- package/dist/compliance/field-encryption.d.ts +84 -0
- package/dist/compliance/immutable-record.d.ts +84 -0
- package/dist/compliance/index.d.ts +93 -0
- package/dist/compliance/privacy-impact-assessment.d.ts +196 -0
- package/dist/compliance/pseudonymization.d.ts +96 -0
- package/dist/compliance/query-firewall.d.ts +661 -0
- package/dist/compliance/rate-limiter.d.ts +203 -0
- package/dist/compliance/right-to-erasure.d.ts +96 -0
- package/dist/compliance/row-level-security.d.ts +152 -0
- package/dist/compliance/security-decorator.d.ts +388 -0
- package/dist/compliance/security-monitor.d.ts +170 -0
- package/dist/compliance/sensitive-data-discovery.d.ts +151 -0
- package/dist/compliance/session-isolation.d.ts +286 -0
- package/dist/compliance/tls-enforcer.d.ts +51 -0
- package/dist/compliance/worm-storage.d.ts +225 -0
- package/dist/connection-manager.d.ts +130 -0
- package/dist/connection-pool.d.ts +311 -0
- package/dist/decorators/audit.d.ts +49 -0
- package/dist/decorators/check.d.ts +218 -0
- package/dist/decorators/collate.d.ts +346 -0
- package/dist/decorators/comment.d.ts +51 -0
- package/dist/decorators/database-settings.d.ts +193 -0
- package/dist/decorators/default.d.ts +148 -0
- package/dist/decorators/encryption.d.ts +175 -0
- package/dist/decorators/engine.d.ts +97 -0
- package/dist/decorators/fk-constraints.d.ts +387 -0
- package/dist/decorators/foreign-table.d.ts +57 -0
- package/dist/decorators/generated.d.ts +232 -0
- package/dist/decorators/hstore.d.ts +96 -0
- package/dist/decorators/index.d.ts +57 -0
- package/dist/decorators/index.js +14 -30
- package/dist/decorators/json-column.d.ts +47 -0
- package/dist/decorators/jsonb.d.ts +83 -0
- package/dist/decorators/orm-decorators.d.ts +274 -0
- package/dist/decorators/permissions.d.ts +192 -0
- package/dist/decorators/procedure.d.ts +168 -0
- package/dist/decorators/procedure.js +31 -7
- package/dist/decorators/query-options.d.ts +527 -0
- package/dist/decorators/range.d.ts +122 -0
- package/dist/decorators/set-column.d.ts +43 -0
- package/dist/decorators/spatial.d.ts +60 -0
- package/dist/decorators/storage.d.ts +561 -0
- package/dist/decorators/timezone.d.ts +319 -0
- package/dist/decorators/trigger.d.ts +50 -0
- package/dist/decorators/uuid.d.ts +102 -0
- package/dist/decorators/view.d.ts +213 -0
- package/dist/diagrams/chen-diagram.d.ts +70 -0
- package/dist/diagrams/chen-diagram.js +33 -31
- package/dist/diagrams/class-diagram.d.ts +78 -0
- package/dist/diagrams/class-diagram.js +23 -27
- package/dist/diagrams/dependency-diagram.d.ts +82 -0
- package/dist/diagrams/dependency-diagram.js +18 -9
- package/dist/diagrams/er-diagram.d.ts +82 -0
- package/dist/diagrams/er-diagram.js +174 -231
- package/dist/diagrams/flow-diagram.d.ts +70 -0
- package/dist/diagrams/flow-diagram.js +23 -18
- package/dist/diagrams/gantt-diagram.d.ts +67 -0
- package/dist/diagrams/gantt-diagram.js +20 -18
- package/dist/diagrams/index-diagram.d.ts +61 -0
- package/dist/diagrams/index-diagram.js +36 -31
- package/dist/diagrams/index.d.ts +155 -0
- package/dist/diagrams/index.js +7 -1
- package/dist/diagrams/migration-diagram.d.ts +67 -0
- package/dist/diagrams/migration-diagram.js +45 -57
- package/dist/diagrams/model-diagram.d.ts +85 -0
- package/dist/diagrams/model-diagram.js +225 -287
- package/dist/diagrams/package-diagram.d.ts +69 -0
- package/dist/diagrams/package-diagram.js +30 -32
- package/dist/diagrams/palette.d.ts +138 -0
- package/dist/diagrams/palette.js +134 -25
- package/dist/diagrams/relational-diagram.d.ts +82 -0
- package/dist/diagrams/relational-diagram.js +51 -59
- package/dist/diagrams/schemadoc-diagram.d.ts +57 -0
- package/dist/diagrams/schemadoc-diagram.js +36 -28
- package/dist/diagrams/sequence-diagram.d.ts +61 -0
- package/dist/diagrams/sequence-diagram.js +20 -11
- package/dist/diagrams/state-diagram.d.ts +85 -0
- package/dist/diagrams/state-diagram.js +21 -17
- package/dist/diagrams/svg-dom.d.ts +62 -0
- package/dist/diagrams/svg-dom.js +11 -0
- package/dist/diagrams/tree-diagram.d.ts +47 -0
- package/dist/diagrams/tree-diagram.js +19 -10
- package/dist/dialects/clickhouse/index.d.ts +660 -0
- package/dist/dialects/clickhouse/index.js +107 -2
- package/dist/dialects/cockroachdb/index.d.ts +1708 -0
- package/dist/dialects/cockroachdb/index.js +139 -10
- package/dist/dialects/cratedb/index.d.ts +262 -0
- package/dist/dialects/cratedb/index.js +148 -0
- package/dist/dialects/databricks/index.d.ts +397 -0
- package/dist/dialects/databricks/index.js +233 -11
- package/dist/dialects/db2/index.d.ts +729 -0
- package/dist/dialects/db2/index.js +152 -2
- package/dist/dialects/dialect.d.ts +1653 -0
- package/dist/dialects/duckdb/index.d.ts +440 -0
- package/dist/dialects/duckdb/index.js +21 -37
- package/dist/dialects/exasol/index.d.ts +197 -0
- package/dist/dialects/exasol/index.js +14 -0
- package/dist/dialects/firebird/index.d.ts +286 -0
- package/dist/dialects/firebird/index.js +135 -0
- package/dist/dialects/greenplum/index.d.ts +336 -0
- package/dist/dialects/greenplum/index.js +168 -0
- package/dist/dialects/hana/index.d.ts +512 -0
- package/dist/dialects/hana/index.js +17 -35
- package/dist/dialects/mariadb/index.d.ts +1241 -0
- package/dist/dialects/mariadb/index.js +181 -43
- package/dist/dialects/mssql/index.d.ts +729 -0
- package/dist/dialects/mssql/index.js +76 -7
- package/dist/dialects/mysql/index.d.ts +1233 -0
- package/dist/dialects/mysql/index.js +87 -19
- package/dist/dialects/oracle/index.d.ts +1222 -0
- package/dist/dialects/oracle/index.js +210 -9
- package/dist/dialects/postgres/index.d.ts +1598 -0
- package/dist/dialects/postgres/index.js +34 -13
- package/dist/dialects/query-stream-helper.d.ts +58 -0
- package/dist/dialects/questdb/index.d.ts +430 -0
- package/dist/dialects/questdb/index.js +292 -0
- package/dist/dialects/redshift/index.d.ts +933 -0
- package/dist/dialects/redshift/index.js +17 -5
- package/dist/dialects/singlestore/index.d.ts +233 -0
- package/dist/dialects/singlestore/index.js +53 -0
- package/dist/dialects/snowflake/index.d.ts +727 -0
- package/dist/dialects/snowflake/index.js +154 -5
- package/dist/dialects/spanner/index.d.ts +660 -0
- package/dist/dialects/spanner/index.js +43 -21
- package/dist/dialects/sqlite/index.d.ts +1133 -0
- package/dist/dialects/sqlite/index.js +168 -30
- package/dist/dialects/tidb/index.d.ts +226 -0
- package/dist/dialects/tidb/index.js +10 -0
- package/dist/dialects/timescaledb/index.d.ts +286 -0
- package/dist/dialects/timescaledb/index.js +179 -0
- package/dist/dialects/trino/index.d.ts +230 -0
- package/dist/dialects/trino/index.js +85 -10
- package/dist/dialects/turso/index.d.ts +98 -0
- package/dist/dialects/turso/index.js +10 -0
- package/dist/dialects/vertica/index.d.ts +321 -0
- package/dist/dialects/vertica/index.js +161 -0
- package/dist/dialects/yugabytedb/index.d.ts +276 -0
- package/dist/dialects/yugabytedb/index.js +121 -0
- package/dist/errors/index.d.ts +378 -0
- package/dist/errors/index.js +29 -1
- package/dist/errors/utils.d.ts +53 -0
- package/dist/errors.d.ts +5 -0
- package/dist/extensions/catalog/cloud-warehouse-features.d.ts +27 -0
- package/dist/extensions/catalog/mssql-features.d.ts +20 -0
- package/dist/extensions/catalog/mysql-mariadb-plugins.d.ts +18 -0
- package/dist/extensions/catalog/oracle-db2-features.d.ts +17 -0
- package/dist/extensions/catalog/postgres-extensions.d.ts +15 -0
- package/dist/extensions/index.d.ts +34 -0
- package/dist/extensions/types.d.ts +43 -0
- package/dist/external-fields/adapters.d.ts +50 -0
- package/dist/external-fields/adapters.js +227 -0
- package/dist/external-fields/decorator.d.ts +77 -0
- package/dist/external-fields/decorator.js +80 -0
- package/dist/external-fields/index.d.ts +10 -0
- package/dist/external-fields/index.js +19 -0
- package/dist/external-fields/runtime.d.ts +39 -0
- package/dist/external-fields/runtime.js +221 -0
- package/dist/foreign-data.d.ts +168 -0
- package/dist/graph/base-graph-dialect.d.ts +250 -0
- package/dist/graph/base-graph-dialect.js +539 -0
- package/dist/graph/dgraph/index.d.ts +65 -0
- package/dist/graph/dgraph/index.js +559 -0
- package/dist/graph/gremlin/index.d.ts +59 -0
- package/dist/graph/gremlin/index.js +378 -0
- package/dist/graph/index.d.ts +60 -0
- package/dist/graph/index.js +67 -0
- package/dist/graph/neo4j/index.d.ts +50 -0
- package/dist/graph/neo4j/index.js +462 -0
- package/dist/graph/types.d.ts +213 -0
- package/dist/graph/types.js +234 -0
- package/dist/hooks/hooks-manager.d.ts +189 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/index.d.ts +713 -0
- package/dist/index.js +36 -4
- package/dist/logging.d.ts +183 -0
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/migration.d.ts +143 -0
- package/dist/migrations/migrator.d.ts +199 -0
- package/dist/migrations/prormmigration.d.ts +131 -0
- package/dist/migrations/query-interface.d.ts +335 -0
- package/dist/migrations/seeder.d.ts +167 -0
- package/dist/models/associations.d.ts +131 -0
- package/dist/models/associations.js +7 -2
- package/dist/models/constraints.d.ts +175 -0
- package/dist/models/data-types.d.ts +1656 -0
- package/dist/models/decorators.d.ts +328 -0
- package/dist/models/decorators.js +61 -82
- package/dist/models/eager-load.d.ts +86 -0
- package/dist/models/eager-load.js +369 -0
- package/dist/models/index.d.ts +13 -0
- package/dist/models/indexes.d.ts +325 -0
- package/dist/models/methods.d.ts +419 -0
- package/dist/models/model-manager.d.ts +76 -0
- package/dist/models/model.d.ts +820 -0
- package/dist/models/model.js +15 -101
- package/dist/models/operators.d.ts +29 -0
- package/dist/models/scopes.d.ts +71 -0
- package/dist/models/typescript-types.d.ts +177 -0
- package/dist/nosql/aerospike/index.d.ts +126 -0
- package/dist/nosql/allegrograph/index.d.ts +86 -0
- package/dist/nosql/arangodb/index.d.ts +285 -0
- package/dist/nosql/arangodb/index.js +274 -2
- package/dist/nosql/arangodb/where.d.ts +38 -0
- package/dist/nosql/arangodb/where.js +94 -0
- package/dist/nosql/azure-blob/index.d.ts +104 -0
- package/dist/nosql/beanstalkd/index.d.ts +88 -0
- package/dist/nosql/beequeue/index.d.ts +99 -0
- package/dist/nosql/bigchaindb/index.d.ts +113 -0
- package/dist/nosql/bigtable/index.d.ts +144 -0
- package/dist/nosql/blazegraph/index.d.ts +88 -0
- package/dist/nosql/bullmq/index.d.ts +83 -0
- package/dist/nosql/cassandra/index.d.ts +119 -0
- package/dist/nosql/chroma/index.d.ts +151 -0
- package/dist/nosql/cloudflare-kv/index.d.ts +120 -0
- package/dist/nosql/coherence/index.d.ts +91 -0
- package/dist/nosql/cosmosdb/index.d.ts +78 -0
- package/dist/nosql/couchbase/index.d.ts +103 -0
- package/dist/nosql/dax/index.d.ts +118 -0
- package/dist/nosql/deno-kv/index.d.ts +109 -0
- package/dist/nosql/dgraph/index.d.ts +80 -0
- package/dist/nosql/doris/index.d.ts +88 -0
- package/dist/nosql/druid/index.d.ts +95 -0
- package/dist/nosql/dynamodb/index.d.ts +643 -0
- package/dist/nosql/dynamodb/index.js +423 -0
- package/dist/nosql/elasticsearch/index.d.ts +239 -0
- package/dist/nosql/etcd/index.d.ts +243 -0
- package/dist/nosql/eventhubs/index.d.ts +89 -0
- package/dist/nosql/eventstore/index.d.ts +102 -0
- package/dist/nosql/faunadb/index.d.ts +141 -0
- package/dist/nosql/faunadb/index.js +329 -0
- package/dist/nosql/firestore/index.d.ts +67 -0
- package/dist/nosql/fluree/index.d.ts +88 -0
- package/dist/nosql/fuseki/index.d.ts +94 -0
- package/dist/nosql/gcs/index.d.ts +62 -0
- package/dist/nosql/gearman/index.d.ts +77 -0
- package/dist/nosql/geode/index.d.ts +93 -0
- package/dist/nosql/graphdb/index.d.ts +86 -0
- package/dist/nosql/graylog/index.d.ts +118 -0
- package/dist/nosql/gridgain/index.d.ts +78 -0
- package/dist/nosql/hazelcast/index.d.ts +73 -0
- package/dist/nosql/hbase/index.d.ts +123 -0
- package/dist/nosql/ignite/index.d.ts +80 -0
- package/dist/nosql/immudb/index.d.ts +131 -0
- package/dist/nosql/index.d.ts +215 -0
- package/dist/nosql/infinispan/index.d.ts +95 -0
- package/dist/nosql/influxdb/flux-compiler.d.ts +23 -0
- package/dist/nosql/influxdb/flux-compiler.js +170 -0
- package/dist/nosql/influxdb/index.d.ts +300 -0
- package/dist/nosql/influxdb/index.js +0 -0
- package/dist/nosql/kafka/index.d.ts +113 -0
- package/dist/nosql/keyspaces/index.d.ts +122 -0
- package/dist/nosql/kinesis/index.d.ts +121 -0
- package/dist/nosql/leveldb/index.d.ts +112 -0
- package/dist/nosql/leveldb/index.js +103 -1
- package/dist/nosql/lmdb/index.d.ts +76 -0
- package/dist/nosql/loki/index.d.ts +126 -0
- package/dist/nosql/marklogic/index.d.ts +76 -0
- package/dist/nosql/materialize/index.d.ts +91 -0
- package/dist/nosql/meilisearch/index.d.ts +76 -0
- package/dist/nosql/memcached/index.d.ts +138 -0
- package/dist/nosql/milvus/index.d.ts +167 -0
- package/dist/nosql/minio/index.d.ts +122 -0
- package/dist/nosql/momento/index.d.ts +99 -0
- package/dist/nosql/mongodb/index.d.ts +265 -0
- package/dist/nosql/mongodb/index.js +139 -0
- package/dist/nosql/mongodb/where.d.ts +8 -0
- package/dist/nosql/mongodb/where.js +181 -0
- package/dist/nosql/nats/index.d.ts +139 -0
- package/dist/nosql/nedb/index.d.ts +79 -0
- package/dist/nosql/neo4j/index.d.ts +217 -0
- package/dist/nosql/neo4j/index.js +26 -14
- package/dist/nosql/neptune/index.d.ts +234 -0
- package/dist/nosql/neptune/index.js +23 -9
- package/dist/nosql/nsq/index.d.ts +93 -0
- package/dist/nosql/opensearch/index.d.ts +97 -0
- package/dist/nosql/orientdb/index.d.ts +72 -0
- package/dist/nosql/papertrail/index.d.ts +120 -0
- package/dist/nosql/pinecone/index.d.ts +148 -0
- package/dist/nosql/pinot/index.d.ts +90 -0
- package/dist/nosql/pouchdb/index.d.ts +95 -0
- package/dist/nosql/prometheus/index.d.ts +112 -0
- package/dist/nosql/provendb/index.d.ts +143 -0
- package/dist/nosql/provendb/index.js +262 -0
- package/dist/nosql/pubsub/index.d.ts +83 -0
- package/dist/nosql/pulsar/index.d.ts +105 -0
- package/dist/nosql/qdrant/index.d.ts +231 -0
- package/dist/nosql/qldb/index.d.ts +182 -0
- package/dist/nosql/qldb/index.js +302 -1
- package/dist/nosql/r2/index.d.ts +160 -0
- package/dist/nosql/rabbitmq/index.d.ts +131 -0
- package/dist/nosql/ravendb/index.d.ts +138 -0
- package/dist/nosql/ravendb/index.js +323 -9
- package/dist/nosql/ravendb/where.d.ts +38 -0
- package/dist/nosql/ravendb/where.js +94 -0
- package/dist/nosql/redis/index.d.ts +267 -0
- package/dist/nosql/redis/index.js +19 -5
- package/dist/nosql/redpanda/index.d.ts +117 -0
- package/dist/nosql/resque/index.d.ts +91 -0
- package/dist/nosql/rethinkdb/index.d.ts +194 -0
- package/dist/nosql/rethinkdb/index.js +290 -0
- package/dist/nosql/rethinkdb/where.d.ts +38 -0
- package/dist/nosql/rethinkdb/where.js +94 -0
- package/dist/nosql/rocksdb/document-layer.d.ts +162 -0
- package/dist/nosql/rocksdb/document-layer.js +338 -0
- package/dist/nosql/rocksdb/index.d.ts +112 -0
- package/dist/nosql/rocksdb/index.js +103 -1
- package/dist/nosql/rocksdb/where-match.d.ts +21 -0
- package/dist/nosql/rocksdb/where-match.js +238 -0
- package/dist/nosql/rockset/index.d.ts +84 -0
- package/dist/nosql/s3/index.d.ts +170 -0
- package/dist/nosql/scylladb/index.d.ts +117 -0
- package/dist/nosql/signoz/index.d.ts +116 -0
- package/dist/nosql/sns/index.d.ts +99 -0
- package/dist/nosql/solr/index.d.ts +129 -0
- package/dist/nosql/splunk/index.d.ts +125 -0
- package/dist/nosql/sqs/index.d.ts +116 -0
- package/dist/nosql/stardog/index.d.ts +86 -0
- package/dist/nosql/starrocks/index.d.ts +89 -0
- package/dist/nosql/store.d.ts +23 -0
- package/dist/nosql/sumologic/index.d.ts +119 -0
- package/dist/nosql/surrealdb/index.d.ts +156 -0
- package/dist/nosql/surrealdb/index.js +174 -1
- package/dist/nosql/surrealdb/query-compiler.d.ts +26 -0
- package/dist/nosql/surrealdb/query-compiler.js +193 -0
- package/dist/nosql/terminusdb/index.d.ts +95 -0
- package/dist/nosql/tigergraph/index.d.ts +314 -0
- package/dist/nosql/typesense/index.d.ts +82 -0
- package/dist/nosql/unqlite/index.d.ts +68 -0
- package/dist/nosql/upstash/index.d.ts +80 -0
- package/dist/nosql/vercel-kv/index.d.ts +82 -0
- package/dist/nosql/victoriametrics/index.d.ts +129 -0
- package/dist/nosql/virtuoso/index.d.ts +87 -0
- package/dist/nosql/weaviate/index.d.ts +196 -0
- package/dist/operators/index.d.ts +7 -0
- package/dist/operators.d.ts +2947 -0
- package/dist/operators.js +46 -1
- package/dist/prisma-migrate/index.d.ts +28 -0
- package/dist/prisma-migrate/migration-generator.d.ts +21 -0
- package/dist/prisma-migrate/model-generator.d.ts +12 -0
- package/dist/prisma-migrate/relations.d.ts +28 -0
- package/dist/prisma-migrate/schema-parser.d.ts +42 -0
- package/dist/prisma-migrate/type-mapper.d.ts +20 -0
- package/dist/prorm.d.ts +2093 -0
- package/dist/prorm.js +721 -302
- package/dist/query-builders/cte-builder.d.ts +104 -0
- package/dist/query-builders/functions/aggregate.d.ts +199 -0
- package/dist/query-builders/functions/conditional.d.ts +195 -0
- package/dist/query-builders/functions/datetime.d.ts +202 -0
- package/dist/query-builders/functions/fulltext.d.ts +220 -0
- package/dist/query-builders/functions/index.d.ts +17 -0
- package/dist/query-builders/functions/json.d.ts +157 -0
- package/dist/query-builders/functions/math.d.ts +215 -0
- package/dist/query-builders/functions/string.d.ts +233 -0
- package/dist/query-builders/functions/window.d.ts +209 -0
- package/dist/query-builders/include-builder.d.ts +85 -0
- package/dist/query-builders/index-expression-builder.d.ts +153 -0
- package/dist/query-builders/index.d.ts +121 -0
- package/dist/query-builders/index.js +10 -0
- package/dist/query-builders/insert-builder.d.ts +62 -0
- package/dist/query-builders/model-helpers.d.ts +28 -0
- package/dist/query-builders/order-limit-builder.d.ts +84 -0
- package/dist/query-builders/sql-compiler.d.ts +562 -0
- package/dist/query-builders/subquery-builder.d.ts +133 -0
- package/dist/query-builders/update-builder.d.ts +71 -0
- package/dist/query-builders/view-builder.d.ts +189 -0
- package/dist/query-builders/where-builder.d.ts +124 -0
- package/dist/query-interface.d.ts +407 -0
- package/dist/query-interface.js +84 -0
- package/dist/query-optimizers/batch-optimizer.d.ts +175 -0
- package/dist/query-optimizers/explain-plans.d.ts +187 -0
- package/dist/query-optimizers/index.d.ts +27 -0
- package/dist/query-optimizers/prepared-statement-cache.d.ts +252 -0
- package/dist/query-optimizers/query-hints.d.ts +201 -0
- package/dist/query-optimizers/query-optimizer.d.ts +162 -0
- package/dist/query-optimizers/slow-query-logger.d.ts +186 -0
- package/dist/replica-manager.d.ts +235 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/migration-generator.d.ts +74 -0
- package/dist/schema/schema-differ.d.ts +114 -0
- package/dist/schema/types.d.ts +246 -0
- package/dist/schema-objects.d.ts +78 -0
- package/dist/schema-objects.js +203 -0
- package/dist/sql-constants.d.ts +240 -0
- package/dist/sqlite-advanced.d.ts +572 -0
- package/dist/streams/index.d.ts +5 -0
- package/dist/streams/transforms.d.ts +120 -0
- package/dist/transaction.d.ts +221 -0
- package/dist/types/index.d.ts +3123 -0
- package/dist/user-management.d.ts +141 -0
- package/dist/utils/date.d.ts +149 -0
- package/dist/utils/index.d.ts +359 -0
- package/dist/utils/string.d.ts +88 -0
- package/dist/validators/index.d.ts +7 -0
- package/dist/validators/validator.d.ts +306 -0
- package/package.json +20 -5
|
@@ -0,0 +1,1598 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL dialect implementation for the TypeScript ORM
|
|
3
|
+
*/
|
|
4
|
+
import type { Pool, PoolClient } from 'pg';
|
|
5
|
+
import { Dialect, DialectOptions, ColumnDefinition, TableOptions, DropTableOptions, TableDescription, IndexOptions, InsertOptions, UpdateOptions as DUpdateOptions, DeleteOptions, SelectOptions, CTEOption, UpsertQueryOptions, CreateExtensionOptions, DropExtensionOptions, ExtensionInfo, CreateEnumTypeOptions, DropTypeOptions, CreateDomainOptions, DropDomainOptions, FdwForeignServerOptions, FdwAlterForeignServerOptions, FdwUserMappingOptions, FdwForeignTableOptions, FdwImportForeignSchemaOptions, ViewOptions, DropViewOptions, DropSchemaOptions, MaterializedViewOptions, RefreshOptions, DropMaterializedViewOptions } from '../dialect';
|
|
6
|
+
import { Transaction, TransactionOptions, QueryResult, QueryOptions, StreamOptions, DataType, WhereOptions, Order, PartitionDefinition, CreatePartitionOptions, AttachPartitionOptions, DetachPartitionOptions, StoredProcedureOptions, DropStoredProcedureOptions, ExecuteStoredProcedureOptions, TriggerOptions, DropTriggerOptions, SequenceOptions, DropSequenceOptions, PolicyOptions, DropPolicyOptions } from '../../types';
|
|
7
|
+
/**
|
|
8
|
+
* A single `WHEN MATCHED [AND condition] THEN ...` clause for `buildMergeQuery`.
|
|
9
|
+
*/
|
|
10
|
+
export interface MergeWhenMatchedClause {
|
|
11
|
+
/** Additional `AND` condition appended to `WHEN MATCHED` */
|
|
12
|
+
condition?: string;
|
|
13
|
+
/** The action to take: UPDATE the matched row, DELETE it, or DO NOTHING */
|
|
14
|
+
then: 'UPDATE' | 'DELETE' | 'DO NOTHING';
|
|
15
|
+
/** Column/value pairs for the `UPDATE SET` clause (required when `then === 'UPDATE'`) */
|
|
16
|
+
set?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A single `WHEN NOT MATCHED [AND condition] THEN ...` clause for `buildMergeQuery`.
|
|
20
|
+
*/
|
|
21
|
+
export interface MergeWhenNotMatchedClause {
|
|
22
|
+
/** Additional `AND` condition appended to `WHEN NOT MATCHED` */
|
|
23
|
+
condition?: string;
|
|
24
|
+
/** The action to take: INSERT a new row, or DO NOTHING */
|
|
25
|
+
then: 'INSERT' | 'DO NOTHING';
|
|
26
|
+
/** Columns to insert into (required when `then === 'INSERT'`) */
|
|
27
|
+
columns?: string[];
|
|
28
|
+
/** Values corresponding to `columns` (required when `then === 'INSERT'`) */
|
|
29
|
+
values?: unknown[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options shared by `PostgresDialect.copyFrom` and `PostgresDialect.copyTo`, mirroring
|
|
33
|
+
* PostgreSQL's `COPY ... WITH (...)` options: https://www.postgresql.org/docs/current/sql-copy.html
|
|
34
|
+
*/
|
|
35
|
+
export interface CopyOptions {
|
|
36
|
+
/** `FORMAT` — defaults to `'CSV'` when a `delimiter`/`header`/`quote`/`escape` option is given, otherwise `'TEXT'`. */
|
|
37
|
+
format?: 'CSV' | 'TEXT' | 'BINARY';
|
|
38
|
+
/** `DELIMITER 'char'` — single character that separates columns. Defaults to `,` for CSV, tab for TEXT. */
|
|
39
|
+
delimiter?: string;
|
|
40
|
+
/**
|
|
41
|
+
* `HEADER` — for `copyFrom`, whether the source's first line is a header row to skip.
|
|
42
|
+
* For `copyTo`, whether to emit a header row. Only valid for CSV format (and TEXT since PG 17).
|
|
43
|
+
*/
|
|
44
|
+
header?: boolean;
|
|
45
|
+
/** `NULL 'string'` — string that represents a null value. Defaults to `\N` for TEXT, unquoted empty string for CSV. */
|
|
46
|
+
null?: string;
|
|
47
|
+
/** `QUOTE 'char'` — quoting character for CSV format. Defaults to double-quote. */
|
|
48
|
+
quote?: string;
|
|
49
|
+
/** `ESCAPE 'char'` — escape character for CSV format. Defaults to the QUOTE value. */
|
|
50
|
+
escape?: string;
|
|
51
|
+
/** `ENCODING 'name'` — character set encoding of the copy data. */
|
|
52
|
+
encoding?: string;
|
|
53
|
+
/** `FREEZE` — (COPY FROM only) performs the copy as though it were run in a newly created table/index. */
|
|
54
|
+
freeze?: boolean;
|
|
55
|
+
/** Explicit column list, e.g. `['id', 'name']`. When omitted, all columns are used (in table order). */
|
|
56
|
+
columns?: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* PostgreSQL dialect class that implements the Dialect interface
|
|
60
|
+
*/
|
|
61
|
+
export declare class PostgresDialect implements Dialect {
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly library: string;
|
|
64
|
+
private pool;
|
|
65
|
+
private _isConnected;
|
|
66
|
+
private config;
|
|
67
|
+
private transactionDepth;
|
|
68
|
+
/**
|
|
69
|
+
* Dedicated (non-pooled) client used for LISTEN/NOTIFY. Postgres notifications are only
|
|
70
|
+
* delivered to the specific backend connection that issued LISTEN, so a pooled connection
|
|
71
|
+
* cannot be used reliably (the pool may hand that connection back out or close it). We lazily
|
|
72
|
+
* open a single long-lived `pg.Client` the first time `listen()` is called and keep it open
|
|
73
|
+
* for the lifetime of the dialect (or until `disconnect()`/`unlisten()` closes it out).
|
|
74
|
+
*/
|
|
75
|
+
private notifyClient;
|
|
76
|
+
private notifyChannels;
|
|
77
|
+
private notifyConnectPromise;
|
|
78
|
+
constructor(config: PostgresDialectOptions);
|
|
79
|
+
/**
|
|
80
|
+
* Connect to the PostgreSQL database
|
|
81
|
+
*/
|
|
82
|
+
connect(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Disconnect from the PostgreSQL database
|
|
85
|
+
*/
|
|
86
|
+
disconnect(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Get the current connection pool
|
|
89
|
+
*/
|
|
90
|
+
getConnection(): Pool | null;
|
|
91
|
+
/**
|
|
92
|
+
* Check if connected
|
|
93
|
+
*/
|
|
94
|
+
isConnected(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Lazily creates (or returns the existing) dedicated client used to receive Postgres
|
|
97
|
+
* notifications. This client is separate from the pool because `LISTEN` registers interest
|
|
98
|
+
* on the specific backend connection - handing that connection back to a pool would mean
|
|
99
|
+
* notifications get delivered to whichever caller happens to check the connection out next.
|
|
100
|
+
*/
|
|
101
|
+
private getNotifyClient;
|
|
102
|
+
/**
|
|
103
|
+
* Subscribe to a PostgreSQL notification channel (`LISTEN channel`). The provided callback
|
|
104
|
+
* is invoked with the notification payload every time `NOTIFY channel, 'payload'` (or
|
|
105
|
+
* `pg_notify('channel', 'payload')`) is executed by any backend, including this one.
|
|
106
|
+
*
|
|
107
|
+
* Returns an unsubscribe function that removes just this callback; use `unlisten()` to
|
|
108
|
+
* drop the entire channel subscription (issues `UNLISTEN` on the dedicated connection).
|
|
109
|
+
*/
|
|
110
|
+
listen(channel: string, callback: (payload: string) => void): Promise<() => Promise<void>>;
|
|
111
|
+
/**
|
|
112
|
+
* Unsubscribe from a PostgreSQL notification channel entirely (`UNLISTEN channel`), removing
|
|
113
|
+
* all callbacks registered for it via `listen()`.
|
|
114
|
+
*/
|
|
115
|
+
unlisten(channel: string): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Send a PostgreSQL notification (`NOTIFY channel, 'payload'` / `pg_notify(channel, payload)`).
|
|
118
|
+
* Uses `pg_notify()` with bound parameters (rather than string-interpolated `NOTIFY`) so the
|
|
119
|
+
* payload can safely contain arbitrary text without manual escaping.
|
|
120
|
+
*/
|
|
121
|
+
notify(channel: string, payload?: string): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Execute a raw SQL query with retry support
|
|
124
|
+
*/
|
|
125
|
+
query(sql: string, options?: QueryOptions): Promise<QueryResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Execute a query and stream results using PostgreSQL cursor
|
|
128
|
+
* Uses server-side cursors for efficient memory usage with large datasets
|
|
129
|
+
* @param sql - The SQL query string
|
|
130
|
+
* @param options - Stream options
|
|
131
|
+
* @returns Readable stream for streaming results
|
|
132
|
+
*/
|
|
133
|
+
queryStream(sql: string, options?: StreamOptions): import('stream').Readable;
|
|
134
|
+
/**
|
|
135
|
+
* Execute a function with retry logic for query execution
|
|
136
|
+
*/
|
|
137
|
+
private executeWithRetry;
|
|
138
|
+
/**
|
|
139
|
+
* Escape a value for use in a query
|
|
140
|
+
*/
|
|
141
|
+
escape(value: unknown): string;
|
|
142
|
+
/**
|
|
143
|
+
* Escape a string for SQL
|
|
144
|
+
*/
|
|
145
|
+
private escapeString;
|
|
146
|
+
/**
|
|
147
|
+
* Format a date for PostgreSQL
|
|
148
|
+
*/
|
|
149
|
+
private formatDate;
|
|
150
|
+
/**
|
|
151
|
+
* Escape an identifier (table name, column name, etc.)
|
|
152
|
+
* PostgreSQL uses double quotes for identifiers
|
|
153
|
+
*/
|
|
154
|
+
escapeId(identifier: unknown): string;
|
|
155
|
+
/**
|
|
156
|
+
* Quote an identifier (column name, table name)
|
|
157
|
+
* PostgreSQL uses double quotes for identifiers
|
|
158
|
+
*/
|
|
159
|
+
quoteIdentifier(identifier: string): string;
|
|
160
|
+
/**
|
|
161
|
+
* Quote a table name
|
|
162
|
+
* Includes schema prefix if provided
|
|
163
|
+
*/
|
|
164
|
+
quoteTable(tableName: string, schema?: string): string;
|
|
165
|
+
/**
|
|
166
|
+
* Get the database version
|
|
167
|
+
*/
|
|
168
|
+
getDatabaseVersion(): Promise<string>;
|
|
169
|
+
/**
|
|
170
|
+
* Create a database schema
|
|
171
|
+
* @param schema - The schema name to create
|
|
172
|
+
*/
|
|
173
|
+
createSchema(schema: string): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Drop a database schema
|
|
176
|
+
* @param schema - The schema name to drop
|
|
177
|
+
* @param options - Drop options (e.g., cascade)
|
|
178
|
+
*/
|
|
179
|
+
dropSchema(schema: string, options?: DropSchemaOptions): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Show all schemas in the database
|
|
182
|
+
*/
|
|
183
|
+
showAllSchemas(): Promise<string[]>;
|
|
184
|
+
/**
|
|
185
|
+
* List all schemas in the database
|
|
186
|
+
*/
|
|
187
|
+
listSchemas(): Promise<string[]>;
|
|
188
|
+
/**
|
|
189
|
+
* Replace placeholders in SQL with actual values
|
|
190
|
+
* @param sql - SQL string with placeholders
|
|
191
|
+
* @param replacements - Object or array of replacement values
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* Format a single JS value as a SQL literal for inlining into a query
|
|
195
|
+
* (used by replaceReplacements() below, which inlines values into the SQL text
|
|
196
|
+
* rather than sending them as real driver parameters).
|
|
197
|
+
*
|
|
198
|
+
* Without this, plain objects/arrays fell through to the `String(value)` fallback:
|
|
199
|
+
* `String({a: 1})` produces the bare text `[object Object]` and `String(['a', 'b'])`
|
|
200
|
+
* produces the unquoted, comma-joined text `a,b` - both invalid or wrong SQL, and the
|
|
201
|
+
* array case is silently misinterpreted as bare column references (`a`, `b`) rather
|
|
202
|
+
* than a PostgreSQL array literal.
|
|
203
|
+
*/
|
|
204
|
+
private formatReplacementValue;
|
|
205
|
+
replaceReplacements(sql: string, replacements?: Record<string, unknown> | unknown[]): string;
|
|
206
|
+
/**
|
|
207
|
+
* Create a new table
|
|
208
|
+
*/
|
|
209
|
+
createTable(tableName: string, columns: Record<string, ColumnDefinition>, options?: TableOptions): Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
* Build constraint SQL for table creation
|
|
212
|
+
*/
|
|
213
|
+
private buildConstraintSql;
|
|
214
|
+
/**
|
|
215
|
+
* Generate column definition SQL for PostgreSQL
|
|
216
|
+
*/
|
|
217
|
+
private getColumnDefinitionSql;
|
|
218
|
+
/**
|
|
219
|
+
* Get default value SQL
|
|
220
|
+
*/
|
|
221
|
+
private getDefaultValue;
|
|
222
|
+
/**
|
|
223
|
+
* Drop a table
|
|
224
|
+
*/
|
|
225
|
+
dropTable(tableName: string, options?: DropTableOptions): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* List all materialized view names in the database.
|
|
228
|
+
*/
|
|
229
|
+
listMaterializedViews(schema?: string): Promise<string[]>;
|
|
230
|
+
/**
|
|
231
|
+
* Create a partitioned table (PostgreSQL 10+)
|
|
232
|
+
*
|
|
233
|
+
* @param tableName - Name of the table to create
|
|
234
|
+
* @param columns - Column definitions
|
|
235
|
+
* @param options - Table options including partition configuration
|
|
236
|
+
*/
|
|
237
|
+
createPartitionedTable(tableName: string, columns: Record<string, ColumnDefinition>, options?: TableOptions & {
|
|
238
|
+
partitionBy: {
|
|
239
|
+
type: 'range' | 'list' | 'hash';
|
|
240
|
+
column: string | string[];
|
|
241
|
+
};
|
|
242
|
+
partitions?: PartitionDefinition[];
|
|
243
|
+
}): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* Create a partition for an existing partitioned table (PostgreSQL 10+)
|
|
246
|
+
*
|
|
247
|
+
* @param options - Partition creation options
|
|
248
|
+
*/
|
|
249
|
+
createPartition(options: CreatePartitionOptions): Promise<void>;
|
|
250
|
+
/**
|
|
251
|
+
* Attach a partition to a partitioned table (PostgreSQL 11+)
|
|
252
|
+
*
|
|
253
|
+
* @param options - Partition attachment options
|
|
254
|
+
*/
|
|
255
|
+
attachPartition(options: AttachPartitionOptions): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* Detach a partition from a partitioned table (PostgreSQL 11+)
|
|
258
|
+
*
|
|
259
|
+
* @param options - Partition detachment options
|
|
260
|
+
*/
|
|
261
|
+
detachPartition(options: DetachPartitionOptions): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Drop a partition (PostgreSQL 10+)
|
|
264
|
+
*
|
|
265
|
+
* @param partitionName - Name of the partition to drop
|
|
266
|
+
* @param options - Drop options
|
|
267
|
+
*/
|
|
268
|
+
dropPartition(partitionName: string, options?: {
|
|
269
|
+
ifExists?: boolean;
|
|
270
|
+
cascade?: boolean;
|
|
271
|
+
}): Promise<void>;
|
|
272
|
+
/**
|
|
273
|
+
* Add a partition to an existing partitioned table (PostgreSQL 10+)
|
|
274
|
+
* @param tableName - Name of the partitioned table
|
|
275
|
+
* @param partitionName - Name for the new partition
|
|
276
|
+
* @param partitionSpec - Partition specification
|
|
277
|
+
*/
|
|
278
|
+
addPartition(tableName: string, partitionName: string, partitionSpec: {
|
|
279
|
+
values?: string;
|
|
280
|
+
forValues?: string;
|
|
281
|
+
}): Promise<void>;
|
|
282
|
+
/**
|
|
283
|
+
* Create a database view
|
|
284
|
+
*/
|
|
285
|
+
createView(viewName: string, query: string, options?: ViewOptions): Promise<void>;
|
|
286
|
+
/**
|
|
287
|
+
* Drop a database view
|
|
288
|
+
*/
|
|
289
|
+
dropView(viewName: string, options?: DropViewOptions): Promise<void>;
|
|
290
|
+
/**
|
|
291
|
+
* Show all views in the database
|
|
292
|
+
*/
|
|
293
|
+
showViews(): Promise<string[]>;
|
|
294
|
+
/**
|
|
295
|
+
* Create a materialized view
|
|
296
|
+
* @param options - Materialized view options
|
|
297
|
+
*/
|
|
298
|
+
createMaterializedView(options: MaterializedViewOptions): Promise<void>;
|
|
299
|
+
/**
|
|
300
|
+
* Refresh a materialized view
|
|
301
|
+
* @param viewName - Name of the materialized view to refresh
|
|
302
|
+
* @param options - Refresh options
|
|
303
|
+
*/
|
|
304
|
+
refreshMaterializedView(viewName: string, options?: RefreshOptions): Promise<void>;
|
|
305
|
+
/**
|
|
306
|
+
* Drop a materialized view
|
|
307
|
+
* @param viewName - Name of the materialized view to drop
|
|
308
|
+
* @param options - Drop options
|
|
309
|
+
*/
|
|
310
|
+
dropMaterializedView(viewName: string, options?: DropMaterializedViewOptions): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Check if a materialized view exists
|
|
313
|
+
* @param viewName - Name of the materialized view
|
|
314
|
+
* @returns True if the materialized view exists
|
|
315
|
+
*/
|
|
316
|
+
hasMaterializedView(viewName: string): Promise<boolean>;
|
|
317
|
+
/**
|
|
318
|
+
* Show all materialized views in the database
|
|
319
|
+
*/
|
|
320
|
+
showMaterializedViews(): Promise<string[]>;
|
|
321
|
+
/**
|
|
322
|
+
* Create a stored procedure (PostgreSQL 11+)
|
|
323
|
+
*/
|
|
324
|
+
createStoredProcedure(options: StoredProcedureOptions): Promise<void>;
|
|
325
|
+
/**
|
|
326
|
+
* Create a foreign data wrapper (PostgreSQL)
|
|
327
|
+
* @param fdwName - Foreign data wrapper name
|
|
328
|
+
* @param options - Options including handler function
|
|
329
|
+
*/
|
|
330
|
+
createForeignDataWrapper(fdwName: string, options?: {
|
|
331
|
+
handler?: string;
|
|
332
|
+
}): Promise<void>;
|
|
333
|
+
dropForeignDataWrapper(fdwName: string, options?: {
|
|
334
|
+
ifExists?: boolean;
|
|
335
|
+
}): Promise<void>;
|
|
336
|
+
createForeignServer(serverName: string, fdwName: string, options?: {
|
|
337
|
+
options?: Record<string, string>;
|
|
338
|
+
ifNotExists?: boolean;
|
|
339
|
+
}): Promise<void>;
|
|
340
|
+
dropForeignServer(serverName: string, options?: {
|
|
341
|
+
ifExists?: boolean;
|
|
342
|
+
cascade?: boolean;
|
|
343
|
+
}): Promise<void>;
|
|
344
|
+
createForeignTable(tableName: string, columns: Record<string, {
|
|
345
|
+
type: string;
|
|
346
|
+
}>, options?: {
|
|
347
|
+
serverName?: string;
|
|
348
|
+
ifNotExists?: boolean;
|
|
349
|
+
}): Promise<void>;
|
|
350
|
+
changeOwner(newOwner: string, tableName: string): Promise<void>;
|
|
351
|
+
addConstraint(tableName: string, options: {
|
|
352
|
+
type: 'UNIQUE' | 'CHECK' | 'PRIMARY KEY' | 'FOREIGN KEY';
|
|
353
|
+
fields: string[];
|
|
354
|
+
name?: string;
|
|
355
|
+
references?: {
|
|
356
|
+
table: string;
|
|
357
|
+
fields: string[];
|
|
358
|
+
};
|
|
359
|
+
check?: string;
|
|
360
|
+
}): Promise<void>;
|
|
361
|
+
removeConstraint(tableName: string, constraintName: string): Promise<void>;
|
|
362
|
+
/**
|
|
363
|
+
* Alias for createPolicy() using the generic cross-dialect security-policy shape.
|
|
364
|
+
* PostgreSQL's row-level security is implemented via createPolicy()/dropPolicy(); this
|
|
365
|
+
* method exists only to satisfy the abstract Dialect contract and simply forwards to it.
|
|
366
|
+
*/
|
|
367
|
+
createSecurityPolicy(policyName: string, tableName: string, options?: {
|
|
368
|
+
predicate?: string;
|
|
369
|
+
}): Promise<void>;
|
|
370
|
+
/**
|
|
371
|
+
* Alias for dropPolicy() - see createSecurityPolicy().
|
|
372
|
+
*/
|
|
373
|
+
dropSecurityPolicy(policyName: string, tableName: string): Promise<void>;
|
|
374
|
+
/**
|
|
375
|
+
* Drop a stored procedure
|
|
376
|
+
*/
|
|
377
|
+
dropStoredProcedure(procedureName: string, options?: DropStoredProcedureOptions): Promise<void>;
|
|
378
|
+
/**
|
|
379
|
+
* Drop a stored procedure (alias for dropStoredProcedure)
|
|
380
|
+
*/
|
|
381
|
+
dropProcedure(procedureName: string, options?: DropStoredProcedureOptions): Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Create a stored procedure (alias for createStoredProcedure)
|
|
384
|
+
*/
|
|
385
|
+
createProcedure(options: StoredProcedureOptions): Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Execute a stored procedure
|
|
388
|
+
*/
|
|
389
|
+
executeStoredProcedure(options: ExecuteStoredProcedureOptions): Promise<QueryResult>;
|
|
390
|
+
/**
|
|
391
|
+
* Check if a stored procedure exists
|
|
392
|
+
*/
|
|
393
|
+
hasStoredProcedure(procedureName: string, schema?: string): Promise<boolean>;
|
|
394
|
+
/**
|
|
395
|
+
* Create a trigger
|
|
396
|
+
*/
|
|
397
|
+
createTrigger(options: TriggerOptions): Promise<void>;
|
|
398
|
+
/**
|
|
399
|
+
* Drop a trigger
|
|
400
|
+
*/
|
|
401
|
+
dropTrigger(triggerName: string, tableName: string, options?: DropTriggerOptions): Promise<void>;
|
|
402
|
+
/**
|
|
403
|
+
* Check if a trigger exists
|
|
404
|
+
*/
|
|
405
|
+
hasTrigger(triggerName: string, tableName: string): Promise<boolean>;
|
|
406
|
+
/**
|
|
407
|
+
* Create a sequence
|
|
408
|
+
*/
|
|
409
|
+
createSequence(options: SequenceOptions): Promise<void>;
|
|
410
|
+
/**
|
|
411
|
+
* Drop a sequence
|
|
412
|
+
*/
|
|
413
|
+
dropSequence(sequenceName: string, options?: DropSequenceOptions): Promise<void>;
|
|
414
|
+
/**
|
|
415
|
+
* Get next value from a sequence
|
|
416
|
+
*/
|
|
417
|
+
nextSequenceValue(sequenceName: string): Promise<number>;
|
|
418
|
+
/**
|
|
419
|
+
* Get the current (session-local) value of a sequence.
|
|
420
|
+
* Requires nextval() to have been called at least once in the current session.
|
|
421
|
+
*/
|
|
422
|
+
currSequenceValue(sequenceName: string): Promise<number>;
|
|
423
|
+
/**
|
|
424
|
+
* Check if a sequence exists
|
|
425
|
+
*/
|
|
426
|
+
hasSequence(sequenceName: string): Promise<boolean>;
|
|
427
|
+
/**
|
|
428
|
+
* List all sequences in the database (PostgreSQL)
|
|
429
|
+
* @returns Array of sequence names
|
|
430
|
+
*/
|
|
431
|
+
listSequences(): Promise<string[]>;
|
|
432
|
+
/**
|
|
433
|
+
* Create a policy (PostgreSQL RLS)
|
|
434
|
+
*/
|
|
435
|
+
createPolicy(options: PolicyOptions): Promise<void>;
|
|
436
|
+
/**
|
|
437
|
+
* Drop a policy (PostgreSQL RLS)
|
|
438
|
+
*/
|
|
439
|
+
dropPolicy(policyName: string, tableName: string, options?: DropPolicyOptions): Promise<void>;
|
|
440
|
+
/**
|
|
441
|
+
* Enable row-level security on a table (PostgreSQL)
|
|
442
|
+
*/
|
|
443
|
+
enableRLS(tableName: string, schema?: string): Promise<void>;
|
|
444
|
+
/**
|
|
445
|
+
* Enable row-level security on a table (alias for enableRLS)
|
|
446
|
+
*/
|
|
447
|
+
enableRowLevelSecurity(tableName: string, schema?: string): Promise<void>;
|
|
448
|
+
/**
|
|
449
|
+
* Disable row-level security on a table (PostgreSQL)
|
|
450
|
+
*/
|
|
451
|
+
disableRLS(tableName: string, schema?: string): Promise<void>;
|
|
452
|
+
/**
|
|
453
|
+
* Disable row-level security on a table (alias for disableRLS, matching enableRowLevelSecurity)
|
|
454
|
+
*/
|
|
455
|
+
disableRowLevelSecurity(tableName: string, schema?: string): Promise<void>;
|
|
456
|
+
/**
|
|
457
|
+
* Check if a policy exists (PostgreSQL RLS)
|
|
458
|
+
*/
|
|
459
|
+
hasPolicy(policyName: string, tableName: string): Promise<boolean>;
|
|
460
|
+
/**
|
|
461
|
+
* Add comment to a table
|
|
462
|
+
*/
|
|
463
|
+
commentTable(tableName: string, comment: string): Promise<void>;
|
|
464
|
+
/**
|
|
465
|
+
* Add comment to a column
|
|
466
|
+
*/
|
|
467
|
+
commentColumn(tableName: string, columnName: string, comment: string): Promise<void>;
|
|
468
|
+
/**
|
|
469
|
+
* Create a partial index (index with WHERE clause)
|
|
470
|
+
*/
|
|
471
|
+
createPartialIndex(tableName: string, indexName: string, fields: string[], where: string, options?: IndexOptions): Promise<void>;
|
|
472
|
+
/**
|
|
473
|
+
* Create an expression index
|
|
474
|
+
*/
|
|
475
|
+
createExpressionIndex(tableName: string, indexName: string, expression: string, options?: IndexOptions): Promise<void>;
|
|
476
|
+
/**
|
|
477
|
+
* Create a fulltext index (PostgreSQL)
|
|
478
|
+
* Uses GIN index for fulltext search
|
|
479
|
+
* @param tableName - Table name
|
|
480
|
+
* @param indexName - Index name
|
|
481
|
+
* @param fields - Fields to index
|
|
482
|
+
* @param options - Fulltext index options
|
|
483
|
+
*/
|
|
484
|
+
createFulltextIndex(tableName: string, indexName: string, fields: string[], options?: {
|
|
485
|
+
parser?: string;
|
|
486
|
+
comment?: string;
|
|
487
|
+
}): Promise<void>;
|
|
488
|
+
/**
|
|
489
|
+
* Create a spatial index (PostgreSQL)
|
|
490
|
+
* Uses GIST index for spatial data
|
|
491
|
+
* @param tableName - Table name
|
|
492
|
+
* @param indexName - Index name
|
|
493
|
+
* @param fields - Fields to index
|
|
494
|
+
* @param options - Spatial index options
|
|
495
|
+
*/
|
|
496
|
+
createSpatialIndex(tableName: string, indexName: string, fields: string[], options?: {
|
|
497
|
+
storage?: string;
|
|
498
|
+
srid?: number;
|
|
499
|
+
}): Promise<void>;
|
|
500
|
+
/**
|
|
501
|
+
* Bulk insert records into a table
|
|
502
|
+
*/
|
|
503
|
+
bulkInsert(tableName: string, records: Record<string, any>[], _options?: any): Promise<QueryResult>;
|
|
504
|
+
/**
|
|
505
|
+
* Add a foreign key to a table
|
|
506
|
+
*/
|
|
507
|
+
addForeignKey(tableName: string, columnName: string, referencedTableName: string, referencedColumnName: string, options?: {
|
|
508
|
+
name?: string;
|
|
509
|
+
onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION';
|
|
510
|
+
onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION';
|
|
511
|
+
}): Promise<void>;
|
|
512
|
+
/**
|
|
513
|
+
* Rename a column
|
|
514
|
+
*/
|
|
515
|
+
renameColumn(tableName: string, oldColumnName: string, newColumnName: string): Promise<void>;
|
|
516
|
+
/**
|
|
517
|
+
* Create an identity column
|
|
518
|
+
*/
|
|
519
|
+
createIdentityColumn(tableName: string, columnName: string, options?: {
|
|
520
|
+
startWith?: number;
|
|
521
|
+
incrementBy?: number;
|
|
522
|
+
minvalue?: number;
|
|
523
|
+
maxvalue?: number;
|
|
524
|
+
cycle?: boolean;
|
|
525
|
+
}): Promise<void>;
|
|
526
|
+
/**
|
|
527
|
+
* Create a computed column (generated column)
|
|
528
|
+
*/
|
|
529
|
+
createComputedColumn(tableName: string, columnName: string, expression: string, options?: {
|
|
530
|
+
persisted?: boolean;
|
|
531
|
+
type?: string;
|
|
532
|
+
}): Promise<void>;
|
|
533
|
+
/**
|
|
534
|
+
* Create a PostgreSQL extension
|
|
535
|
+
* @param extensionName - Name of the extension to create
|
|
536
|
+
* @param options - Extension options
|
|
537
|
+
*/
|
|
538
|
+
createExtension(extensionName: string, options?: CreateExtensionOptions): Promise<void>;
|
|
539
|
+
/**
|
|
540
|
+
* Drop a PostgreSQL extension
|
|
541
|
+
* @param extensionName - Name of the extension to drop
|
|
542
|
+
* @param options - Drop options
|
|
543
|
+
*/
|
|
544
|
+
dropExtension(extensionName: string, options?: DropExtensionOptions): Promise<void>;
|
|
545
|
+
/**
|
|
546
|
+
* Get all installed PostgreSQL extensions
|
|
547
|
+
* @returns Array of extension information
|
|
548
|
+
*/
|
|
549
|
+
getExtensions(): Promise<ExtensionInfo[]>;
|
|
550
|
+
/**
|
|
551
|
+
* Check if a PostgreSQL extension is installed
|
|
552
|
+
* @param extensionName - Name of the extension
|
|
553
|
+
* @returns True if the extension is installed
|
|
554
|
+
*/
|
|
555
|
+
hasExtension(extensionName: string): Promise<boolean>;
|
|
556
|
+
/**
|
|
557
|
+
* Create a PostgreSQL enum type: `CREATE TYPE name AS ENUM ('a', 'b', ...)`.
|
|
558
|
+
*
|
|
559
|
+
* Postgres has no native `CREATE TYPE IF NOT EXISTS`; pass `options.ifNotExists`
|
|
560
|
+
* to have this method check `pg_type` first and skip creation if the type
|
|
561
|
+
* already exists.
|
|
562
|
+
*
|
|
563
|
+
* @param name - Name of the type to create
|
|
564
|
+
* @param values - Enum label values, in the order they should sort
|
|
565
|
+
* @param options - Schema and if-not-exists options
|
|
566
|
+
*/
|
|
567
|
+
createEnumType(name: string, values: string[], options?: CreateEnumTypeOptions): Promise<void>;
|
|
568
|
+
/**
|
|
569
|
+
* Drop a PostgreSQL type (e.g. one created with `createEnumType`).
|
|
570
|
+
* `DROP TYPE [IF EXISTS] name [CASCADE | RESTRICT]`.
|
|
571
|
+
*
|
|
572
|
+
* @param name - Name of the type to drop
|
|
573
|
+
* @param options - If-exists, cascade, and schema options
|
|
574
|
+
*/
|
|
575
|
+
dropType(name: string, options?: DropTypeOptions): Promise<void>;
|
|
576
|
+
/**
|
|
577
|
+
* Create a PostgreSQL domain: `CREATE DOMAIN name AS base_type [DEFAULT ...]
|
|
578
|
+
* [COLLATE ...] [NOT NULL] [CONSTRAINT name CHECK (...)] ...`.
|
|
579
|
+
*
|
|
580
|
+
* @param name - Name of the domain to create
|
|
581
|
+
* @param baseType - Underlying data type the domain is based on, e.g. `'INTEGER'` or `'VARCHAR(255)'`
|
|
582
|
+
* @param options - Default value, collation, nullability, and CHECK constraints
|
|
583
|
+
*/
|
|
584
|
+
createDomain(name: string, baseType: string, options?: CreateDomainOptions): Promise<void>;
|
|
585
|
+
/**
|
|
586
|
+
* Drop a PostgreSQL domain. `DROP DOMAIN [IF EXISTS] name [CASCADE | RESTRICT]`.
|
|
587
|
+
*
|
|
588
|
+
* @param name - Name of the domain to drop
|
|
589
|
+
* @param options - If-exists, cascade, and schema options
|
|
590
|
+
*/
|
|
591
|
+
dropDomain(name: string, options?: DropDomainOptions): Promise<void>;
|
|
592
|
+
/**
|
|
593
|
+
* Lazily loads `pg-copy-streams`, throwing a clear error (with install instructions) if it
|
|
594
|
+
* isn't available. Kept as a single choke point so both `copyFrom` and `copyTo` fail the
|
|
595
|
+
* same way.
|
|
596
|
+
*/
|
|
597
|
+
private loadCopyStreams;
|
|
598
|
+
/**
|
|
599
|
+
* Build the `WITH (...)` options clause shared by `COPY ... FROM STDIN` and `COPY ... TO STDOUT`.
|
|
600
|
+
*/
|
|
601
|
+
private buildCopyOptionsSql;
|
|
602
|
+
/**
|
|
603
|
+
* Bulk-load data into a table using PostgreSQL's `COPY ... FROM STDIN`.
|
|
604
|
+
*
|
|
605
|
+
* Requires the optional `pg-copy-streams` package (see the comment above this section);
|
|
606
|
+
* throws a descriptive error if it isn't installed.
|
|
607
|
+
*
|
|
608
|
+
* @param tableName - Table to load data into
|
|
609
|
+
* @param source - Where the copy data comes from:
|
|
610
|
+
* - A Node `Readable` stream (piped directly into the COPY stream)
|
|
611
|
+
* - A `string` of pre-formatted CSV/text COPY data
|
|
612
|
+
* - An array of rows, each either an array of column values or a plain object keyed by
|
|
613
|
+
* column name - these are serialized to CSV using `options`
|
|
614
|
+
* @param options - `FORMAT`/`DELIMITER`/`HEADER`/`NULL`/`QUOTE`/`ESCAPE`/column-list options
|
|
615
|
+
* @returns The number of rows copied
|
|
616
|
+
*/
|
|
617
|
+
copyFrom(tableName: string, source: NodeJS.ReadableStream | string | Array<unknown[] | Record<string, unknown>>, options?: CopyOptions): Promise<{
|
|
618
|
+
rowCount: number;
|
|
619
|
+
}>;
|
|
620
|
+
/**
|
|
621
|
+
* Serialize a single value for inclusion in hand-built CSV/TEXT COPY data (used by
|
|
622
|
+
* `copyFrom` when given an array of rows rather than a pre-formatted stream/string).
|
|
623
|
+
*/
|
|
624
|
+
private formatCopyValue;
|
|
625
|
+
/**
|
|
626
|
+
* Bulk-export data from a table (or query) using PostgreSQL's `COPY ... TO STDOUT`.
|
|
627
|
+
*
|
|
628
|
+
* Requires the optional `pg-copy-streams` package (see the comment above this section);
|
|
629
|
+
* throws a descriptive error if it isn't installed.
|
|
630
|
+
*
|
|
631
|
+
* @param tableName - Table (or, if `options.query` is set, ignored in favor of that query) to export from
|
|
632
|
+
* @param destination - A Node `Writable` to pipe copy data into. When omitted, the copied
|
|
633
|
+
* data is buffered in memory and returned as a string instead - convenient for small
|
|
634
|
+
* exports, but not recommended for large tables.
|
|
635
|
+
* @param options - `FORMAT`/`DELIMITER`/`HEADER`/`NULL`/`QUOTE`/`ESCAPE`/column-list options,
|
|
636
|
+
* plus an optional `query` to export the result of an arbitrary `SELECT` instead of a whole table
|
|
637
|
+
* @returns The destination stream (if provided) or the exported data as a string
|
|
638
|
+
*/
|
|
639
|
+
copyTo(tableName: string, destination?: NodeJS.WritableStream, options?: CopyOptions & {
|
|
640
|
+
query?: string;
|
|
641
|
+
}): Promise<NodeJS.WritableStream | string>;
|
|
642
|
+
/**
|
|
643
|
+
* Build a vector similarity distance expression using a pgvector operator.
|
|
644
|
+
*
|
|
645
|
+
* Requires the `pgvector` extension to be installed (see `createExtension('vector')`
|
|
646
|
+
* / `hasExtension('vector')`). The returned SQL can be used directly in an
|
|
647
|
+
* `ORDER BY` clause (nearest-neighbor search) or a `WHERE` clause (thresholding).
|
|
648
|
+
*
|
|
649
|
+
* @param column - Column name holding the `vector` value
|
|
650
|
+
* @param vector - Query vector to compare against
|
|
651
|
+
* @param metric - Distance metric:
|
|
652
|
+
* - 'l2' (default) uses `<->` (Euclidean/L2 distance)
|
|
653
|
+
* - 'cosine' uses `<=>` (cosine distance)
|
|
654
|
+
* - 'innerProduct' uses `<#>` (negative inner product)
|
|
655
|
+
* @param paramIndex - Starting placeholder index (defaults to 1) so callers can
|
|
656
|
+
* splice this expression into a larger parameterized query
|
|
657
|
+
* @returns SQL expression and the values to bind to its placeholder
|
|
658
|
+
*/
|
|
659
|
+
buildVectorDistance(column: string, vector: number[], metric?: 'l2' | 'cosine' | 'innerProduct', paramIndex?: number): {
|
|
660
|
+
sql: string;
|
|
661
|
+
values: unknown[];
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Create a pgvector ANN (approximate nearest neighbor) index using `ivfflat` or `hnsw`.
|
|
665
|
+
*
|
|
666
|
+
* Requires the `pgvector` extension (see `createExtension('vector')`). Example output:
|
|
667
|
+
* CREATE INDEX idx ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)
|
|
668
|
+
* CREATE INDEX idx ON items USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 64)
|
|
669
|
+
*
|
|
670
|
+
* @param tableName - Table name
|
|
671
|
+
* @param indexName - Index name
|
|
672
|
+
* @param column - Vector column name
|
|
673
|
+
* @param options - Index method and tuning parameters
|
|
674
|
+
*/
|
|
675
|
+
createVectorIndex(tableName: string, indexName: string, column: string, options?: {
|
|
676
|
+
method?: 'ivfflat' | 'hnsw';
|
|
677
|
+
metric?: 'l2' | 'cosine' | 'innerProduct';
|
|
678
|
+
lists?: number;
|
|
679
|
+
m?: number;
|
|
680
|
+
efConstruction?: number;
|
|
681
|
+
ifNotExists?: boolean;
|
|
682
|
+
}): Promise<void>;
|
|
683
|
+
/**
|
|
684
|
+
* Build CREATE FOREIGN SERVER SQL.
|
|
685
|
+
*
|
|
686
|
+
* CREATE FOREIGN SERVER [IF NOT EXISTS] name
|
|
687
|
+
* FOREIGN DATA WRAPPER fdw_name
|
|
688
|
+
* [VERSION 'version']
|
|
689
|
+
* [OPTIONS (key 'value', ...)];
|
|
690
|
+
*/
|
|
691
|
+
buildCreateServerQuery(name: string, opts: FdwForeignServerOptions): string;
|
|
692
|
+
/**
|
|
693
|
+
* Build ALTER FOREIGN SERVER SQL.
|
|
694
|
+
*
|
|
695
|
+
* ALTER FOREIGN SERVER name
|
|
696
|
+
* [VERSION 'version']
|
|
697
|
+
* [OPTIONS ([ADD|SET|DROP] key ['value'], ...)];
|
|
698
|
+
*/
|
|
699
|
+
buildAlterServerQuery(name: string, opts: FdwAlterForeignServerOptions): string;
|
|
700
|
+
/**
|
|
701
|
+
* Build DROP FOREIGN SERVER SQL.
|
|
702
|
+
*
|
|
703
|
+
* DROP FOREIGN SERVER [IF EXISTS] name [CASCADE|RESTRICT];
|
|
704
|
+
*/
|
|
705
|
+
buildDropServerQuery(name: string, opts?: {
|
|
706
|
+
ifExists?: boolean;
|
|
707
|
+
cascade?: boolean;
|
|
708
|
+
}): string;
|
|
709
|
+
/**
|
|
710
|
+
* Return the SQL to list all foreign servers from the catalog.
|
|
711
|
+
*/
|
|
712
|
+
getServersQuery(): string;
|
|
713
|
+
/**
|
|
714
|
+
* List all foreign server names. Thin wrapper around getServersQuery().
|
|
715
|
+
*/
|
|
716
|
+
listServers(): Promise<string[]>;
|
|
717
|
+
/**
|
|
718
|
+
* Build CREATE USER MAPPING SQL.
|
|
719
|
+
*
|
|
720
|
+
* CREATE USER MAPPING [IF NOT EXISTS] FOR { user | CURRENT_USER | PUBLIC }
|
|
721
|
+
* SERVER server_name
|
|
722
|
+
* [OPTIONS (key 'value', ...)];
|
|
723
|
+
*/
|
|
724
|
+
buildCreateUserMappingQuery(opts: FdwUserMappingOptions): string;
|
|
725
|
+
/**
|
|
726
|
+
* Build ALTER USER MAPPING SQL.
|
|
727
|
+
*
|
|
728
|
+
* ALTER USER MAPPING FOR { user | CURRENT_USER | PUBLIC }
|
|
729
|
+
* SERVER server_name
|
|
730
|
+
* OPTIONS (...);
|
|
731
|
+
*/
|
|
732
|
+
buildAlterUserMappingQuery(opts: FdwUserMappingOptions): string;
|
|
733
|
+
/**
|
|
734
|
+
* Build DROP USER MAPPING SQL.
|
|
735
|
+
*
|
|
736
|
+
* DROP USER MAPPING [IF EXISTS] FOR { user | CURRENT_USER | PUBLIC }
|
|
737
|
+
* SERVER server_name;
|
|
738
|
+
*/
|
|
739
|
+
buildDropUserMappingQuery(serverName: string, user: string, opts?: {
|
|
740
|
+
ifExists?: boolean;
|
|
741
|
+
}): string;
|
|
742
|
+
/**
|
|
743
|
+
* Create a user mapping for a foreign server
|
|
744
|
+
*/
|
|
745
|
+
createUserMapping(userName: string, serverName: string, options?: {
|
|
746
|
+
username?: string;
|
|
747
|
+
password?: string;
|
|
748
|
+
}): Promise<void>;
|
|
749
|
+
/**
|
|
750
|
+
* Drop a user mapping for a foreign server
|
|
751
|
+
*/
|
|
752
|
+
dropUserMapping(userName: string, serverName: string, options?: {
|
|
753
|
+
ifExists?: boolean;
|
|
754
|
+
}): Promise<void>;
|
|
755
|
+
/**
|
|
756
|
+
* Build CREATE FOREIGN TABLE SQL.
|
|
757
|
+
*
|
|
758
|
+
* CREATE FOREIGN TABLE [IF NOT EXISTS] [schema.]table_name (
|
|
759
|
+
* col1 type [OPTIONS (...)],
|
|
760
|
+
* ...
|
|
761
|
+
* ) SERVER server_name [OPTIONS (key 'value', ...)];
|
|
762
|
+
*/
|
|
763
|
+
buildCreateForeignTableQuery(tableName: string, opts: FdwForeignTableOptions): string;
|
|
764
|
+
/**
|
|
765
|
+
* Build DROP FOREIGN TABLE SQL.
|
|
766
|
+
*
|
|
767
|
+
* DROP FOREIGN TABLE [IF EXISTS] table_name [CASCADE|RESTRICT];
|
|
768
|
+
*/
|
|
769
|
+
buildDropForeignTableQuery(tableName: string, opts?: {
|
|
770
|
+
ifExists?: boolean;
|
|
771
|
+
cascade?: boolean;
|
|
772
|
+
}): string;
|
|
773
|
+
/**
|
|
774
|
+
* Build IMPORT FOREIGN SCHEMA SQL.
|
|
775
|
+
*
|
|
776
|
+
* IMPORT FOREIGN SCHEMA remote_schema
|
|
777
|
+
* [LIMIT TO (t1, t2) | EXCEPT (t1, t2)]
|
|
778
|
+
* FROM SERVER server_name
|
|
779
|
+
* INTO local_schema
|
|
780
|
+
* [OPTIONS (key 'value', ...)];
|
|
781
|
+
*/
|
|
782
|
+
buildImportForeignSchemaQuery(remoteSchema: string, serverName: string, opts?: FdwImportForeignSchemaOptions): string;
|
|
783
|
+
/**
|
|
784
|
+
* Add a column to a table
|
|
785
|
+
*/
|
|
786
|
+
addColumn(tableName: string, columnName: string, definition: ColumnDefinition): Promise<void>;
|
|
787
|
+
/**
|
|
788
|
+
* Remove a column from a table
|
|
789
|
+
*/
|
|
790
|
+
removeColumn(tableName: string, columnName: string): Promise<void>;
|
|
791
|
+
/**
|
|
792
|
+
* Change a column definition
|
|
793
|
+
*/
|
|
794
|
+
changeColumn(tableName: string, columnName: string, definition: ColumnDefinition): Promise<void>;
|
|
795
|
+
/**
|
|
796
|
+
* Show all tables in the database
|
|
797
|
+
*/
|
|
798
|
+
showTables(): Promise<string[]>;
|
|
799
|
+
/**
|
|
800
|
+
* Get table status (PostgreSQL implementation)
|
|
801
|
+
*/
|
|
802
|
+
getTableStatus(tableName?: string): Promise<Record<string, any>[]>;
|
|
803
|
+
/**
|
|
804
|
+
* Get table create statement (PostgreSQL implementation)
|
|
805
|
+
*/
|
|
806
|
+
getCreateTable(tableName: string): Promise<string>;
|
|
807
|
+
/**
|
|
808
|
+
* List the child partitions of a partitioned table (PostgreSQL implementation).
|
|
809
|
+
* Uses pg_inherits/pg_class, the standard catalog tables for native partitioning.
|
|
810
|
+
*/
|
|
811
|
+
listPartitions(tableName: string): Promise<Array<{
|
|
812
|
+
name: string;
|
|
813
|
+
parentTable: string;
|
|
814
|
+
bound: string | null;
|
|
815
|
+
}>>;
|
|
816
|
+
/**
|
|
817
|
+
* Check if a table has partitions (PostgreSQL implementation)
|
|
818
|
+
*/
|
|
819
|
+
hasPartition(tableName: string): Promise<boolean>;
|
|
820
|
+
/**
|
|
821
|
+
* Show constraints for a table
|
|
822
|
+
*/
|
|
823
|
+
showConstraints(tableName: string): Promise<any[]>;
|
|
824
|
+
/**
|
|
825
|
+
* Show indexes for a table
|
|
826
|
+
*/
|
|
827
|
+
showIndexes(tableName: string): Promise<any[]>;
|
|
828
|
+
/**
|
|
829
|
+
* Describe a table (get column information)
|
|
830
|
+
*/
|
|
831
|
+
describeTable(tableName: string): Promise<TableDescription>;
|
|
832
|
+
/**
|
|
833
|
+
* Rename a table
|
|
834
|
+
*/
|
|
835
|
+
renameTable(oldName: string, newName: string): Promise<void>;
|
|
836
|
+
/**
|
|
837
|
+
* Add an index to a table
|
|
838
|
+
*/
|
|
839
|
+
addIndex(tableName: string, indexName: string, fields?: string[], options?: IndexOptions): Promise<void>;
|
|
840
|
+
/**
|
|
841
|
+
* Remove an index from a table
|
|
842
|
+
*/
|
|
843
|
+
removeIndex(tableName: string, indexName: string): Promise<void>;
|
|
844
|
+
/**
|
|
845
|
+
* Create an index on a table with full options support
|
|
846
|
+
*/
|
|
847
|
+
createIndex(tableName: string, indexDef: {
|
|
848
|
+
name: string;
|
|
849
|
+
unique?: boolean;
|
|
850
|
+
type?: string;
|
|
851
|
+
using?: string;
|
|
852
|
+
fields: string[];
|
|
853
|
+
where?: WhereOptions;
|
|
854
|
+
expression?: string;
|
|
855
|
+
include?: string[];
|
|
856
|
+
}): Promise<void>;
|
|
857
|
+
/**
|
|
858
|
+
* Create a GIN index for full-text search
|
|
859
|
+
* PostgreSQL-specific GIN (Generalized Inverted Index) for tsvector
|
|
860
|
+
*/
|
|
861
|
+
createGINIndex(tableName: string, indexName: string, column: string, options?: {
|
|
862
|
+
config?: string;
|
|
863
|
+
storageParameters?: Record<string, string | number>;
|
|
864
|
+
}): Promise<void>;
|
|
865
|
+
/**
|
|
866
|
+
* Build a to_tsvector expression
|
|
867
|
+
* SQL: to_tsvector([config,] document)
|
|
868
|
+
*/
|
|
869
|
+
buildTsVector(column: string | string[], config?: string): string;
|
|
870
|
+
/**
|
|
871
|
+
* Build a to_tsquery expression
|
|
872
|
+
* SQL: to_tsquery([config,] query)
|
|
873
|
+
*/
|
|
874
|
+
buildTsQuery(query: string, config?: string): string;
|
|
875
|
+
/**
|
|
876
|
+
* Build a plainto_tsquery expression (for phrase searching)
|
|
877
|
+
* SQL: plainto_tsquery([config,] query)
|
|
878
|
+
* Converts a phrase into a tsquery that matches documents containing all the words
|
|
879
|
+
*/
|
|
880
|
+
buildPlainTsQuery(query: string, config?: string): string;
|
|
881
|
+
/**
|
|
882
|
+
* Build a phraseto_tsquery expression (for exact phrase matching)
|
|
883
|
+
* SQL: phraseto_tsquery([config,] query)
|
|
884
|
+
* Converts a phrase into a tsquery that matches documents containing the exact phrase
|
|
885
|
+
*/
|
|
886
|
+
buildPhraseTsQuery(query: string, config?: string): string;
|
|
887
|
+
/**
|
|
888
|
+
* Build a websearch_to_tsquery expression (for web search style queries)
|
|
889
|
+
* SQL: websearch_to_tsquery([config,] query)
|
|
890
|
+
* Supports web search operators like +, -, "quotes", etc.
|
|
891
|
+
*/
|
|
892
|
+
buildWebsearchTsQuery(query: string, config?: string): string;
|
|
893
|
+
/**
|
|
894
|
+
* Build a ts_rank expression for ranking full-text search results
|
|
895
|
+
* SQL: ts_rank([weights,] vector, query [, normalization])
|
|
896
|
+
*/
|
|
897
|
+
buildTsRank(vector: string, query: string, options?: {
|
|
898
|
+
weights?: number[];
|
|
899
|
+
normalization?: number;
|
|
900
|
+
}): string;
|
|
901
|
+
/**
|
|
902
|
+
* Create a GIST index for spatial data
|
|
903
|
+
* PostgreSQL GIST (Generalized Search Tree) index for geometry/geography columns
|
|
904
|
+
*/
|
|
905
|
+
createGISTIndex(tableName: string, indexName: string, column: string, options?: {
|
|
906
|
+
/** Use geography instead of geometry */
|
|
907
|
+
geography?: boolean;
|
|
908
|
+
/** Geometry type constraint (e.g., 'POINT', 'POLYGON') */
|
|
909
|
+
geometryType?: string;
|
|
910
|
+
/** SRID constraint (e.g., 4326 for WGS84) */
|
|
911
|
+
srid?: number;
|
|
912
|
+
/** Storage parameters */
|
|
913
|
+
fillFactor?: number;
|
|
914
|
+
}): Promise<void>;
|
|
915
|
+
/**
|
|
916
|
+
* Create a GIN index for spatial data (PostGIS 2.1+)
|
|
917
|
+
* GIN indexes are slower to build but faster for very large datasets with many overlapping geometries
|
|
918
|
+
*/
|
|
919
|
+
createGINSpatialIndex(tableName: string, indexName: string, column: string): Promise<void>;
|
|
920
|
+
/**
|
|
921
|
+
* ST_Distance - calculate distance between two geometries
|
|
922
|
+
* For geography, returns distance in meters
|
|
923
|
+
*/
|
|
924
|
+
stDistance(geom1: string, geom2: string, useGeography?: boolean): string;
|
|
925
|
+
/**
|
|
926
|
+
* ST_DWithin - check if geometries are within a given distance
|
|
927
|
+
* For geography, distance is in meters
|
|
928
|
+
*/
|
|
929
|
+
stDWithin(geom1: string, geom2: string, distance: number, useGeography?: boolean): string;
|
|
930
|
+
/**
|
|
931
|
+
* ST_Within - check if geometry A is within geometry B
|
|
932
|
+
*/
|
|
933
|
+
stWithin(geom1: string, geom2: string): string;
|
|
934
|
+
/**
|
|
935
|
+
* ST_Contains - check if geometry A contains geometry B
|
|
936
|
+
*/
|
|
937
|
+
stContains(geom1: string, geom2: string): string;
|
|
938
|
+
/**
|
|
939
|
+
* ST_Intersects - check if two geometries intersect
|
|
940
|
+
*/
|
|
941
|
+
stIntersects(geom1: string, geom2: string): string;
|
|
942
|
+
/**
|
|
943
|
+
* ST_Crosses - check if two geometries cross
|
|
944
|
+
*/
|
|
945
|
+
stCrosses(geom1: string, geom2: string): string;
|
|
946
|
+
/**
|
|
947
|
+
* ST_Overlaps - check if two geometries overlap
|
|
948
|
+
*/
|
|
949
|
+
stOverlaps(geom1: string, geom2: string): string;
|
|
950
|
+
/**
|
|
951
|
+
* ST_Touches - check if two geometries touch
|
|
952
|
+
*/
|
|
953
|
+
stTouches(geom1: string, geom2: string): string;
|
|
954
|
+
/**
|
|
955
|
+
* ST_Equals - check if two geometries are equal
|
|
956
|
+
*/
|
|
957
|
+
stEquals(geom1: string, geom2: string): string;
|
|
958
|
+
/**
|
|
959
|
+
* ST_IsValid - check if a geometry is valid
|
|
960
|
+
*/
|
|
961
|
+
stIsValid(geom: string): string;
|
|
962
|
+
/**
|
|
963
|
+
* ST_GeomFromText - create geometry from WKT text
|
|
964
|
+
*/
|
|
965
|
+
stGeomFromText(wkt: string, srid?: number): string;
|
|
966
|
+
/**
|
|
967
|
+
* ST_GeomFromGeoJSON - create geometry from GeoJSON
|
|
968
|
+
*/
|
|
969
|
+
stGeomFromGeoJSON(geojson: string, srid?: number): string;
|
|
970
|
+
/**
|
|
971
|
+
* ST_AsGeoJSON - convert geometry to GeoJSON
|
|
972
|
+
*/
|
|
973
|
+
stAsGeoJSON(geom: string, options?: {
|
|
974
|
+
precision?: number;
|
|
975
|
+
longCRS?: boolean;
|
|
976
|
+
}): string;
|
|
977
|
+
/**
|
|
978
|
+
* ST_AsText - convert geometry to WKT
|
|
979
|
+
*/
|
|
980
|
+
stAsText(geom: string): string;
|
|
981
|
+
/**
|
|
982
|
+
* ST_Centroid - get the centroid of a geometry
|
|
983
|
+
*/
|
|
984
|
+
stCentroid(geom: string): string;
|
|
985
|
+
/**
|
|
986
|
+
* ST_Area - calculate the area of a polygon
|
|
987
|
+
* For geography, returns area in square meters
|
|
988
|
+
*/
|
|
989
|
+
stArea(geom: string, useGeography?: boolean): string;
|
|
990
|
+
/**
|
|
991
|
+
* ST_Length - calculate the length of a line
|
|
992
|
+
* For geography, returns length in meters
|
|
993
|
+
*/
|
|
994
|
+
stLength(geom: string, useGeography?: boolean): string;
|
|
995
|
+
/**
|
|
996
|
+
* ST_Point - create a point from coordinates
|
|
997
|
+
*/
|
|
998
|
+
stPoint(long: string, lat: string): string;
|
|
999
|
+
/**
|
|
1000
|
+
* ST_SetSRID - set the SRID of a geometry
|
|
1001
|
+
*/
|
|
1002
|
+
stSetSRID(geom: string, srid: number): string;
|
|
1003
|
+
/**
|
|
1004
|
+
* ST_SRID - get the SRID of a geometry
|
|
1005
|
+
*/
|
|
1006
|
+
stSRID(geom: string): string;
|
|
1007
|
+
/**
|
|
1008
|
+
* ST_X - get the X coordinate of a point
|
|
1009
|
+
*/
|
|
1010
|
+
stX(geom: string): string;
|
|
1011
|
+
/**
|
|
1012
|
+
* ST_Y - get the Y coordinate of a point
|
|
1013
|
+
*/
|
|
1014
|
+
stY(geom: string): string;
|
|
1015
|
+
/**
|
|
1016
|
+
* ST_Distance_Sphere - calculate distance using sphere (less accurate but faster)
|
|
1017
|
+
* Returns distance in meters
|
|
1018
|
+
*/
|
|
1019
|
+
stDistanceSphere(geom1: string, geom2: string): string;
|
|
1020
|
+
/**
|
|
1021
|
+
* ST_Distance_Spheroid - calculate distance using spheroid (accurate)
|
|
1022
|
+
* Returns distance in meters
|
|
1023
|
+
*/
|
|
1024
|
+
stDistanceSpheroid(geom1: string, geom2: string): string;
|
|
1025
|
+
/**
|
|
1026
|
+
* Drop an index from a table
|
|
1027
|
+
*/
|
|
1028
|
+
dropIndex(tableName: string, indexName: string, options?: {
|
|
1029
|
+
ifExists?: boolean;
|
|
1030
|
+
cascade?: boolean;
|
|
1031
|
+
}): Promise<void>;
|
|
1032
|
+
/**
|
|
1033
|
+
* Create a constraint on a table
|
|
1034
|
+
*/
|
|
1035
|
+
createConstraint(tableName: string, constraintDef: {
|
|
1036
|
+
name: string;
|
|
1037
|
+
type: 'PRIMARY KEY' | 'UNIQUE' | 'FOREIGN KEY' | 'CHECK' | 'EXCLUDE';
|
|
1038
|
+
fields?: string[];
|
|
1039
|
+
references?: {
|
|
1040
|
+
table: string;
|
|
1041
|
+
field: string;
|
|
1042
|
+
onDelete?: string;
|
|
1043
|
+
onUpdate?: string;
|
|
1044
|
+
};
|
|
1045
|
+
check?: string;
|
|
1046
|
+
deferrable?: 'INITIALLY DEFERRED' | 'INITIALLY IMMEDIATE';
|
|
1047
|
+
/**
|
|
1048
|
+
* `EXCLUDE` constraint elements, e.g. `[{ column: 'room_id', operator: '=' },
|
|
1049
|
+
* { column: 'during', operator: '&&' }]` produces
|
|
1050
|
+
* `EXCLUDE USING gist (room_id WITH =, during WITH &&)`.
|
|
1051
|
+
*/
|
|
1052
|
+
exclude?: {
|
|
1053
|
+
using?: string;
|
|
1054
|
+
elements: Array<{
|
|
1055
|
+
column: string;
|
|
1056
|
+
operator: string;
|
|
1057
|
+
}>;
|
|
1058
|
+
where?: string;
|
|
1059
|
+
};
|
|
1060
|
+
}): Promise<void>;
|
|
1061
|
+
/**
|
|
1062
|
+
* Drop a constraint from a table
|
|
1063
|
+
*/
|
|
1064
|
+
dropConstraint(tableName: string, constraintName: string, options?: {
|
|
1065
|
+
ifExists?: boolean;
|
|
1066
|
+
cascade?: boolean;
|
|
1067
|
+
}): Promise<void>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Begin a new transaction
|
|
1070
|
+
*/
|
|
1071
|
+
startTransaction(options?: TransactionOptions): Promise<Transaction>;
|
|
1072
|
+
/**
|
|
1073
|
+
* Commit a transaction
|
|
1074
|
+
*/
|
|
1075
|
+
commitTransaction(transaction: Transaction): Promise<void>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Rollback a transaction
|
|
1078
|
+
*/
|
|
1079
|
+
rollbackTransaction(transaction: Transaction): Promise<void>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Get the SQL for a data type
|
|
1082
|
+
*/
|
|
1083
|
+
getDataTypeSql(dataType: DataType): string;
|
|
1084
|
+
/**
|
|
1085
|
+
* Get the SQL for an ARRAY type
|
|
1086
|
+
*/
|
|
1087
|
+
getArrayTypeSql(elementType: DataType): string;
|
|
1088
|
+
/**
|
|
1089
|
+
* Get the isolation level SQL
|
|
1090
|
+
*/
|
|
1091
|
+
private getIsolationLevelSql;
|
|
1092
|
+
/**
|
|
1093
|
+
* Resolve a WHERE-clause field key to SQL, supporting Sequelize-style inline JSON path
|
|
1094
|
+
* keys like `'data->>active'` or `'data->meta->>role'` (translated to
|
|
1095
|
+
* `"data"->>'active'` / `"data"->'meta'->>'role'`) in addition to plain column names.
|
|
1096
|
+
* Without this, a key containing `->`/`->>` was passed straight to escapeId(), which
|
|
1097
|
+
* double-quotes the whole string as one (nonexistent) column name.
|
|
1098
|
+
*/
|
|
1099
|
+
private escapeJsonPathKey;
|
|
1100
|
+
/**
|
|
1101
|
+
* Build a WHERE clause from a WhereOptions object
|
|
1102
|
+
*/
|
|
1103
|
+
buildWhereClause(where: WhereOptions, options?: {
|
|
1104
|
+
replacements?: Record<string, unknown>;
|
|
1105
|
+
}): {
|
|
1106
|
+
sql: string;
|
|
1107
|
+
values: unknown[];
|
|
1108
|
+
};
|
|
1109
|
+
/**
|
|
1110
|
+
* Build an ORDER BY clause
|
|
1111
|
+
*/
|
|
1112
|
+
buildOrderClause(order: Order, options?: {
|
|
1113
|
+
replacements?: Record<string, unknown>;
|
|
1114
|
+
}): string;
|
|
1115
|
+
/**
|
|
1116
|
+
* Build a LIMIT/OFFSET clause
|
|
1117
|
+
*/
|
|
1118
|
+
buildLimitOffset(limit?: number | string, offset?: number | string): string;
|
|
1119
|
+
/**
|
|
1120
|
+
* Build an INSERT query with RETURNING support
|
|
1121
|
+
*/
|
|
1122
|
+
buildInsertQuery(tableName: string, values: Record<string, unknown>, options?: InsertOptions): {
|
|
1123
|
+
sql: string;
|
|
1124
|
+
values: unknown[];
|
|
1125
|
+
};
|
|
1126
|
+
/**
|
|
1127
|
+
* Build an UPSERT query for PostgreSQL
|
|
1128
|
+
* Uses ON CONFLICT ... DO UPDATE SET syntax
|
|
1129
|
+
*/
|
|
1130
|
+
buildUpsertQuery(tableName: string, values: Record<string, unknown>, options?: UpsertQueryOptions): {
|
|
1131
|
+
sql: string;
|
|
1132
|
+
values: unknown[];
|
|
1133
|
+
};
|
|
1134
|
+
/**
|
|
1135
|
+
* Build a PostgreSQL 15+ `MERGE INTO ... USING ... ON ... WHEN [NOT] MATCHED ...` statement.
|
|
1136
|
+
*
|
|
1137
|
+
* This is an additional builder alongside `buildUpsertQuery` (which uses `INSERT ... ON
|
|
1138
|
+
* CONFLICT` for simple single-condition upserts). `MERGE` is useful when the merge logic
|
|
1139
|
+
* needs multiple conditional branches (e.g. delete on one condition, update on another,
|
|
1140
|
+
* insert otherwise) or when merging from an arbitrary source table/subquery rather than
|
|
1141
|
+
* a single row of values.
|
|
1142
|
+
*
|
|
1143
|
+
* @param targetTable - Table being merged into
|
|
1144
|
+
* @param source - Source table/subquery to merge from, with an alias
|
|
1145
|
+
* @param onCondition - Raw SQL join condition (e.g. `target.id = source.id`)
|
|
1146
|
+
* @param whenMatched - Ordered list of `WHEN MATCHED [AND condition] THEN ...` clauses
|
|
1147
|
+
* @param whenNotMatched - Ordered list of `WHEN NOT MATCHED [AND condition] THEN ...` clauses
|
|
1148
|
+
* @param options - Optional RETURNING clause (PostgreSQL 17+)
|
|
1149
|
+
*/
|
|
1150
|
+
buildMergeQuery(targetTable: string, source: {
|
|
1151
|
+
table: string;
|
|
1152
|
+
alias?: string;
|
|
1153
|
+
}, onCondition: string, whenMatched?: MergeWhenMatchedClause[], whenNotMatched?: MergeWhenNotMatchedClause[], options?: {
|
|
1154
|
+
returning?: boolean | string[];
|
|
1155
|
+
}): {
|
|
1156
|
+
sql: string;
|
|
1157
|
+
values: unknown[];
|
|
1158
|
+
};
|
|
1159
|
+
/**
|
|
1160
|
+
* Build an increment query
|
|
1161
|
+
* @param tableName - Table name
|
|
1162
|
+
* @param fields - Fields to increment
|
|
1163
|
+
* @param where - Where clause
|
|
1164
|
+
* @param options - Query options (by: number)
|
|
1165
|
+
*/
|
|
1166
|
+
buildIncrementQuery(tableName: string, fields: string | string[] | Record<string, number>, where: WhereOptions, options?: {
|
|
1167
|
+
by?: number;
|
|
1168
|
+
}): {
|
|
1169
|
+
sql: string;
|
|
1170
|
+
values: unknown[];
|
|
1171
|
+
};
|
|
1172
|
+
/**
|
|
1173
|
+
* Build an UPDATE query with RETURNING support
|
|
1174
|
+
*/
|
|
1175
|
+
buildUpdateQuery(tableName: string, values: Record<string, unknown>, where: WhereOptions, options?: DUpdateOptions): {
|
|
1176
|
+
sql: string;
|
|
1177
|
+
values: unknown[];
|
|
1178
|
+
};
|
|
1179
|
+
/**
|
|
1180
|
+
* Build a DELETE query with RETURNING support
|
|
1181
|
+
*/
|
|
1182
|
+
buildDeleteQuery(tableName: string, where: WhereOptions, options?: DeleteOptions): {
|
|
1183
|
+
sql: string;
|
|
1184
|
+
values: unknown[];
|
|
1185
|
+
};
|
|
1186
|
+
/**
|
|
1187
|
+
* Check if a value is a function expression (fn('COUNT', ...))
|
|
1188
|
+
*/
|
|
1189
|
+
private isFnExpression;
|
|
1190
|
+
/**
|
|
1191
|
+
* Check if a value is a column expression (col('name'))
|
|
1192
|
+
*/
|
|
1193
|
+
private isColExpression;
|
|
1194
|
+
/**
|
|
1195
|
+
* Check if a value is a literal expression (literal('sql'))
|
|
1196
|
+
*/
|
|
1197
|
+
/**
|
|
1198
|
+
* Render a literal expression, substituting any `bindings` into its `?`
|
|
1199
|
+
* placeholders with dialect-correct escaping. `literalExpr(sql)` with no
|
|
1200
|
+
* bindings is unchanged; `literalExpr('x > ?', [v])` no longer requires the
|
|
1201
|
+
* caller to concatenate the value into the string themselves.
|
|
1202
|
+
*/
|
|
1203
|
+
private literalSql;
|
|
1204
|
+
private isLiteralExpression;
|
|
1205
|
+
/**
|
|
1206
|
+
* Compile a function expression to SQL
|
|
1207
|
+
*/
|
|
1208
|
+
private compileFnExpression;
|
|
1209
|
+
/**
|
|
1210
|
+
* Build SELECT clause with support for function expressions and aliases
|
|
1211
|
+
* Handles: 'field', ['field'], ['field', 'alias'], [fn('COUNT', 'id'), 'count']
|
|
1212
|
+
*/
|
|
1213
|
+
private buildSelectClause;
|
|
1214
|
+
/**
|
|
1215
|
+
* Build GROUP BY clause with support for function expressions and aliases
|
|
1216
|
+
* Handles: 'field', ['field1', 'field2'], [[fn('COUNT', 'id'), 'count']]
|
|
1217
|
+
*/
|
|
1218
|
+
private buildGroupByClause;
|
|
1219
|
+
/**
|
|
1220
|
+
* Build a WHERE clause condition using standard operators (Op.gt, Op.eq, etc.)
|
|
1221
|
+
* PostgreSQL uses $1, $2, etc. for parameter placeholders
|
|
1222
|
+
*/
|
|
1223
|
+
private buildCondition;
|
|
1224
|
+
/**
|
|
1225
|
+
* Build a HAVING clause with support for standard Op operators
|
|
1226
|
+
*/
|
|
1227
|
+
private buildHavingClause;
|
|
1228
|
+
/**
|
|
1229
|
+
* Build a SELECT query with PostgreSQL-specific features
|
|
1230
|
+
*/
|
|
1231
|
+
/**
|
|
1232
|
+
* Build a `WITH [RECURSIVE] name [(cols)] AS (query), ...` clause from
|
|
1233
|
+
* `SelectOptions.cte`. Nested `SelectOptions` queries are compiled via a
|
|
1234
|
+
* recursive call to `buildSelectQuery`; raw SQL strings are used verbatim.
|
|
1235
|
+
*
|
|
1236
|
+
* Placeholder values contributed by CTE subqueries are returned in the
|
|
1237
|
+
* order they appear in the rendered SQL so callers can prepend them to the
|
|
1238
|
+
* overall query's `values` array before renumbering downstream clauses.
|
|
1239
|
+
*/
|
|
1240
|
+
buildWithClause(ctes: CTEOption[]): {
|
|
1241
|
+
sql: string;
|
|
1242
|
+
values: unknown[];
|
|
1243
|
+
};
|
|
1244
|
+
/**
|
|
1245
|
+
* Shift all `$n` positional placeholders in a SQL fragment by `offset`.
|
|
1246
|
+
* Used to keep parameter numbering correct when a clause built in
|
|
1247
|
+
* isolation (which always numbers its own placeholders starting at `$1`)
|
|
1248
|
+
* is appended after other clauses that already consumed placeholder slots.
|
|
1249
|
+
*/
|
|
1250
|
+
private offsetParamPlaceholders;
|
|
1251
|
+
buildSelectQuery(options: SelectOptions): {
|
|
1252
|
+
sql: string;
|
|
1253
|
+
values: unknown[];
|
|
1254
|
+
};
|
|
1255
|
+
/**
|
|
1256
|
+
* Escape a value for use in a PostgreSQL array literal
|
|
1257
|
+
*/
|
|
1258
|
+
escapeArray(values: unknown[]): string;
|
|
1259
|
+
/**
|
|
1260
|
+
* Build an array contains operator query (@>)
|
|
1261
|
+
* SELECT * FROM table WHERE column @> ARRAY['elem1', 'elem2']
|
|
1262
|
+
*/
|
|
1263
|
+
buildArrayContains(column: string, values: unknown[]): string;
|
|
1264
|
+
/**
|
|
1265
|
+
* Build an array contained by operator query (<@)
|
|
1266
|
+
* SELECT * FROM table WHERE column <@ ARRAY['elem1', 'elem2']
|
|
1267
|
+
*/
|
|
1268
|
+
buildArrayContainedBy(column: string, values: unknown[]): string;
|
|
1269
|
+
/**
|
|
1270
|
+
* Build an array overlaps operator query (&&)
|
|
1271
|
+
* SELECT * FROM table WHERE column && ARRAY['elem1', 'elem2']
|
|
1272
|
+
*/
|
|
1273
|
+
buildArrayOverlaps(column: string, values: unknown[]): string;
|
|
1274
|
+
/**
|
|
1275
|
+
* Build an array ANY operator query
|
|
1276
|
+
* SELECT * FROM table WHERE 'value' = ANY(column)
|
|
1277
|
+
*/
|
|
1278
|
+
buildArrayAny(column: string, value: unknown): string;
|
|
1279
|
+
/**
|
|
1280
|
+
* Build an array ALL operator query
|
|
1281
|
+
* SELECT * FROM table WHERE 'value' = ALL(column)
|
|
1282
|
+
* or with comparison: SELECT * FROM table WHERE value > ALL(column)
|
|
1283
|
+
*/
|
|
1284
|
+
buildArrayAll(column: string, value: unknown, operator?: string): string;
|
|
1285
|
+
/**
|
|
1286
|
+
* Build a full-text search query
|
|
1287
|
+
*/
|
|
1288
|
+
buildFullTextSearchQuery(tableName: string, searchColumns: string[], searchTerm: string, options?: {
|
|
1289
|
+
language?: string;
|
|
1290
|
+
ranking?: 'ts_rank' | 'ts_rank_cd';
|
|
1291
|
+
orderBy?: Order;
|
|
1292
|
+
}): {
|
|
1293
|
+
sql: string;
|
|
1294
|
+
values: unknown[];
|
|
1295
|
+
};
|
|
1296
|
+
/**
|
|
1297
|
+
* Build a JSON/JSONB path query
|
|
1298
|
+
*/
|
|
1299
|
+
buildJsonPathQuery(column: string, path: string, value: unknown, operator: '=' | '!=' | '>' | '<' | '>=' | '<=' | '~' | '~*' | '@>' | '<@' | '?' | '?|'): {
|
|
1300
|
+
sql: string;
|
|
1301
|
+
values: unknown[];
|
|
1302
|
+
};
|
|
1303
|
+
/**
|
|
1304
|
+
* Get PostgreSQL specific lock options
|
|
1305
|
+
*/
|
|
1306
|
+
getLockOptions(lock: any): {
|
|
1307
|
+
sql: string;
|
|
1308
|
+
params: unknown[];
|
|
1309
|
+
};
|
|
1310
|
+
/**
|
|
1311
|
+
* Acquire a session-level advisory lock (`pg_advisory_lock`), blocking until it is available.
|
|
1312
|
+
* Pass a single 64-bit key, or two 32-bit keys (`key`, `key2`) for the two-argument form.
|
|
1313
|
+
*
|
|
1314
|
+
* Returns a handle whose `release()` calls `pg_advisory_unlock` and returns the underlying
|
|
1315
|
+
* connection back to the pool. Always call `release()` (e.g. in a `finally` block) - until
|
|
1316
|
+
* you do, this holds one connection out of the pool for the lifetime of the lock.
|
|
1317
|
+
*/
|
|
1318
|
+
pgAdvisoryLock(key: number | bigint, key2?: number): Promise<{
|
|
1319
|
+
release: () => Promise<void>;
|
|
1320
|
+
}>;
|
|
1321
|
+
/**
|
|
1322
|
+
* Attempt to acquire a session-level advisory lock without blocking
|
|
1323
|
+
* (`pg_try_advisory_lock`). Resolves immediately with `acquired: false` if the lock is
|
|
1324
|
+
* already held elsewhere. When `acquired` is `true`, call `release()` to unlock and return
|
|
1325
|
+
* the underlying connection to the pool; when `false`, the connection has already been
|
|
1326
|
+
* returned to the pool and `release()` is a no-op.
|
|
1327
|
+
*/
|
|
1328
|
+
pgTryAdvisoryLock(key: number | bigint, key2?: number): Promise<{
|
|
1329
|
+
acquired: boolean;
|
|
1330
|
+
release: () => Promise<void>;
|
|
1331
|
+
}>;
|
|
1332
|
+
/**
|
|
1333
|
+
* Escape a single-quoted string value (replace ' with '').
|
|
1334
|
+
*/
|
|
1335
|
+
private escapeStringValue;
|
|
1336
|
+
/**
|
|
1337
|
+
* Build the shared WITH-clause attribute list used by both CREATE USER and
|
|
1338
|
+
* ALTER USER. Returns a (possibly empty) array of attribute tokens.
|
|
1339
|
+
*/
|
|
1340
|
+
private buildUserAttributes;
|
|
1341
|
+
/**
|
|
1342
|
+
* Build a CREATE USER statement.
|
|
1343
|
+
*
|
|
1344
|
+
* PostgreSQL treats users as roles with LOGIN. Supported options:
|
|
1345
|
+
* ifNotExists, password, superuser, createdb, createrole, login,
|
|
1346
|
+
* replication, bypassrls, maxConnections, accountLocked, expirePassword,
|
|
1347
|
+
* defaultRole, requireSSL (noted but skipped — not a standard PG attribute).
|
|
1348
|
+
*/
|
|
1349
|
+
buildCreateUserQuery(username: string, options?: any): string;
|
|
1350
|
+
/**
|
|
1351
|
+
* Build an ALTER USER statement.
|
|
1352
|
+
*
|
|
1353
|
+
* Supports the same attribute options as buildCreateUserQuery plus
|
|
1354
|
+
* `options.renameTo` to rename the role.
|
|
1355
|
+
*/
|
|
1356
|
+
buildAlterUserQuery(username: string, options: any): string;
|
|
1357
|
+
/**
|
|
1358
|
+
* Build a DROP USER statement.
|
|
1359
|
+
*
|
|
1360
|
+
* Options: ifExists, cascade, restrict.
|
|
1361
|
+
*/
|
|
1362
|
+
buildDropUserQuery(username: string, options?: any): string;
|
|
1363
|
+
/**
|
|
1364
|
+
* Return a query that lists all PostgreSQL users (roles with LOGIN).
|
|
1365
|
+
*/
|
|
1366
|
+
getUsersQuery(): string;
|
|
1367
|
+
/**
|
|
1368
|
+
* Create a database user
|
|
1369
|
+
*/
|
|
1370
|
+
createUser(username: string, options?: Record<string, any>): Promise<void>;
|
|
1371
|
+
/**
|
|
1372
|
+
* List all PostgreSQL login users (roles with LOGIN).
|
|
1373
|
+
* Thin wrapper around getUsersQuery() so callers don't need to build/parse SQL themselves.
|
|
1374
|
+
*/
|
|
1375
|
+
listUsers(): Promise<string[]>;
|
|
1376
|
+
/**
|
|
1377
|
+
* Drop a database user (PostgreSQL treats users as roles; DROP USER is an alias for DROP ROLE).
|
|
1378
|
+
*/
|
|
1379
|
+
dropUser(username: string, options?: {
|
|
1380
|
+
ifExists?: boolean;
|
|
1381
|
+
}): Promise<void>;
|
|
1382
|
+
/**
|
|
1383
|
+
* Create a role (PostgreSQL role without LOGIN by default, distinguishing it from createUser()).
|
|
1384
|
+
*/
|
|
1385
|
+
createRole(roleName: string, options?: Record<string, any>): Promise<void>;
|
|
1386
|
+
/**
|
|
1387
|
+
* Drop a role.
|
|
1388
|
+
*/
|
|
1389
|
+
dropRole(roleName: string, options?: {
|
|
1390
|
+
ifExists?: boolean;
|
|
1391
|
+
}): Promise<void>;
|
|
1392
|
+
/**
|
|
1393
|
+
* List all PostgreSQL roles (pg_roles), including non-login roles.
|
|
1394
|
+
*/
|
|
1395
|
+
listRoles(): Promise<string[]>;
|
|
1396
|
+
/**
|
|
1397
|
+
* Simple GRANT wrapper: GRANT <privilege> ON <table> TO <grantee>.
|
|
1398
|
+
* For more advanced scopes (database/schema/column-level, WITH GRANT OPTION, etc.)
|
|
1399
|
+
* use buildGrantQuery() directly.
|
|
1400
|
+
*/
|
|
1401
|
+
grant(privilege: string, on: string, to: string): Promise<void>;
|
|
1402
|
+
/**
|
|
1403
|
+
* Simple REVOKE wrapper: REVOKE <privilege> ON <table> FROM <grantee>.
|
|
1404
|
+
*/
|
|
1405
|
+
revoke(privilege: string, on: string, from: string): Promise<void>;
|
|
1406
|
+
/**
|
|
1407
|
+
* Map a generic privilege name to a PostgreSQL privilege name.
|
|
1408
|
+
* Returns null when the privilege has no PostgreSQL equivalent and
|
|
1409
|
+
* should be silently skipped.
|
|
1410
|
+
*/
|
|
1411
|
+
private mapPrivilege;
|
|
1412
|
+
/**
|
|
1413
|
+
* Build the ON <scope> clause for GRANT / REVOKE.
|
|
1414
|
+
*
|
|
1415
|
+
* Scope shapes:
|
|
1416
|
+
* { level: 'global' }
|
|
1417
|
+
* { level: 'database', database: 'dbname' }
|
|
1418
|
+
* { level: 'schema', schema: 'schemaname' }
|
|
1419
|
+
* { level: 'table', table: 'tablename' }
|
|
1420
|
+
* { level: 'column', table: 'tablename', columns: ['col1', 'col2'] }
|
|
1421
|
+
* { level: 'sequence', schema: 'schemaname' }
|
|
1422
|
+
*/
|
|
1423
|
+
private buildGrantScope;
|
|
1424
|
+
/**
|
|
1425
|
+
* Build a GRANT statement.
|
|
1426
|
+
*
|
|
1427
|
+
* options.privileges — string | string[] (e.g. ['SELECT', 'INSERT'])
|
|
1428
|
+
* options.on — scope object (see buildGrantScope)
|
|
1429
|
+
* options.to — string | string[] (grantees)
|
|
1430
|
+
* options.withGrantOption — boolean
|
|
1431
|
+
* options.asUser — string (GRANTED BY, PG 14+)
|
|
1432
|
+
*
|
|
1433
|
+
* For column-level grants (options.on.level === 'column') the columns are
|
|
1434
|
+
* embedded in each privilege token: SELECT (col1, col2).
|
|
1435
|
+
*/
|
|
1436
|
+
buildGrantQuery(options: any): string;
|
|
1437
|
+
/**
|
|
1438
|
+
* Build a REVOKE statement.
|
|
1439
|
+
*
|
|
1440
|
+
* options.privileges — string | string[]
|
|
1441
|
+
* options.on — scope object (same as buildGrantQuery)
|
|
1442
|
+
* options.from — string | string[] (revokees)
|
|
1443
|
+
* options.grantOptionFor — boolean (revoke only the GRANT OPTION)
|
|
1444
|
+
* options.cascade — boolean
|
|
1445
|
+
* options.restrict — boolean
|
|
1446
|
+
*/
|
|
1447
|
+
buildRevokeQuery(options: any): string;
|
|
1448
|
+
/**
|
|
1449
|
+
* Return a query that shows the privileges granted to a specific user/role.
|
|
1450
|
+
* The optional `host` parameter is ignored — PostgreSQL has no host concept.
|
|
1451
|
+
*/
|
|
1452
|
+
buildShowGrantsQuery(username: string, _host?: string): string;
|
|
1453
|
+
/**
|
|
1454
|
+
* PostgreSQL applies privilege changes automatically — FLUSH PRIVILEGES is
|
|
1455
|
+
* a MySQL concept. Return a no-op with an explanatory comment.
|
|
1456
|
+
*/
|
|
1457
|
+
buildFlushPrivilegesQuery(): string;
|
|
1458
|
+
/**
|
|
1459
|
+
* Build a CREATE ROLE statement.
|
|
1460
|
+
*
|
|
1461
|
+
* Unlike CREATE USER, NOLOGIN is the default for roles. Pass
|
|
1462
|
+
* `options.login = true` to enable login.
|
|
1463
|
+
*
|
|
1464
|
+
* Supported options: ifNotExists, login, password, superuser, createdb,
|
|
1465
|
+
* createrole, inherit, replication, bypassrls, maxConnections,
|
|
1466
|
+
* expirePassword, accountLocked.
|
|
1467
|
+
*/
|
|
1468
|
+
buildCreateRoleQuery(roleName: string, options?: any): string;
|
|
1469
|
+
/**
|
|
1470
|
+
* Build a DROP ROLE statement.
|
|
1471
|
+
*
|
|
1472
|
+
* Options: ifExists, cascade.
|
|
1473
|
+
*/
|
|
1474
|
+
buildDropRoleQuery(roleName: string, options?: any): string;
|
|
1475
|
+
/**
|
|
1476
|
+
* Build a GRANT <role> TO <members> statement.
|
|
1477
|
+
*
|
|
1478
|
+
* Options: withAdminOption.
|
|
1479
|
+
*/
|
|
1480
|
+
buildGrantRoleQuery(role: string, to: string | string[], options?: any): string;
|
|
1481
|
+
/**
|
|
1482
|
+
* Build a REVOKE <role> FROM <members> statement.
|
|
1483
|
+
*
|
|
1484
|
+
* Options: adminOptionFor, cascade.
|
|
1485
|
+
*/
|
|
1486
|
+
buildRevokeRoleQuery(role: string, from: string | string[], options?: any): string;
|
|
1487
|
+
/**
|
|
1488
|
+
* Return a query that lists all PostgreSQL roles that cannot log in
|
|
1489
|
+
* (i.e. "group roles" as opposed to user roles).
|
|
1490
|
+
*/
|
|
1491
|
+
getRolesQuery(): string;
|
|
1492
|
+
/**
|
|
1493
|
+
* Generate SQL for creating a PostgreSQL database
|
|
1494
|
+
*/
|
|
1495
|
+
createDatabaseSQL(options: {
|
|
1496
|
+
name: string;
|
|
1497
|
+
encoding?: string;
|
|
1498
|
+
lcCollate?: string;
|
|
1499
|
+
lcCtype?: string;
|
|
1500
|
+
template?: string;
|
|
1501
|
+
tablespace?: string;
|
|
1502
|
+
isTemplate?: boolean;
|
|
1503
|
+
}): string;
|
|
1504
|
+
/**
|
|
1505
|
+
* Generate SQL for dropping a PostgreSQL database
|
|
1506
|
+
*/
|
|
1507
|
+
dropDatabaseSQL(name: string): string;
|
|
1508
|
+
/**
|
|
1509
|
+
* Generate SQL for creating a savepoint
|
|
1510
|
+
*/
|
|
1511
|
+
createSavepointSQL(name?: string): string;
|
|
1512
|
+
/**
|
|
1513
|
+
* Generate SQL for releasing a savepoint
|
|
1514
|
+
*/
|
|
1515
|
+
releaseSavepointSQL(name: string): string;
|
|
1516
|
+
/**
|
|
1517
|
+
* Generate SQL for rolling back to a savepoint
|
|
1518
|
+
*/
|
|
1519
|
+
rollbackToSavepointSQL(name: string): string;
|
|
1520
|
+
/**
|
|
1521
|
+
* Build a jsonb_to_recordset expression to shred a JSON array into relational rows.
|
|
1522
|
+
* Postgres only gained a native `JSON_TABLE` in PG17+; `jsonb_to_recordset(...) AS
|
|
1523
|
+
* alias(col type, ...)` has been available since 9.4 and matches how the rest of this
|
|
1524
|
+
* dialect's JSON handling (jsonb operators, `buildJsonPathQuery`) already works, so it
|
|
1525
|
+
* is used here for broad version compatibility.
|
|
1526
|
+
* Per-column `path` is not used — jsonb_to_recordset matches columns to top-level JSON
|
|
1527
|
+
* object keys by name. `rowPath` (dot-notation, e.g. `$.items`) is used only to narrow
|
|
1528
|
+
* down to the nested array being expanded, via the `#>` path-extraction operator.
|
|
1529
|
+
* Postgres: jsonb_to_recordset(expr #> '{items}') AS alias(name type, ...)
|
|
1530
|
+
*/
|
|
1531
|
+
buildJsonTable(jsonExpression: string, rowPath: string, columns: Array<{
|
|
1532
|
+
name: string;
|
|
1533
|
+
type?: string;
|
|
1534
|
+
path?: string;
|
|
1535
|
+
forOrdinality?: boolean;
|
|
1536
|
+
}>, alias: string): string;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* PostgreSQL-specific transaction class with isolation level support and savepoints
|
|
1540
|
+
*/
|
|
1541
|
+
export declare class PostgresTransaction implements Transaction {
|
|
1542
|
+
id: string;
|
|
1543
|
+
finished: boolean;
|
|
1544
|
+
options: TransactionOptions;
|
|
1545
|
+
parent: Transaction | null;
|
|
1546
|
+
savepoints: string[];
|
|
1547
|
+
client: PoolClient | null;
|
|
1548
|
+
private savepointCount;
|
|
1549
|
+
constructor(client: PoolClient, depth: number, options?: TransactionOptions);
|
|
1550
|
+
/**
|
|
1551
|
+
* Create a savepoint
|
|
1552
|
+
*/
|
|
1553
|
+
createSavepoint(name?: string): Promise<string>;
|
|
1554
|
+
/**
|
|
1555
|
+
* Rollback to a savepoint
|
|
1556
|
+
*/
|
|
1557
|
+
rollbackToSavepoint(name: string): Promise<void>;
|
|
1558
|
+
/**
|
|
1559
|
+
* Release a savepoint
|
|
1560
|
+
*/
|
|
1561
|
+
releaseSavepoint(name: string): Promise<void>;
|
|
1562
|
+
commit(): Promise<void>;
|
|
1563
|
+
rollback(): Promise<void>;
|
|
1564
|
+
/**
|
|
1565
|
+
* Acquire a transaction-scoped (`pg_advisory_xact_lock`) exclusive advisory lock. Unlike
|
|
1566
|
+
* session-level advisory locks, xact-scoped locks are automatically released when this
|
|
1567
|
+
* transaction commits or rolls back - there is no explicit unlock call (Postgres does not
|
|
1568
|
+
* provide one; see the "Advisory Locks" section of the docs).
|
|
1569
|
+
*
|
|
1570
|
+
* Pass a single 64-bit key, or two 32-bit keys (`key`, `key2`) to use the two-argument form.
|
|
1571
|
+
*/
|
|
1572
|
+
advisoryXactLock(key: number | bigint, key2?: number): Promise<void>;
|
|
1573
|
+
/**
|
|
1574
|
+
* Attempt to acquire a transaction-scoped advisory lock without blocking
|
|
1575
|
+
* (`pg_try_advisory_xact_lock`). Returns `true` if the lock was acquired. The lock, if
|
|
1576
|
+
* acquired, is released automatically when this transaction commits or rolls back.
|
|
1577
|
+
*/
|
|
1578
|
+
tryAdvisoryXactLock(key: number | bigint, key2?: number): Promise<boolean>;
|
|
1579
|
+
}
|
|
1580
|
+
export interface PostgresDialectOptions extends DialectOptions {
|
|
1581
|
+
host?: string;
|
|
1582
|
+
port?: number;
|
|
1583
|
+
database?: string;
|
|
1584
|
+
username?: string;
|
|
1585
|
+
password?: string;
|
|
1586
|
+
ssl?: any;
|
|
1587
|
+
max?: number;
|
|
1588
|
+
idleTimeoutMillis?: number;
|
|
1589
|
+
connectionTimeoutMillis?: number;
|
|
1590
|
+
statementTimeout?: number;
|
|
1591
|
+
queryTimeout?: number;
|
|
1592
|
+
types?: any;
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Create a new PostgreSQL dialect instance
|
|
1596
|
+
*/
|
|
1597
|
+
export declare function createPostgresDialect(options?: PostgresDialectOptions): PostgresDialect;
|
|
1598
|
+
export default PostgresDialect;
|