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.
Files changed (460) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +194 -72
  3. package/dist/audit/history-query.d.ts +35 -0
  4. package/dist/audit/index.d.ts +16 -0
  5. package/dist/audit/logger.d.ts +126 -0
  6. package/dist/cache/cache-manager.d.ts +341 -0
  7. package/dist/cache/index.d.ts +8 -0
  8. package/dist/cache/redis-cluster-cache.d.ts +164 -0
  9. package/dist/cache/redis-cluster-cache.js +19 -36
  10. package/dist/cli/cloud.d.ts +55 -0
  11. package/dist/cli/cloud.js +318 -0
  12. package/dist/cli/commands/auth.d.ts +2 -0
  13. package/dist/cli/commands/auth.js +345 -0
  14. package/dist/cli/commands/billing.d.ts +2 -0
  15. package/dist/cli/commands/billing.js +135 -0
  16. package/dist/cli/commands/code.d.ts +2 -0
  17. package/dist/cli/commands/code.js +168 -0
  18. package/dist/cli/commands/config.d.ts +2 -0
  19. package/dist/cli/commands/config.js +154 -0
  20. package/dist/cli/commands/db.d.ts +2 -0
  21. package/dist/cli/commands/db.js +189 -0
  22. package/dist/cli/commands/index.d.ts +1 -0
  23. package/dist/cli/commands/index.js +22 -0
  24. package/dist/cli/commands/keys.d.ts +2 -0
  25. package/dist/cli/commands/keys.js +100 -0
  26. package/dist/cli/commands/misc.d.ts +2 -0
  27. package/dist/cli/commands/misc.js +282 -0
  28. package/dist/cli/commands/pull.d.ts +2 -0
  29. package/dist/cli/commands/pull.js +306 -0
  30. package/dist/cli/commands/runners.d.ts +2 -0
  31. package/dist/cli/commands/runners.js +218 -0
  32. package/dist/cli/commands/scaffold.d.ts +2 -0
  33. package/dist/cli/commands/scaffold.js +383 -0
  34. package/dist/cli/commands/secrets.d.ts +2 -0
  35. package/dist/cli/commands/secrets.js +162 -0
  36. package/dist/cli/commands/store.d.ts +2 -0
  37. package/dist/cli/commands/store.js +274 -0
  38. package/dist/cli/commands/system.d.ts +10 -0
  39. package/dist/cli/commands/system.js +169 -0
  40. package/dist/cli/commands/teams.d.ts +2 -0
  41. package/dist/cli/commands/teams.js +189 -0
  42. package/dist/cli/commands/user.d.ts +2 -0
  43. package/dist/cli/commands/user.js +171 -0
  44. package/dist/cli/framework.d.ts +103 -0
  45. package/dist/cli/framework.js +436 -0
  46. package/dist/cli/io.d.ts +26 -0
  47. package/dist/cli/io.js +181 -0
  48. package/dist/cli/keychain.d.ts +10 -0
  49. package/dist/cli/keychain.js +101 -0
  50. package/dist/cli/prompt.d.ts +20 -0
  51. package/dist/cli/prompt.js +111 -0
  52. package/dist/cli.d.ts +214 -0
  53. package/dist/cli.js +72 -5
  54. package/dist/compliance/audit-trail.d.ts +66 -0
  55. package/dist/compliance/backup-verification.d.ts +279 -0
  56. package/dist/compliance/breach-detector.d.ts +197 -0
  57. package/dist/compliance/consent-record.d.ts +107 -0
  58. package/dist/compliance/consent-versioning.d.ts +169 -0
  59. package/dist/compliance/cross-border-log.d.ts +254 -0
  60. package/dist/compliance/data-classifier.d.ts +127 -0
  61. package/dist/compliance/data-lineage.d.ts +268 -0
  62. package/dist/compliance/data-masker.d.ts +110 -0
  63. package/dist/compliance/data-portability.d.ts +98 -0
  64. package/dist/compliance/data-retention.d.ts +108 -0
  65. package/dist/compliance/dsar-workflow.d.ts +175 -0
  66. package/dist/compliance/field-encryption.d.ts +84 -0
  67. package/dist/compliance/immutable-record.d.ts +84 -0
  68. package/dist/compliance/index.d.ts +93 -0
  69. package/dist/compliance/privacy-impact-assessment.d.ts +196 -0
  70. package/dist/compliance/pseudonymization.d.ts +96 -0
  71. package/dist/compliance/query-firewall.d.ts +661 -0
  72. package/dist/compliance/rate-limiter.d.ts +203 -0
  73. package/dist/compliance/right-to-erasure.d.ts +96 -0
  74. package/dist/compliance/row-level-security.d.ts +152 -0
  75. package/dist/compliance/security-decorator.d.ts +388 -0
  76. package/dist/compliance/security-monitor.d.ts +170 -0
  77. package/dist/compliance/sensitive-data-discovery.d.ts +151 -0
  78. package/dist/compliance/session-isolation.d.ts +286 -0
  79. package/dist/compliance/tls-enforcer.d.ts +51 -0
  80. package/dist/compliance/worm-storage.d.ts +225 -0
  81. package/dist/connection-manager.d.ts +130 -0
  82. package/dist/connection-pool.d.ts +311 -0
  83. package/dist/decorators/audit.d.ts +49 -0
  84. package/dist/decorators/check.d.ts +218 -0
  85. package/dist/decorators/collate.d.ts +346 -0
  86. package/dist/decorators/comment.d.ts +51 -0
  87. package/dist/decorators/database-settings.d.ts +193 -0
  88. package/dist/decorators/default.d.ts +148 -0
  89. package/dist/decorators/encryption.d.ts +175 -0
  90. package/dist/decorators/engine.d.ts +97 -0
  91. package/dist/decorators/fk-constraints.d.ts +387 -0
  92. package/dist/decorators/foreign-table.d.ts +57 -0
  93. package/dist/decorators/generated.d.ts +232 -0
  94. package/dist/decorators/hstore.d.ts +96 -0
  95. package/dist/decorators/index.d.ts +57 -0
  96. package/dist/decorators/index.js +14 -30
  97. package/dist/decorators/json-column.d.ts +47 -0
  98. package/dist/decorators/jsonb.d.ts +83 -0
  99. package/dist/decorators/orm-decorators.d.ts +274 -0
  100. package/dist/decorators/permissions.d.ts +192 -0
  101. package/dist/decorators/procedure.d.ts +168 -0
  102. package/dist/decorators/procedure.js +31 -7
  103. package/dist/decorators/query-options.d.ts +527 -0
  104. package/dist/decorators/range.d.ts +122 -0
  105. package/dist/decorators/set-column.d.ts +43 -0
  106. package/dist/decorators/spatial.d.ts +60 -0
  107. package/dist/decorators/storage.d.ts +561 -0
  108. package/dist/decorators/timezone.d.ts +319 -0
  109. package/dist/decorators/trigger.d.ts +50 -0
  110. package/dist/decorators/uuid.d.ts +102 -0
  111. package/dist/decorators/view.d.ts +213 -0
  112. package/dist/diagrams/chen-diagram.d.ts +70 -0
  113. package/dist/diagrams/chen-diagram.js +33 -31
  114. package/dist/diagrams/class-diagram.d.ts +78 -0
  115. package/dist/diagrams/class-diagram.js +23 -27
  116. package/dist/diagrams/dependency-diagram.d.ts +82 -0
  117. package/dist/diagrams/dependency-diagram.js +18 -9
  118. package/dist/diagrams/er-diagram.d.ts +82 -0
  119. package/dist/diagrams/er-diagram.js +174 -231
  120. package/dist/diagrams/flow-diagram.d.ts +70 -0
  121. package/dist/diagrams/flow-diagram.js +23 -18
  122. package/dist/diagrams/gantt-diagram.d.ts +67 -0
  123. package/dist/diagrams/gantt-diagram.js +20 -18
  124. package/dist/diagrams/index-diagram.d.ts +61 -0
  125. package/dist/diagrams/index-diagram.js +36 -31
  126. package/dist/diagrams/index.d.ts +155 -0
  127. package/dist/diagrams/index.js +7 -1
  128. package/dist/diagrams/migration-diagram.d.ts +67 -0
  129. package/dist/diagrams/migration-diagram.js +45 -57
  130. package/dist/diagrams/model-diagram.d.ts +85 -0
  131. package/dist/diagrams/model-diagram.js +225 -287
  132. package/dist/diagrams/package-diagram.d.ts +69 -0
  133. package/dist/diagrams/package-diagram.js +30 -32
  134. package/dist/diagrams/palette.d.ts +138 -0
  135. package/dist/diagrams/palette.js +134 -25
  136. package/dist/diagrams/relational-diagram.d.ts +82 -0
  137. package/dist/diagrams/relational-diagram.js +51 -59
  138. package/dist/diagrams/schemadoc-diagram.d.ts +57 -0
  139. package/dist/diagrams/schemadoc-diagram.js +36 -28
  140. package/dist/diagrams/sequence-diagram.d.ts +61 -0
  141. package/dist/diagrams/sequence-diagram.js +20 -11
  142. package/dist/diagrams/state-diagram.d.ts +85 -0
  143. package/dist/diagrams/state-diagram.js +21 -17
  144. package/dist/diagrams/svg-dom.d.ts +62 -0
  145. package/dist/diagrams/svg-dom.js +11 -0
  146. package/dist/diagrams/tree-diagram.d.ts +47 -0
  147. package/dist/diagrams/tree-diagram.js +19 -10
  148. package/dist/dialects/clickhouse/index.d.ts +660 -0
  149. package/dist/dialects/clickhouse/index.js +107 -2
  150. package/dist/dialects/cockroachdb/index.d.ts +1708 -0
  151. package/dist/dialects/cockroachdb/index.js +139 -10
  152. package/dist/dialects/cratedb/index.d.ts +262 -0
  153. package/dist/dialects/cratedb/index.js +148 -0
  154. package/dist/dialects/databricks/index.d.ts +397 -0
  155. package/dist/dialects/databricks/index.js +233 -11
  156. package/dist/dialects/db2/index.d.ts +729 -0
  157. package/dist/dialects/db2/index.js +152 -2
  158. package/dist/dialects/dialect.d.ts +1653 -0
  159. package/dist/dialects/duckdb/index.d.ts +440 -0
  160. package/dist/dialects/duckdb/index.js +21 -37
  161. package/dist/dialects/exasol/index.d.ts +197 -0
  162. package/dist/dialects/exasol/index.js +14 -0
  163. package/dist/dialects/firebird/index.d.ts +286 -0
  164. package/dist/dialects/firebird/index.js +135 -0
  165. package/dist/dialects/greenplum/index.d.ts +336 -0
  166. package/dist/dialects/greenplum/index.js +168 -0
  167. package/dist/dialects/hana/index.d.ts +512 -0
  168. package/dist/dialects/hana/index.js +17 -35
  169. package/dist/dialects/mariadb/index.d.ts +1241 -0
  170. package/dist/dialects/mariadb/index.js +181 -43
  171. package/dist/dialects/mssql/index.d.ts +729 -0
  172. package/dist/dialects/mssql/index.js +76 -7
  173. package/dist/dialects/mysql/index.d.ts +1233 -0
  174. package/dist/dialects/mysql/index.js +87 -19
  175. package/dist/dialects/oracle/index.d.ts +1222 -0
  176. package/dist/dialects/oracle/index.js +210 -9
  177. package/dist/dialects/postgres/index.d.ts +1598 -0
  178. package/dist/dialects/postgres/index.js +34 -13
  179. package/dist/dialects/query-stream-helper.d.ts +58 -0
  180. package/dist/dialects/questdb/index.d.ts +430 -0
  181. package/dist/dialects/questdb/index.js +292 -0
  182. package/dist/dialects/redshift/index.d.ts +933 -0
  183. package/dist/dialects/redshift/index.js +17 -5
  184. package/dist/dialects/singlestore/index.d.ts +233 -0
  185. package/dist/dialects/singlestore/index.js +53 -0
  186. package/dist/dialects/snowflake/index.d.ts +727 -0
  187. package/dist/dialects/snowflake/index.js +154 -5
  188. package/dist/dialects/spanner/index.d.ts +660 -0
  189. package/dist/dialects/spanner/index.js +43 -21
  190. package/dist/dialects/sqlite/index.d.ts +1133 -0
  191. package/dist/dialects/sqlite/index.js +168 -30
  192. package/dist/dialects/tidb/index.d.ts +226 -0
  193. package/dist/dialects/tidb/index.js +10 -0
  194. package/dist/dialects/timescaledb/index.d.ts +286 -0
  195. package/dist/dialects/timescaledb/index.js +179 -0
  196. package/dist/dialects/trino/index.d.ts +230 -0
  197. package/dist/dialects/trino/index.js +85 -10
  198. package/dist/dialects/turso/index.d.ts +98 -0
  199. package/dist/dialects/turso/index.js +10 -0
  200. package/dist/dialects/vertica/index.d.ts +321 -0
  201. package/dist/dialects/vertica/index.js +161 -0
  202. package/dist/dialects/yugabytedb/index.d.ts +276 -0
  203. package/dist/dialects/yugabytedb/index.js +121 -0
  204. package/dist/errors/index.d.ts +378 -0
  205. package/dist/errors/index.js +29 -1
  206. package/dist/errors/utils.d.ts +53 -0
  207. package/dist/errors.d.ts +5 -0
  208. package/dist/extensions/catalog/cloud-warehouse-features.d.ts +27 -0
  209. package/dist/extensions/catalog/mssql-features.d.ts +20 -0
  210. package/dist/extensions/catalog/mysql-mariadb-plugins.d.ts +18 -0
  211. package/dist/extensions/catalog/oracle-db2-features.d.ts +17 -0
  212. package/dist/extensions/catalog/postgres-extensions.d.ts +15 -0
  213. package/dist/extensions/index.d.ts +34 -0
  214. package/dist/extensions/types.d.ts +43 -0
  215. package/dist/external-fields/adapters.d.ts +50 -0
  216. package/dist/external-fields/adapters.js +227 -0
  217. package/dist/external-fields/decorator.d.ts +77 -0
  218. package/dist/external-fields/decorator.js +80 -0
  219. package/dist/external-fields/index.d.ts +10 -0
  220. package/dist/external-fields/index.js +19 -0
  221. package/dist/external-fields/runtime.d.ts +39 -0
  222. package/dist/external-fields/runtime.js +221 -0
  223. package/dist/foreign-data.d.ts +168 -0
  224. package/dist/graph/base-graph-dialect.d.ts +250 -0
  225. package/dist/graph/base-graph-dialect.js +539 -0
  226. package/dist/graph/dgraph/index.d.ts +65 -0
  227. package/dist/graph/dgraph/index.js +559 -0
  228. package/dist/graph/gremlin/index.d.ts +59 -0
  229. package/dist/graph/gremlin/index.js +378 -0
  230. package/dist/graph/index.d.ts +60 -0
  231. package/dist/graph/index.js +67 -0
  232. package/dist/graph/neo4j/index.d.ts +50 -0
  233. package/dist/graph/neo4j/index.js +462 -0
  234. package/dist/graph/types.d.ts +213 -0
  235. package/dist/graph/types.js +234 -0
  236. package/dist/hooks/hooks-manager.d.ts +189 -0
  237. package/dist/hooks/index.d.ts +8 -0
  238. package/dist/index.d.ts +713 -0
  239. package/dist/index.js +36 -4
  240. package/dist/logging.d.ts +183 -0
  241. package/dist/migrations/index.d.ts +9 -0
  242. package/dist/migrations/migration.d.ts +143 -0
  243. package/dist/migrations/migrator.d.ts +199 -0
  244. package/dist/migrations/prormmigration.d.ts +131 -0
  245. package/dist/migrations/query-interface.d.ts +335 -0
  246. package/dist/migrations/seeder.d.ts +167 -0
  247. package/dist/models/associations.d.ts +131 -0
  248. package/dist/models/associations.js +7 -2
  249. package/dist/models/constraints.d.ts +175 -0
  250. package/dist/models/data-types.d.ts +1656 -0
  251. package/dist/models/decorators.d.ts +328 -0
  252. package/dist/models/decorators.js +61 -82
  253. package/dist/models/eager-load.d.ts +86 -0
  254. package/dist/models/eager-load.js +369 -0
  255. package/dist/models/index.d.ts +13 -0
  256. package/dist/models/indexes.d.ts +325 -0
  257. package/dist/models/methods.d.ts +419 -0
  258. package/dist/models/model-manager.d.ts +76 -0
  259. package/dist/models/model.d.ts +820 -0
  260. package/dist/models/model.js +15 -101
  261. package/dist/models/operators.d.ts +29 -0
  262. package/dist/models/scopes.d.ts +71 -0
  263. package/dist/models/typescript-types.d.ts +177 -0
  264. package/dist/nosql/aerospike/index.d.ts +126 -0
  265. package/dist/nosql/allegrograph/index.d.ts +86 -0
  266. package/dist/nosql/arangodb/index.d.ts +285 -0
  267. package/dist/nosql/arangodb/index.js +274 -2
  268. package/dist/nosql/arangodb/where.d.ts +38 -0
  269. package/dist/nosql/arangodb/where.js +94 -0
  270. package/dist/nosql/azure-blob/index.d.ts +104 -0
  271. package/dist/nosql/beanstalkd/index.d.ts +88 -0
  272. package/dist/nosql/beequeue/index.d.ts +99 -0
  273. package/dist/nosql/bigchaindb/index.d.ts +113 -0
  274. package/dist/nosql/bigtable/index.d.ts +144 -0
  275. package/dist/nosql/blazegraph/index.d.ts +88 -0
  276. package/dist/nosql/bullmq/index.d.ts +83 -0
  277. package/dist/nosql/cassandra/index.d.ts +119 -0
  278. package/dist/nosql/chroma/index.d.ts +151 -0
  279. package/dist/nosql/cloudflare-kv/index.d.ts +120 -0
  280. package/dist/nosql/coherence/index.d.ts +91 -0
  281. package/dist/nosql/cosmosdb/index.d.ts +78 -0
  282. package/dist/nosql/couchbase/index.d.ts +103 -0
  283. package/dist/nosql/dax/index.d.ts +118 -0
  284. package/dist/nosql/deno-kv/index.d.ts +109 -0
  285. package/dist/nosql/dgraph/index.d.ts +80 -0
  286. package/dist/nosql/doris/index.d.ts +88 -0
  287. package/dist/nosql/druid/index.d.ts +95 -0
  288. package/dist/nosql/dynamodb/index.d.ts +643 -0
  289. package/dist/nosql/dynamodb/index.js +423 -0
  290. package/dist/nosql/elasticsearch/index.d.ts +239 -0
  291. package/dist/nosql/etcd/index.d.ts +243 -0
  292. package/dist/nosql/eventhubs/index.d.ts +89 -0
  293. package/dist/nosql/eventstore/index.d.ts +102 -0
  294. package/dist/nosql/faunadb/index.d.ts +141 -0
  295. package/dist/nosql/faunadb/index.js +329 -0
  296. package/dist/nosql/firestore/index.d.ts +67 -0
  297. package/dist/nosql/fluree/index.d.ts +88 -0
  298. package/dist/nosql/fuseki/index.d.ts +94 -0
  299. package/dist/nosql/gcs/index.d.ts +62 -0
  300. package/dist/nosql/gearman/index.d.ts +77 -0
  301. package/dist/nosql/geode/index.d.ts +93 -0
  302. package/dist/nosql/graphdb/index.d.ts +86 -0
  303. package/dist/nosql/graylog/index.d.ts +118 -0
  304. package/dist/nosql/gridgain/index.d.ts +78 -0
  305. package/dist/nosql/hazelcast/index.d.ts +73 -0
  306. package/dist/nosql/hbase/index.d.ts +123 -0
  307. package/dist/nosql/ignite/index.d.ts +80 -0
  308. package/dist/nosql/immudb/index.d.ts +131 -0
  309. package/dist/nosql/index.d.ts +215 -0
  310. package/dist/nosql/infinispan/index.d.ts +95 -0
  311. package/dist/nosql/influxdb/flux-compiler.d.ts +23 -0
  312. package/dist/nosql/influxdb/flux-compiler.js +170 -0
  313. package/dist/nosql/influxdb/index.d.ts +300 -0
  314. package/dist/nosql/influxdb/index.js +0 -0
  315. package/dist/nosql/kafka/index.d.ts +113 -0
  316. package/dist/nosql/keyspaces/index.d.ts +122 -0
  317. package/dist/nosql/kinesis/index.d.ts +121 -0
  318. package/dist/nosql/leveldb/index.d.ts +112 -0
  319. package/dist/nosql/leveldb/index.js +103 -1
  320. package/dist/nosql/lmdb/index.d.ts +76 -0
  321. package/dist/nosql/loki/index.d.ts +126 -0
  322. package/dist/nosql/marklogic/index.d.ts +76 -0
  323. package/dist/nosql/materialize/index.d.ts +91 -0
  324. package/dist/nosql/meilisearch/index.d.ts +76 -0
  325. package/dist/nosql/memcached/index.d.ts +138 -0
  326. package/dist/nosql/milvus/index.d.ts +167 -0
  327. package/dist/nosql/minio/index.d.ts +122 -0
  328. package/dist/nosql/momento/index.d.ts +99 -0
  329. package/dist/nosql/mongodb/index.d.ts +265 -0
  330. package/dist/nosql/mongodb/index.js +139 -0
  331. package/dist/nosql/mongodb/where.d.ts +8 -0
  332. package/dist/nosql/mongodb/where.js +181 -0
  333. package/dist/nosql/nats/index.d.ts +139 -0
  334. package/dist/nosql/nedb/index.d.ts +79 -0
  335. package/dist/nosql/neo4j/index.d.ts +217 -0
  336. package/dist/nosql/neo4j/index.js +26 -14
  337. package/dist/nosql/neptune/index.d.ts +234 -0
  338. package/dist/nosql/neptune/index.js +23 -9
  339. package/dist/nosql/nsq/index.d.ts +93 -0
  340. package/dist/nosql/opensearch/index.d.ts +97 -0
  341. package/dist/nosql/orientdb/index.d.ts +72 -0
  342. package/dist/nosql/papertrail/index.d.ts +120 -0
  343. package/dist/nosql/pinecone/index.d.ts +148 -0
  344. package/dist/nosql/pinot/index.d.ts +90 -0
  345. package/dist/nosql/pouchdb/index.d.ts +95 -0
  346. package/dist/nosql/prometheus/index.d.ts +112 -0
  347. package/dist/nosql/provendb/index.d.ts +143 -0
  348. package/dist/nosql/provendb/index.js +262 -0
  349. package/dist/nosql/pubsub/index.d.ts +83 -0
  350. package/dist/nosql/pulsar/index.d.ts +105 -0
  351. package/dist/nosql/qdrant/index.d.ts +231 -0
  352. package/dist/nosql/qldb/index.d.ts +182 -0
  353. package/dist/nosql/qldb/index.js +302 -1
  354. package/dist/nosql/r2/index.d.ts +160 -0
  355. package/dist/nosql/rabbitmq/index.d.ts +131 -0
  356. package/dist/nosql/ravendb/index.d.ts +138 -0
  357. package/dist/nosql/ravendb/index.js +323 -9
  358. package/dist/nosql/ravendb/where.d.ts +38 -0
  359. package/dist/nosql/ravendb/where.js +94 -0
  360. package/dist/nosql/redis/index.d.ts +267 -0
  361. package/dist/nosql/redis/index.js +19 -5
  362. package/dist/nosql/redpanda/index.d.ts +117 -0
  363. package/dist/nosql/resque/index.d.ts +91 -0
  364. package/dist/nosql/rethinkdb/index.d.ts +194 -0
  365. package/dist/nosql/rethinkdb/index.js +290 -0
  366. package/dist/nosql/rethinkdb/where.d.ts +38 -0
  367. package/dist/nosql/rethinkdb/where.js +94 -0
  368. package/dist/nosql/rocksdb/document-layer.d.ts +162 -0
  369. package/dist/nosql/rocksdb/document-layer.js +338 -0
  370. package/dist/nosql/rocksdb/index.d.ts +112 -0
  371. package/dist/nosql/rocksdb/index.js +103 -1
  372. package/dist/nosql/rocksdb/where-match.d.ts +21 -0
  373. package/dist/nosql/rocksdb/where-match.js +238 -0
  374. package/dist/nosql/rockset/index.d.ts +84 -0
  375. package/dist/nosql/s3/index.d.ts +170 -0
  376. package/dist/nosql/scylladb/index.d.ts +117 -0
  377. package/dist/nosql/signoz/index.d.ts +116 -0
  378. package/dist/nosql/sns/index.d.ts +99 -0
  379. package/dist/nosql/solr/index.d.ts +129 -0
  380. package/dist/nosql/splunk/index.d.ts +125 -0
  381. package/dist/nosql/sqs/index.d.ts +116 -0
  382. package/dist/nosql/stardog/index.d.ts +86 -0
  383. package/dist/nosql/starrocks/index.d.ts +89 -0
  384. package/dist/nosql/store.d.ts +23 -0
  385. package/dist/nosql/sumologic/index.d.ts +119 -0
  386. package/dist/nosql/surrealdb/index.d.ts +156 -0
  387. package/dist/nosql/surrealdb/index.js +174 -1
  388. package/dist/nosql/surrealdb/query-compiler.d.ts +26 -0
  389. package/dist/nosql/surrealdb/query-compiler.js +193 -0
  390. package/dist/nosql/terminusdb/index.d.ts +95 -0
  391. package/dist/nosql/tigergraph/index.d.ts +314 -0
  392. package/dist/nosql/typesense/index.d.ts +82 -0
  393. package/dist/nosql/unqlite/index.d.ts +68 -0
  394. package/dist/nosql/upstash/index.d.ts +80 -0
  395. package/dist/nosql/vercel-kv/index.d.ts +82 -0
  396. package/dist/nosql/victoriametrics/index.d.ts +129 -0
  397. package/dist/nosql/virtuoso/index.d.ts +87 -0
  398. package/dist/nosql/weaviate/index.d.ts +196 -0
  399. package/dist/operators/index.d.ts +7 -0
  400. package/dist/operators.d.ts +2947 -0
  401. package/dist/operators.js +46 -1
  402. package/dist/prisma-migrate/index.d.ts +28 -0
  403. package/dist/prisma-migrate/migration-generator.d.ts +21 -0
  404. package/dist/prisma-migrate/model-generator.d.ts +12 -0
  405. package/dist/prisma-migrate/relations.d.ts +28 -0
  406. package/dist/prisma-migrate/schema-parser.d.ts +42 -0
  407. package/dist/prisma-migrate/type-mapper.d.ts +20 -0
  408. package/dist/prorm.d.ts +2093 -0
  409. package/dist/prorm.js +721 -302
  410. package/dist/query-builders/cte-builder.d.ts +104 -0
  411. package/dist/query-builders/functions/aggregate.d.ts +199 -0
  412. package/dist/query-builders/functions/conditional.d.ts +195 -0
  413. package/dist/query-builders/functions/datetime.d.ts +202 -0
  414. package/dist/query-builders/functions/fulltext.d.ts +220 -0
  415. package/dist/query-builders/functions/index.d.ts +17 -0
  416. package/dist/query-builders/functions/json.d.ts +157 -0
  417. package/dist/query-builders/functions/math.d.ts +215 -0
  418. package/dist/query-builders/functions/string.d.ts +233 -0
  419. package/dist/query-builders/functions/window.d.ts +209 -0
  420. package/dist/query-builders/include-builder.d.ts +85 -0
  421. package/dist/query-builders/index-expression-builder.d.ts +153 -0
  422. package/dist/query-builders/index.d.ts +121 -0
  423. package/dist/query-builders/index.js +10 -0
  424. package/dist/query-builders/insert-builder.d.ts +62 -0
  425. package/dist/query-builders/model-helpers.d.ts +28 -0
  426. package/dist/query-builders/order-limit-builder.d.ts +84 -0
  427. package/dist/query-builders/sql-compiler.d.ts +562 -0
  428. package/dist/query-builders/subquery-builder.d.ts +133 -0
  429. package/dist/query-builders/update-builder.d.ts +71 -0
  430. package/dist/query-builders/view-builder.d.ts +189 -0
  431. package/dist/query-builders/where-builder.d.ts +124 -0
  432. package/dist/query-interface.d.ts +407 -0
  433. package/dist/query-interface.js +84 -0
  434. package/dist/query-optimizers/batch-optimizer.d.ts +175 -0
  435. package/dist/query-optimizers/explain-plans.d.ts +187 -0
  436. package/dist/query-optimizers/index.d.ts +27 -0
  437. package/dist/query-optimizers/prepared-statement-cache.d.ts +252 -0
  438. package/dist/query-optimizers/query-hints.d.ts +201 -0
  439. package/dist/query-optimizers/query-optimizer.d.ts +162 -0
  440. package/dist/query-optimizers/slow-query-logger.d.ts +186 -0
  441. package/dist/replica-manager.d.ts +235 -0
  442. package/dist/schema/index.d.ts +7 -0
  443. package/dist/schema/migration-generator.d.ts +74 -0
  444. package/dist/schema/schema-differ.d.ts +114 -0
  445. package/dist/schema/types.d.ts +246 -0
  446. package/dist/schema-objects.d.ts +78 -0
  447. package/dist/schema-objects.js +203 -0
  448. package/dist/sql-constants.d.ts +240 -0
  449. package/dist/sqlite-advanced.d.ts +572 -0
  450. package/dist/streams/index.d.ts +5 -0
  451. package/dist/streams/transforms.d.ts +120 -0
  452. package/dist/transaction.d.ts +221 -0
  453. package/dist/types/index.d.ts +3123 -0
  454. package/dist/user-management.d.ts +141 -0
  455. package/dist/utils/date.d.ts +149 -0
  456. package/dist/utils/index.d.ts +359 -0
  457. package/dist/utils/string.d.ts +88 -0
  458. package/dist/validators/index.d.ts +7 -0
  459. package/dist/validators/validator.d.ts +306 -0
  460. package/package.json +20 -5
@@ -0,0 +1,1708 @@
1
+ /**
2
+ * CockroachDB dialect implementation for the TypeScript ORM
3
+ *
4
+ * CockroachDB speaks the CockroachDB wire protocol and is largely SQL-compatible
5
+ * with CockroachDB, so this dialect reuses the `pg` driver (same as the Postgres
6
+ * dialect) and mirrors most of its query-building behavior. Notable differences
7
+ * from the Postgres dialect:
8
+ *
9
+ * - Default port is 26257 (not 5432).
10
+ * - showTables/describeTable/showIndexes/showConstraints prefer CockroachDB's
11
+ * `SHOW TABLES` / `SHOW COLUMNS FROM` / `SHOW INDEXES FROM` / `SHOW CONSTRAINTS FROM`
12
+ * statements instead of querying information_schema/pg_catalog directly.
13
+ * - `CREATE INDEX ... CONCURRENTLY` is not supported (and not needed) in CockroachDB
14
+ * because index creation is online/non-blocking by default; the `concurrently`
15
+ * option is ignored with a warning instead of being emitted in the SQL.
16
+ * - Interleaved tables (CockroachDB's now-deprecated `INTERLEAVE IN PARENT` syntax)
17
+ * are intentionally NOT implemented.
18
+ * - SERIAL/BIGSERIAL auto-increment columns are kept for parity with the Postgres
19
+ * dialect; CockroachDB accepts these as a Postgres-compatibility shorthand that
20
+ * maps to an implicit sequence internally (CockroachDB's default unique ID
21
+ * generation otherwise uses `unique_rowid()`).
22
+ * - `buildUpsertQuery`/`buildInsertQuery` default to Postgres-style `ON CONFLICT
23
+ * ... DO UPDATE` for consistency with the Postgres dialect's style, but
24
+ * accept a `nativeUpsert` option to opt into CockroachDB's native
25
+ * `UPSERT INTO ... VALUES (...)` shorthand, which replaces the whole row
26
+ * without requiring a conflict target.
27
+ * - Adds `isRetryableError()` to detect CockroachDB's serialization failure
28
+ * SQLSTATE (40001), which requires the client to retry the transaction.
29
+ * `runTransaction()` uses it to implement CockroachDB's client-side
30
+ * transaction retry loop (`SAVEPOINT cockroach_restart`), and it's also
31
+ * folded into the default query-retry match lists so single-statement
32
+ * retries cover it too.
33
+ */
34
+ import type { Pool, PoolClient } from 'pg';
35
+ import { Dialect, DialectOptions, ColumnDefinition, TableOptions, DropTableOptions, TableDescription, IndexOptions, InsertOptions, UpdateOptions as DUpdateOptions, DeleteOptions, SelectOptions, UpsertQueryOptions, CreateExtensionOptions, DropExtensionOptions, ExtensionInfo, FdwForeignServerOptions, FdwAlterForeignServerOptions, FdwUserMappingOptions, FdwForeignTableOptions, FdwImportForeignSchemaOptions, ViewOptions, DropViewOptions, DropSchemaOptions, MaterializedViewOptions, RefreshOptions, DropMaterializedViewOptions } from '../dialect';
36
+ import { Transaction, TransactionOptions, QueryResult, QueryOptions, StreamOptions, DataType, WhereOptions, Order, PartitionDefinition, CreatePartitionOptions, AttachPartitionOptions, DetachPartitionOptions, StoredProcedureOptions, DropStoredProcedureOptions, ExecuteStoredProcedureOptions, FunctionOptions, DropFunctionOptions, TriggerOptions, DropTriggerOptions, SequenceOptions, DropSequenceOptions, PolicyOptions, DropPolicyOptions } from '../../types';
37
+ /**
38
+ * CockroachDB-specific hash-sharded index options. Not part of the shared
39
+ * `IndexOptions` type (which is used by every dialect), so callers targeting
40
+ * CockroachDB can pass these alongside the common options via an
41
+ * intersection type.
42
+ *
43
+ * @see https://www.cockroachlabs.com/docs/stable/hash-sharded-indexes
44
+ */
45
+ export interface CockroachHashShardedIndexOptions {
46
+ /** Number of buckets to shard the index into (CockroachDB `USING HASH WITH (bucket_count = N)`) */
47
+ bucketCount?: number;
48
+ /** Alias for `bucketCount` */
49
+ shard?: number;
50
+ }
51
+ /**
52
+ * CockroachDB multi-region table locality setting
53
+ * (`ALTER TABLE ... SET LOCALITY ...` / `CREATE TABLE ... LOCALITY ...`).
54
+ *
55
+ * Only meaningful for multi-region databases (i.e. databases that have had
56
+ * at least one region added via `ADD REGION`/`SET PRIMARY REGION`).
57
+ *
58
+ * @see https://www.cockroachlabs.com/docs/stable/table-localities
59
+ */
60
+ export type CockroachLocality = {
61
+ type: 'global';
62
+ } | {
63
+ type: 'regional-by-table';
64
+ region?: string;
65
+ } | {
66
+ type: 'regional-by-row';
67
+ column?: string;
68
+ };
69
+ /**
70
+ * CockroachDB-specific table options: multi-region `LOCALITY` and column
71
+ * `FAMILY` grouping. Not part of the shared `TableOptions` type (which is
72
+ * used by every dialect), so callers targeting CockroachDB pass these
73
+ * alongside the common options via an intersection type.
74
+ */
75
+ export interface CockroachTableOptions {
76
+ /** Multi-region table locality (`REGIONAL BY TABLE` / `REGIONAL BY ROW` / `GLOBAL`) */
77
+ locality?: CockroachLocality;
78
+ /** Column family groupings (CockroachDB storage-layout hint): `FAMILY name (col1, col2)` */
79
+ families?: {
80
+ name?: string;
81
+ columns: string[];
82
+ }[];
83
+ }
84
+ /**
85
+ * Options for `configureZone()` (`ALTER ... CONFIGURE ZONE USING ...`).
86
+ * Mirrors the subset of CockroachDB zone-configuration replication
87
+ * variables that are reasonable for an ORM to expose.
88
+ *
89
+ * @see https://www.cockroachlabs.com/docs/stable/configure-zone
90
+ */
91
+ export interface CockroachZoneConfigOptions {
92
+ /** Number of replicas to maintain for ranges covered by this zone (`num_replicas`) */
93
+ numReplicas?: number;
94
+ /** Constraints on which nodes/localities may hold replicas (`constraints`), e.g. `'[+region=us-east1]'` */
95
+ constraints?: string;
96
+ /** Ordered lease-preference tiers (`lease_preferences`), e.g. `['[+region=us-east1]']` */
97
+ leasePreferences?: string[];
98
+ /** Garbage-collection TTL in seconds for MVCC versions (`gc.ttlseconds`) */
99
+ gcTtlSeconds?: number;
100
+ /** Minimum range size in bytes before CockroachDB tries to merge ranges (`range_min_bytes`) */
101
+ rangeMinBytes?: number;
102
+ /** Maximum range size in bytes before CockroachDB splits a range (`range_max_bytes`) */
103
+ rangeMaxBytes?: number;
104
+ /** Number of voting replicas (`num_voters`), for use with non-voting replicas */
105
+ numVoters?: number;
106
+ }
107
+ /** Target of a `CONFIGURE ZONE` / `SPLIT AT` / `UNSPLIT AT` statement. */
108
+ export type CockroachZoneTarget = {
109
+ kind: 'table';
110
+ name: string;
111
+ } | {
112
+ kind: 'index';
113
+ table: string;
114
+ index: string;
115
+ } | {
116
+ kind: 'partition';
117
+ name: string;
118
+ table: string;
119
+ index?: string;
120
+ } | {
121
+ kind: 'database';
122
+ name: string;
123
+ };
124
+ /**
125
+ * CockroachDB-specific insert option: opt into the native `UPSERT INTO`
126
+ * shorthand. Not part of the shared `InsertOptions` type (which is used by
127
+ * every dialect), so callers targeting CockroachDB pass `nativeUpsert`
128
+ * alongside the common options via this extended type.
129
+ *
130
+ * @see https://www.cockroachlabs.com/docs/stable/upsert
131
+ */
132
+ export interface CockroachInsertOptions extends InsertOptions {
133
+ /**
134
+ * When true (and `upsert` is also true), emit CockroachDB's native
135
+ * `UPSERT INTO t (...) VALUES (...)` statement instead of
136
+ * `INSERT ... ON CONFLICT ... DO UPDATE`. Native `UPSERT` replaces the row
137
+ * matching the table's primary key wholesale and does not require (or
138
+ * accept) a conflict target, so `conflictFields` is ignored when this is
139
+ * set.
140
+ * @default false
141
+ */
142
+ nativeUpsert?: boolean;
143
+ }
144
+ /**
145
+ * CockroachDB-specific upsert option: opt into the native `UPSERT INTO`
146
+ * shorthand. Not part of the shared `UpsertQueryOptions` type (which is used
147
+ * by every dialect), so callers targeting CockroachDB pass `nativeUpsert`
148
+ * alongside the common options via this extended type.
149
+ *
150
+ * @see https://www.cockroachlabs.com/docs/stable/upsert
151
+ */
152
+ export interface CockroachUpsertQueryOptions extends UpsertQueryOptions {
153
+ /**
154
+ * When true, emit CockroachDB's native `UPSERT INTO t (...) VALUES (...)`
155
+ * statement instead of `INSERT ... ON CONFLICT ... DO UPDATE`. Native
156
+ * `UPSERT` replaces the row matching the table's primary key wholesale and
157
+ * does not require (or accept) a conflict target, so `conflictFields` and
158
+ * `updateOnDuplicate` are ignored when this is set.
159
+ * @default false
160
+ */
161
+ nativeUpsert?: boolean;
162
+ }
163
+ /**
164
+ * Options for {@link CockroachDBDialect.runTransaction}. Not part of the
165
+ * shared `TransactionOptions` type (which is used by every dialect), so
166
+ * callers targeting CockroachDB pass `maxRetries` alongside the common
167
+ * transaction options via this extended type.
168
+ */
169
+ export interface CockroachRunTransactionOptions extends TransactionOptions {
170
+ /**
171
+ * Maximum number of times to retry the transaction body after a
172
+ * serialization failure (SQLSTATE `40001` / "restart transaction") before
173
+ * giving up and rethrowing the error.
174
+ * @default 5
175
+ */
176
+ maxRetries?: number;
177
+ /**
178
+ * CockroachDB transaction priority (`SET TRANSACTION PRIORITY LOW|NORMAL|HIGH`).
179
+ * Higher-priority transactions are less likely to be aborted when they
180
+ * conflict with concurrent transactions, which reduces retry churn for known
181
+ * hot/critical transactions. Applied right after `BEGIN`.
182
+ * @see https://www.cockroachlabs.com/docs/stable/transactions#transaction-priorities
183
+ */
184
+ priority?: CockroachTransactionPriority;
185
+ }
186
+ /**
187
+ * CockroachDB transaction priority level for
188
+ * `SET TRANSACTION PRIORITY {LOW|NORMAL|HIGH}`.
189
+ */
190
+ export type CockroachTransactionPriority = 'LOW' | 'NORMAL' | 'HIGH';
191
+ /**
192
+ * CockroachDB dialect class that implements the Dialect interface
193
+ */
194
+ export declare class CockroachDBDialect implements Dialect {
195
+ readonly name = "cockroachdb";
196
+ readonly library = "pg";
197
+ private pool;
198
+ private _isConnected;
199
+ private config;
200
+ private transactionDepth;
201
+ constructor(config: CockroachDBDialectOptions);
202
+ /**
203
+ * Determine whether an error is retryable, i.e. whether the client should
204
+ * retry the transaction that produced it.
205
+ *
206
+ * CockroachDB uses SQLSTATE 40001 ("serialization_failure", surfaced as the
207
+ * "restart transaction" error) to signal that a transaction could not be
208
+ * committed due to a conflict with a concurrent transaction under
209
+ * SERIALIZABLE isolation, and that the client should retry it from the
210
+ * beginning. See: https://www.cockroachlabs.com/docs/stable/transaction-retry-error-reference
211
+ *
212
+ * @param error - The error to check (expected to expose a `.code` property,
213
+ * as errors from the `pg` driver do).
214
+ * @returns True if the error's SQLSTATE is 40001.
215
+ */
216
+ isRetryableError(error: any): boolean;
217
+ /**
218
+ * Connect to the CockroachDB database
219
+ */
220
+ connect(): Promise<void>;
221
+ /**
222
+ * Disconnect from the CockroachDB database
223
+ */
224
+ disconnect(): Promise<void>;
225
+ /**
226
+ * Get the current connection pool
227
+ */
228
+ getConnection(): Pool | null;
229
+ /**
230
+ * Check if connected
231
+ */
232
+ isConnected(): boolean;
233
+ /**
234
+ * Execute a raw SQL query with retry support
235
+ */
236
+ query(sql: string, options?: QueryOptions): Promise<QueryResult>;
237
+ /**
238
+ * Execute a query and stream results using CockroachDB cursor
239
+ * Uses server-side cursors for efficient memory usage with large datasets
240
+ * @param sql - The SQL query string
241
+ * @param options - Stream options
242
+ * @returns Readable stream for streaming results
243
+ */
244
+ queryStream(sql: string, options?: StreamOptions): import('stream').Readable;
245
+ /**
246
+ * Execute a function with retry logic for query execution
247
+ */
248
+ private executeWithRetry;
249
+ /**
250
+ * Escape a value for use in a query
251
+ */
252
+ escape(value: unknown): string;
253
+ /**
254
+ * Escape a string for SQL
255
+ */
256
+ private escapeString;
257
+ /**
258
+ * Format a date for CockroachDB
259
+ */
260
+ private formatDate;
261
+ /**
262
+ * Escape an identifier (table name, column name, etc.)
263
+ * CockroachDB uses double quotes for identifiers
264
+ */
265
+ escapeId(identifier: unknown): string;
266
+ /**
267
+ * Quote an identifier (column name, table name)
268
+ * CockroachDB uses double quotes for identifiers
269
+ */
270
+ quoteIdentifier(identifier: string): string;
271
+ /**
272
+ * Quote a table name
273
+ * Includes schema prefix if provided
274
+ */
275
+ quoteTable(tableName: string, schema?: string): string;
276
+ /**
277
+ * Get the database version
278
+ */
279
+ getDatabaseVersion(): Promise<string>;
280
+ /**
281
+ * Create a database schema
282
+ * @param schema - The schema name to create
283
+ */
284
+ createSchema(schema: string): Promise<void>;
285
+ /**
286
+ * Drop a database schema
287
+ * @param schema - The schema name to drop
288
+ * @param options - Drop options (e.g., cascade)
289
+ */
290
+ dropSchema(schema: string, options?: DropSchemaOptions): Promise<void>;
291
+ /**
292
+ * Show all schemas in the database
293
+ */
294
+ showAllSchemas(): Promise<string[]>;
295
+ /**
296
+ * List all schemas in the database
297
+ */
298
+ listSchemas(): Promise<string[]>;
299
+ /**
300
+ * Replace placeholders in SQL with actual values
301
+ * @param sql - SQL string with placeholders
302
+ * @param replacements - Object or array of replacement values
303
+ */
304
+ replaceReplacements(sql: string, replacements?: Record<string, unknown> | unknown[]): string;
305
+ /**
306
+ * Create a new table
307
+ */
308
+ createTable(tableName: string, columns: Record<string, ColumnDefinition>, options?: TableOptions & CockroachTableOptions): Promise<void>;
309
+ /**
310
+ * Build constraint SQL for table creation
311
+ */
312
+ private buildConstraintSql;
313
+ /**
314
+ * Generate column definition SQL for CockroachDB
315
+ */
316
+ private getColumnDefinitionSql;
317
+ /**
318
+ * Get default value SQL
319
+ */
320
+ private getDefaultValue;
321
+ /**
322
+ * Drop a table
323
+ */
324
+ dropTable(tableName: string, options?: DropTableOptions): Promise<void>;
325
+ /**
326
+ * Create a partitioned table (CockroachDB)
327
+ *
328
+ * @param tableName - Name of the table to create
329
+ * @param columns - Column definitions
330
+ * @param options - Table options including partition configuration
331
+ */
332
+ createPartitionedTable(tableName: string, columns: Record<string, ColumnDefinition>, options?: TableOptions & {
333
+ partitionBy: {
334
+ type: 'range' | 'list' | 'hash';
335
+ column: string | string[];
336
+ };
337
+ partitions?: PartitionDefinition[];
338
+ }): Promise<void>;
339
+ /**
340
+ * Create a partition for an existing partitioned table (CockroachDB)
341
+ *
342
+ * @param options - Partition creation options
343
+ */
344
+ createPartition(options: CreatePartitionOptions): Promise<void>;
345
+ /**
346
+ * Attach a partition to a partitioned table (CockroachDB)
347
+ *
348
+ * @param options - Partition attachment options
349
+ */
350
+ attachPartition(options: AttachPartitionOptions): Promise<void>;
351
+ /**
352
+ * Detach a partition from a partitioned table (CockroachDB)
353
+ *
354
+ * @param options - Partition detachment options
355
+ */
356
+ detachPartition(options: DetachPartitionOptions): Promise<void>;
357
+ /**
358
+ * Drop a partition (CockroachDB)
359
+ *
360
+ * @param partitionName - Name of the partition to drop
361
+ * @param options - Drop options
362
+ */
363
+ dropPartition(partitionName: string, options?: {
364
+ ifExists?: boolean;
365
+ cascade?: boolean;
366
+ }): Promise<void>;
367
+ /**
368
+ * Add a partition to an existing partitioned table (CockroachDB)
369
+ * @param tableName - Name of the partitioned table
370
+ * @param partitionName - Name for the new partition
371
+ * @param partitionSpec - Partition specification
372
+ */
373
+ addPartition(tableName: string, partitionName: string, partitionSpec: {
374
+ values?: string;
375
+ forValues?: string;
376
+ }): Promise<void>;
377
+ /**
378
+ * Build the `LOCALITY ...` clause fragment (without a leading space, but
379
+ * including the `LOCALITY` keyword itself) for a given locality setting.
380
+ * Shared by `createTable` and `setTableLocality`.
381
+ */
382
+ private buildLocalityClause;
383
+ /**
384
+ * Change the multi-region locality of an existing table
385
+ * (`ALTER TABLE ... SET LOCALITY ...`).
386
+ *
387
+ * Requires the database to already be multi-region (see
388
+ * `setPrimaryRegion`/`addRegion`).
389
+ *
390
+ * @see https://www.cockroachlabs.com/docs/stable/table-localities
391
+ */
392
+ setTableLocality(tableName: string, locality: CockroachLocality): Promise<void>;
393
+ /**
394
+ * Add a region to a multi-region database (`ALTER DATABASE ... ADD REGION ...`).
395
+ *
396
+ * @param region - Region name (e.g. `'us-east1'`)
397
+ * @param options - `database` to target a database other than the current one
398
+ */
399
+ addRegion(region: string, options?: {
400
+ database?: string;
401
+ ifNotExists?: boolean;
402
+ }): Promise<void>;
403
+ /**
404
+ * Remove a region from a multi-region database (`ALTER DATABASE ... DROP REGION ...`).
405
+ */
406
+ dropRegion(region: string, options?: {
407
+ database?: string;
408
+ }): Promise<void>;
409
+ /**
410
+ * Set (or change) the primary region of a database
411
+ * (`ALTER DATABASE ... {SET|PRIMARY REGION} ...`). Setting a primary
412
+ * region for the first time promotes the database to a multi-region
413
+ * database; CockroachDB automatically adds the region as a side effect if
414
+ * it hasn't been added yet.
415
+ *
416
+ * @see https://www.cockroachlabs.com/docs/stable/multiregion-overview
417
+ */
418
+ setPrimaryRegion(region: string, options?: {
419
+ database?: string;
420
+ }): Promise<void>;
421
+ /**
422
+ * Set the survival goal of a multi-region database
423
+ * (`ALTER DATABASE ... SURVIVE {ZONE|REGION} FAILURE`).
424
+ */
425
+ setSurvivalGoal(goal: 'zone' | 'region', options?: {
426
+ database?: string;
427
+ }): Promise<void>;
428
+ /**
429
+ * Resolve a `CockroachZoneTarget` to the SQL fragment that follows
430
+ * `ALTER ...` in `CONFIGURE ZONE`/`SPLIT AT`/`UNSPLIT AT` statements,
431
+ * e.g. `TABLE "orders"`, `INDEX "orders"@"idx_name"`, or
432
+ * `PARTITION "p1" OF TABLE "orders"`.
433
+ */
434
+ private resolveZoneTarget;
435
+ /**
436
+ * Configure replication/placement settings for a table, index, partition,
437
+ * or database (`ALTER ... CONFIGURE ZONE USING ...`).
438
+ *
439
+ * Exposes the subset of zone-configuration variables that are reasonable
440
+ * for an ORM to surface: replica count, placement constraints, lease
441
+ * preferences, GC TTL, and range size bounds. For anything more advanced,
442
+ * callers can fall back to raw `query()`.
443
+ *
444
+ * @see https://www.cockroachlabs.com/docs/stable/configure-zone
445
+ */
446
+ configureZone(target: CockroachZoneTarget, options: CockroachZoneConfigOptions): Promise<void>;
447
+ /**
448
+ * Reset a zone configuration back to its inherited default
449
+ * (`ALTER ... CONFIGURE ZONE DISCARD`).
450
+ */
451
+ resetZoneConfig(target: CockroachZoneTarget): Promise<void>;
452
+ /**
453
+ * Format a single split/unsplit key value for use inside a `VALUES (...)`
454
+ * tuple: quote strings, pass numbers/booleans through, and stringify
455
+ * `Date`s as ISO timestamps.
456
+ */
457
+ private formatSplitValue;
458
+ /**
459
+ * Manually split a range at the given key value(s)
460
+ * (`ALTER TABLE/INDEX ... SPLIT AT VALUES (...)`), to pre-emptively
461
+ * distribute a hot/monotonically-growing key range across nodes before
462
+ * CockroachDB's automatic range-size-based splitting would kick in.
463
+ *
464
+ * `values` is an array of row tuples matching the index prefix; pass
465
+ * multiple tuples to create multiple split points in one call.
466
+ *
467
+ * @see https://www.cockroachlabs.com/docs/stable/alter-table#split-at
468
+ */
469
+ splitAt(target: CockroachZoneTarget, values: unknown[][], options?: {
470
+ expiration?: string;
471
+ }): Promise<void>;
472
+ /**
473
+ * Undo a manual (or expired) range split
474
+ * (`ALTER TABLE/INDEX ... UNSPLIT AT VALUES (...)`), or unsplit every
475
+ * manually-created split point on the target when `values` is omitted
476
+ * (`UNSPLIT ALL`).
477
+ *
478
+ * @see https://www.cockroachlabs.com/docs/stable/alter-table#unsplit-at
479
+ */
480
+ unsplitAt(target: CockroachZoneTarget, values?: unknown[][]): Promise<void>;
481
+ /**
482
+ * Create a database view
483
+ */
484
+ createView(viewName: string, query: string, options?: ViewOptions): Promise<void>;
485
+ /**
486
+ * Drop a database view
487
+ */
488
+ dropView(viewName: string, options?: DropViewOptions): Promise<void>;
489
+ /**
490
+ * Show all views in the database
491
+ */
492
+ showViews(): Promise<string[]>;
493
+ /**
494
+ * Create a materialized view
495
+ * @param options - Materialized view options
496
+ */
497
+ createMaterializedView(options: MaterializedViewOptions): Promise<void>;
498
+ /**
499
+ * Refresh a materialized view
500
+ * @param viewName - Name of the materialized view to refresh
501
+ * @param options - Refresh options
502
+ */
503
+ refreshMaterializedView(viewName: string, options?: RefreshOptions): Promise<void>;
504
+ /**
505
+ * Drop a materialized view
506
+ * @param viewName - Name of the materialized view to drop
507
+ * @param options - Drop options
508
+ */
509
+ dropMaterializedView(viewName: string, options?: DropMaterializedViewOptions): Promise<void>;
510
+ /**
511
+ * Check if a materialized view exists
512
+ *
513
+ * Queries `pg_class`/`pg_namespace` directly (filtering on
514
+ * `relkind = 'm'`) rather than the derived `pg_matviews` view. CockroachDB's
515
+ * `pg_catalog` compatibility layer is partial, and `pg_matviews` — itself
516
+ * normally just a view defined on top of `pg_class` in real Postgres — is
517
+ * not guaranteed to exist/be populated the same way on CockroachDB.
518
+ * `pg_class` is the more fundamental catalog and a safer bet for accurate
519
+ * results (an absent/empty `pg_matviews` would otherwise silently report a
520
+ * false "materialized view doesn't exist").
521
+ * @param viewName - Name of the materialized view
522
+ * @returns True if the materialized view exists
523
+ */
524
+ hasMaterializedView(viewName: string): Promise<boolean>;
525
+ /**
526
+ * Show all materialized views in the database
527
+ *
528
+ * See `hasMaterializedView` for why this queries `pg_class`/`pg_namespace`
529
+ * (`relkind = 'm'`) instead of the `pg_matviews` compatibility view.
530
+ */
531
+ showMaterializedViews(): Promise<string[]>;
532
+ /**
533
+ * Create a stored procedure (CockroachDB)
534
+ */
535
+ createStoredProcedure(options: StoredProcedureOptions): Promise<void>;
536
+ /**
537
+ * CockroachDB has no Foreign Data Wrapper (FDW) machinery: no
538
+ * `CREATE FOREIGN DATA WRAPPER`/`CREATE SERVER`/`CREATE FOREIGN TABLE`/
539
+ * `CREATE USER MAPPING`/`IMPORT FOREIGN SCHEMA` statements, and no
540
+ * `pg_foreign_data_wrapper`/`pg_foreign_server` catalogs. These methods
541
+ * exist only to satisfy the shared `Dialect` interface (which the
542
+ * Postgres dialect implements for real); rather than silently emitting
543
+ * Postgres-only DDL that would fail against a real CockroachDB cluster,
544
+ * they throw a clear "not supported" error. External-data access on
545
+ * CockroachDB instead goes through `IMPORT`/`EXPORT` or
546
+ * `CREATE EXTERNAL CONNECTION`, which are out of scope for this ORM's
547
+ * FDW-shaped API.
548
+ * @see https://www.cockroachlabs.com/docs/stable/create-external-connection
549
+ */
550
+ private static readonly FDW_NOT_SUPPORTED_MESSAGE;
551
+ /**
552
+ * Create a foreign data wrapper — not supported in CockroachDB.
553
+ * @param _fdwName - Foreign data wrapper name (unused; kept for interface parity)
554
+ * @param _options - Options (unused; kept for interface parity)
555
+ */
556
+ createForeignDataWrapper(_fdwName: string, _options?: {
557
+ handler?: string;
558
+ }): Promise<void>;
559
+ dropForeignDataWrapper(_fdwName: string, _options?: {
560
+ ifExists?: boolean;
561
+ }): Promise<void>;
562
+ createForeignServer(_serverName: string, _fdwName: string, _options?: {
563
+ options?: Record<string, string>;
564
+ ifNotExists?: boolean;
565
+ }): Promise<void>;
566
+ dropForeignServer(_serverName: string, _options?: {
567
+ ifExists?: boolean;
568
+ cascade?: boolean;
569
+ }): Promise<void>;
570
+ createForeignTable(_tableName: string, _columns: Record<string, {
571
+ type: string;
572
+ }>, _options?: {
573
+ serverName?: string;
574
+ ifNotExists?: boolean;
575
+ }): Promise<void>;
576
+ changeOwner(newOwner: string, tableName: string): Promise<void>;
577
+ addConstraint(tableName: string, options: {
578
+ type: 'UNIQUE' | 'CHECK' | 'PRIMARY KEY' | 'FOREIGN KEY';
579
+ fields: string[];
580
+ name?: string;
581
+ references?: {
582
+ table: string;
583
+ fields: string[];
584
+ };
585
+ check?: string;
586
+ }): Promise<void>;
587
+ removeConstraint(tableName: string, constraintName: string): Promise<void>;
588
+ createSecurityPolicy(_policyName: string, _tableName: string, _options?: {
589
+ predicate?: string;
590
+ }): Promise<void>;
591
+ dropSecurityPolicy(_policyName: string, _tableName: string): Promise<void>;
592
+ /**
593
+ * Drop a stored procedure
594
+ */
595
+ dropStoredProcedure(procedureName: string, options?: DropStoredProcedureOptions): Promise<void>;
596
+ /**
597
+ * Drop a stored procedure (alias for dropStoredProcedure)
598
+ */
599
+ dropProcedure(procedureName: string, options?: DropStoredProcedureOptions): Promise<void>;
600
+ /**
601
+ * Create a stored procedure (alias for createStoredProcedure)
602
+ */
603
+ createProcedure(options: StoredProcedureOptions): Promise<void>;
604
+ /**
605
+ * Execute a stored procedure
606
+ */
607
+ executeStoredProcedure(options: ExecuteStoredProcedureOptions): Promise<QueryResult>;
608
+ /**
609
+ * Check if a stored procedure exists
610
+ */
611
+ hasStoredProcedure(procedureName: string, schema?: string): Promise<boolean>;
612
+ /**
613
+ * Create a user-defined function (CockroachDB)
614
+ *
615
+ * CockroachDB has supported `CREATE FUNCTION` for SQL and PL/pgSQL
616
+ * functions since v22.2/23.1, and unlike `CREATE PROCEDURE` (see
617
+ * `createStoredProcedure`), functions can be used directly in SELECT
618
+ * lists, computed column expressions, and CHECK constraints. A function
619
+ * must declare a `RETURNS` type, and may optionally declare a volatility
620
+ * category:
621
+ * - `VOLATILE` (the default when omitted): may modify the database
622
+ * and/or return different results on successive calls with the same
623
+ * arguments.
624
+ * - `STABLE`: cannot modify the database and returns the same result
625
+ * for the same arguments within a single statement; lets the
626
+ * optimizer avoid re-evaluating it per-row when safe.
627
+ * - `IMMUTABLE`: cannot modify the database and always returns the same
628
+ * result for the same arguments. Required for a function to be used
629
+ * in a computed column expression.
630
+ * @see https://www.cockroachlabs.com/docs/stable/create-function
631
+ */
632
+ createFunction(options: FunctionOptions): Promise<void>;
633
+ /**
634
+ * Drop a user-defined function
635
+ */
636
+ dropFunction(functionName: string, options?: DropFunctionOptions): Promise<void>;
637
+ /**
638
+ * Check if a user-defined function exists
639
+ */
640
+ hasFunction(functionName: string, schema?: string): Promise<boolean>;
641
+ /**
642
+ * Create a trigger
643
+ *
644
+ * CockroachDB's trigger support (added as a preview feature and
645
+ * subsequently stabilized) is deliberately narrower than Postgres':
646
+ * - Only row-level triggers are supported (`FOR EACH ROW`); there is no
647
+ * `FOR EACH STATEMENT` execution.
648
+ * - `INSTEAD OF` triggers are not supported (CockroachDB views are not
649
+ * updatable in the way Postgres views can be).
650
+ * - The `REFERENCING` clause (transition tables, e.g.
651
+ * `REFERENCING NEW TABLE AS ...`) is not supported.
652
+ * - Constraint triggers (`CREATE CONSTRAINT TRIGGER`) are not supported.
653
+ * Rather than silently emitting Postgres-only DDL that will fail (or
654
+ * behave unexpectedly) against CockroachDB, these unsupported options
655
+ * throw a clear error.
656
+ *
657
+ * @see https://www.cockroachlabs.com/docs/stable/triggers
658
+ */
659
+ createTrigger(options: TriggerOptions): Promise<void>;
660
+ /**
661
+ * Drop a trigger
662
+ */
663
+ dropTrigger(triggerName: string, tableName: string, options?: DropTriggerOptions): Promise<void>;
664
+ /**
665
+ * List triggers defined on a table.
666
+ *
667
+ * Uses CockroachDB's own `SHOW TRIGGERS FROM <table>` introspection
668
+ * statement (in the same family as `SHOW INDEXES FROM`/`SHOW CONSTRAINTS
669
+ * FROM` used elsewhere in this dialect) rather than querying the
670
+ * `pg_trigger` catalog directly. CockroachDB's `pg_catalog` compatibility
671
+ * layer is partial, and there is no guarantee `pg_trigger` is populated
672
+ * for CockroachDB-native triggers the same way it is in real Postgres, so
673
+ * relying on it risks silently reporting "no trigger" when one exists.
674
+ */
675
+ showTriggers(tableName: string): Promise<any[]>;
676
+ /**
677
+ * Check if a trigger exists
678
+ */
679
+ hasTrigger(triggerName: string, tableName: string): Promise<boolean>;
680
+ /**
681
+ * Create a sequence
682
+ */
683
+ createSequence(options: SequenceOptions): Promise<void>;
684
+ /**
685
+ * Drop a sequence
686
+ */
687
+ dropSequence(sequenceName: string, options?: DropSequenceOptions): Promise<void>;
688
+ /**
689
+ * Get next value from a sequence
690
+ */
691
+ nextSequenceValue(sequenceName: string): Promise<number>;
692
+ /**
693
+ * Check if a sequence exists
694
+ */
695
+ hasSequence(sequenceName: string): Promise<boolean>;
696
+ /**
697
+ * List all sequences in the database (CockroachDB)
698
+ * @returns Array of sequence names
699
+ */
700
+ listSequences(): Promise<string[]>;
701
+ /**
702
+ * Create a policy (CockroachDB RLS)
703
+ */
704
+ createPolicy(options: PolicyOptions): Promise<void>;
705
+ /**
706
+ * Drop a policy (CockroachDB RLS)
707
+ */
708
+ dropPolicy(policyName: string, tableName: string, options?: DropPolicyOptions): Promise<void>;
709
+ /**
710
+ * Enable row-level security on a table (CockroachDB)
711
+ */
712
+ enableRLS(tableName: string, schema?: string): Promise<void>;
713
+ /**
714
+ * Enable row-level security on a table (alias for enableRLS)
715
+ */
716
+ enableRowLevelSecurity(tableName: string, schema?: string): Promise<void>;
717
+ /**
718
+ * Disable row-level security on a table (CockroachDB)
719
+ */
720
+ disableRLS(tableName: string, schema?: string): Promise<void>;
721
+ /**
722
+ * Check if a policy exists (CockroachDB RLS)
723
+ */
724
+ hasPolicy(policyName: string, tableName: string): Promise<boolean>;
725
+ /**
726
+ * Add comment to a table
727
+ */
728
+ commentTable(tableName: string, comment: string): Promise<void>;
729
+ /**
730
+ * Add comment to a column
731
+ */
732
+ commentColumn(tableName: string, columnName: string, comment: string): Promise<void>;
733
+ /**
734
+ * Create a partial index (index with WHERE clause)
735
+ */
736
+ createPartialIndex(tableName: string, indexName: string, fields: string[], where: string, options?: IndexOptions): Promise<void>;
737
+ /**
738
+ * Create an expression index
739
+ */
740
+ createExpressionIndex(tableName: string, indexName: string, expression: string, options?: IndexOptions): Promise<void>;
741
+ /**
742
+ * Create a fulltext index (CockroachDB)
743
+ * Uses GIN index for fulltext search
744
+ * @param tableName - Table name
745
+ * @param indexName - Index name
746
+ * @param fields - Fields to index
747
+ * @param options - Fulltext index options
748
+ */
749
+ createFulltextIndex(tableName: string, indexName: string, fields: string[], options?: {
750
+ parser?: string;
751
+ comment?: string;
752
+ }): Promise<void>;
753
+ /**
754
+ * Create a spatial index (CockroachDB)
755
+ * Uses GIST index for spatial data
756
+ * @param tableName - Table name
757
+ * @param indexName - Index name
758
+ * @param fields - Fields to index
759
+ * @param options - Spatial index options
760
+ */
761
+ createSpatialIndex(tableName: string, indexName: string, fields: string[], options?: {
762
+ storage?: string;
763
+ srid?: number;
764
+ }): Promise<void>;
765
+ /**
766
+ * Bulk insert records into a table
767
+ */
768
+ bulkInsert(tableName: string, records: Record<string, any>[], _options?: any): Promise<QueryResult>;
769
+ /**
770
+ * Add a foreign key to a table
771
+ */
772
+ addForeignKey(tableName: string, columnName: string, referencedTableName: string, referencedColumnName: string, options?: {
773
+ name?: string;
774
+ onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION';
775
+ onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'NO ACTION';
776
+ }): Promise<void>;
777
+ /**
778
+ * Rename a column
779
+ */
780
+ renameColumn(tableName: string, oldColumnName: string, newColumnName: string): Promise<void>;
781
+ /**
782
+ * Create an identity column
783
+ */
784
+ createIdentityColumn(tableName: string, columnName: string, options?: {
785
+ startWith?: number;
786
+ incrementBy?: number;
787
+ minvalue?: number;
788
+ maxvalue?: number;
789
+ cycle?: boolean;
790
+ }): Promise<void>;
791
+ /**
792
+ * Create a computed column (generated column)
793
+ */
794
+ createComputedColumn(tableName: string, columnName: string, expression: string, options?: {
795
+ persisted?: boolean;
796
+ type?: string;
797
+ }): Promise<void>;
798
+ /**
799
+ * CockroachDB does NOT implement PostgreSQL's extension mechanism the way
800
+ * Postgres does. `CREATE EXTENSION`/`DROP EXTENSION` are accepted by CRDB
801
+ * purely as no-op compatibility shims for a small, fixed allowlist of
802
+ * extension names (kept in sync with CockroachDB's documented "Supported
803
+ * extensions" list) so that ORMs/tools which unconditionally issue
804
+ * `CREATE EXTENSION IF NOT EXISTS <name>` don't fail outright. No actual
805
+ * extension code is loaded and most Postgres extensions (arbitrary compiled
806
+ * extensions, most contrib modules, etc.) are NOT usable at all. Callers
807
+ * asking for anything outside this allowlist get a clear error instead of
808
+ * a misleading "success" that doesn't provide any real functionality.
809
+ */
810
+ private static readonly SUPPORTED_EXTENSION_SHIMS;
811
+ private assertExtensionShimSupported;
812
+ /**
813
+ * Create a CockroachDB extension (no-op compatibility shim; see
814
+ * SUPPORTED_EXTENSION_SHIMS above for CockroachDB's partial extension compatibility)
815
+ * @param extensionName - Name of the extension to create
816
+ * @param options - Extension options
817
+ */
818
+ createExtension(extensionName: string, options?: CreateExtensionOptions): Promise<void>;
819
+ /**
820
+ * Drop a CockroachDB extension (no-op compatibility shim; see
821
+ * SUPPORTED_EXTENSION_SHIMS above for CockroachDB's partial extension compatibility)
822
+ * @param extensionName - Name of the extension to drop
823
+ * @param options - Drop options
824
+ */
825
+ dropExtension(extensionName: string, options?: DropExtensionOptions): Promise<void>;
826
+ /**
827
+ * Get all installed CockroachDB extensions
828
+ * @returns Array of extension information
829
+ */
830
+ getExtensions(): Promise<ExtensionInfo[]>;
831
+ /**
832
+ * Check if a CockroachDB extension is installed. Extensions outside
833
+ * CockroachDB's small no-op compatibility allowlist (see
834
+ * SUPPORTED_EXTENSION_SHIMS above) can never be "installed" on CockroachDB,
835
+ * so this returns false for them without a round-trip to the server.
836
+ * @param extensionName - Name of the extension
837
+ * @returns True if the extension is installed
838
+ */
839
+ hasExtension(extensionName: string): Promise<boolean>;
840
+ buildCreateServerQuery(_name: string, _opts: FdwForeignServerOptions): string;
841
+ buildAlterServerQuery(_name: string, _opts: FdwAlterForeignServerOptions): string;
842
+ buildDropServerQuery(_name: string, _opts?: {
843
+ ifExists?: boolean;
844
+ cascade?: boolean;
845
+ }): string;
846
+ /**
847
+ * Return the SQL to list all foreign servers from the catalog — not
848
+ * supported in CockroachDB (no `pg_foreign_server`/`pg_foreign_data_wrapper`).
849
+ */
850
+ getServersQuery(): string;
851
+ buildCreateUserMappingQuery(_opts: FdwUserMappingOptions): string;
852
+ buildAlterUserMappingQuery(_opts: FdwUserMappingOptions): string;
853
+ buildDropUserMappingQuery(_serverName: string, _user: string, _opts?: {
854
+ ifExists?: boolean;
855
+ }): string;
856
+ /**
857
+ * Create a user mapping for a foreign server — not supported in CockroachDB.
858
+ */
859
+ createUserMapping(_userName: string, _serverName: string, _options?: {
860
+ username?: string;
861
+ password?: string;
862
+ }): Promise<void>;
863
+ /**
864
+ * Drop a user mapping for a foreign server — not supported in CockroachDB.
865
+ */
866
+ dropUserMapping(_userName: string, _serverName: string, _options?: {
867
+ ifExists?: boolean;
868
+ }): Promise<void>;
869
+ buildCreateForeignTableQuery(_tableName: string, _opts: FdwForeignTableOptions): string;
870
+ buildDropForeignTableQuery(_tableName: string, _opts?: {
871
+ ifExists?: boolean;
872
+ cascade?: boolean;
873
+ }): string;
874
+ buildImportForeignSchemaQuery(_remoteSchema: string, _serverName: string, _opts?: FdwImportForeignSchemaOptions): string;
875
+ /**
876
+ * Add a column to a table
877
+ */
878
+ addColumn(tableName: string, columnName: string, definition: ColumnDefinition): Promise<void>;
879
+ /**
880
+ * Remove a column from a table
881
+ */
882
+ removeColumn(tableName: string, columnName: string): Promise<void>;
883
+ /**
884
+ * Change a column definition
885
+ */
886
+ changeColumn(tableName: string, columnName: string, definition: ColumnDefinition): Promise<void>;
887
+ /**
888
+ * Show all tables in the database
889
+ *
890
+ * Uses CockroachDB's `SHOW TABLES` statement (rather than querying
891
+ * information_schema directly, as the Postgres dialect does) so this
892
+ * dialect exercises CockroachDB-specific introspection syntax. `SHOW
893
+ * TABLES` returns rows shaped like
894
+ * `{ schema_name, table_name, type, owner, estimated_row_count, locality }`
895
+ * for the current database's `public` schema by default.
896
+ */
897
+ showTables(): Promise<string[]>;
898
+ /**
899
+ * Get table status (CockroachDB implementation)
900
+ */
901
+ getTableStatus(tableName?: string): Promise<Record<string, any>[]>;
902
+ /**
903
+ * Get table create statement (CockroachDB implementation)
904
+ */
905
+ getCreateTable(tableName: string): Promise<string>;
906
+ /**
907
+ * Check if a table has partitions (CockroachDB implementation)
908
+ */
909
+ hasPartition(tableName: string): Promise<boolean>;
910
+ /**
911
+ * Show constraints for a table
912
+ *
913
+ * Uses CockroachDB's `SHOW CONSTRAINTS FROM <table>` statement, which
914
+ * returns rows shaped like
915
+ * `{ table_name, constraint_name, constraint_type, details, validated }`.
916
+ */
917
+ showConstraints(tableName: string): Promise<any[]>;
918
+ /**
919
+ * Show indexes for a table
920
+ *
921
+ * Uses CockroachDB's `SHOW INDEXES FROM <table>` statement, which returns
922
+ * rows shaped like
923
+ * `{ table_name, index_name, non_unique, seq_in_index, column_name,
924
+ * direction, storing, implicit }`.
925
+ */
926
+ showIndexes(tableName: string): Promise<any[]>;
927
+ /**
928
+ * Inspect the range (shard) distribution of a table or index via
929
+ * CockroachDB's `SHOW RANGES FROM TABLE|INDEX ...`. Each row describes one
930
+ * range: its start/end keys, lease holder, and replica placement. Useful for
931
+ * diagnosing hotspots and verifying `splitAt()`/`configureZone()` results
932
+ * without dropping to raw SQL.
933
+ *
934
+ * @param target - `{ kind: 'table', name }` or `{ kind: 'index', table,
935
+ * index }` naming what to inspect (same target shape as
936
+ * {@link configureZone}/{@link splitAt}).
937
+ * @see https://www.cockroachlabs.com/docs/stable/show-ranges
938
+ */
939
+ showRanges(target: CockroachZoneTarget): Promise<any[]>;
940
+ /**
941
+ * Show the single range that would contain a given primary-key row
942
+ * (`SHOW RANGE FROM TABLE <t> FOR ROW (val, ...)`), reporting its lease
943
+ * holder and replica placement. Handy for pinpointing which node owns a
944
+ * specific hot key.
945
+ *
946
+ * @param tableName - Table to look up the row's range in.
947
+ * @param rowValues - The row's primary-key column value(s), in key order.
948
+ * @see https://www.cockroachlabs.com/docs/stable/show-range-for-row
949
+ */
950
+ showRangeForRow(tableName: string, rowValues: unknown[]): Promise<any[]>;
951
+ /**
952
+ * Return the cost-based optimizer's table statistics
953
+ * (`SHOW STATISTICS FOR TABLE <t>`): column sets, row counts, distinct
954
+ * counts, null counts and histogram ids the planner uses for cardinality
955
+ * estimation.
956
+ *
957
+ * @see https://www.cockroachlabs.com/docs/stable/show-statistics
958
+ */
959
+ showStatistics(tableName: string): Promise<any[]>;
960
+ /**
961
+ * Trigger a fresh collection of table statistics for the optimizer
962
+ * (`ANALYZE <t>`, an alias of `CREATE STATISTICS ... FROM <t>`). Run after a
963
+ * large bulk load/mutation so the planner has accurate cardinality estimates.
964
+ *
965
+ * @see https://www.cockroachlabs.com/docs/stable/create-statistics
966
+ */
967
+ analyzeTable(tableName: string): Promise<void>;
968
+ /**
969
+ * Describe a table (get column information)
970
+ *
971
+ * Uses CockroachDB's `SHOW COLUMNS FROM <table>` statement, which returns
972
+ * rows shaped like
973
+ * `{ column_name, data_type, is_nullable, column_default,
974
+ * generation_expression, indices, is_hidden }`, plus
975
+ * `SHOW CONSTRAINTS FROM <table>` to determine which column(s) form the
976
+ * primary key.
977
+ */
978
+ describeTable(tableName: string): Promise<TableDescription>;
979
+ /**
980
+ * Rename a table
981
+ */
982
+ renameTable(oldName: string, newName: string): Promise<void>;
983
+ /**
984
+ * Resolve and validate the requested hash-sharded index bucket count
985
+ * (`bucketCount`/`shard`) from an options object. Returns `undefined` if
986
+ * neither is set.
987
+ */
988
+ private resolveHashBucketCount;
989
+ /**
990
+ * Add an index to a table
991
+ *
992
+ * Note: unlike Postgres, CockroachDB does not support (or need)
993
+ * `CREATE INDEX CONCURRENTLY` — index backfills are already online and
994
+ * non-blocking by default. If a caller requests `concurrently`, it is
995
+ * ignored (with a warning) rather than emitted in the SQL.
996
+ */
997
+ addIndex(tableName: string, indexName: string, fields?: string[], options?: IndexOptions & CockroachHashShardedIndexOptions): Promise<void>;
998
+ /**
999
+ * Remove an index from a table
1000
+ */
1001
+ removeIndex(tableName: string, indexName: string): Promise<void>;
1002
+ /**
1003
+ * Create an index on a table with full options support
1004
+ *
1005
+ * Note: CockroachDB does not support `CREATE INDEX CONCURRENTLY` — index
1006
+ * creation is already online/non-blocking, so a `concurrently` flag (if
1007
+ * present on `indexDef`) is ignored with a warning instead of being
1008
+ * emitted in the SQL.
1009
+ */
1010
+ createIndex(tableName: string, indexDef: {
1011
+ name: string;
1012
+ unique?: boolean;
1013
+ type?: string;
1014
+ using?: string;
1015
+ fields: string[];
1016
+ where?: WhereOptions;
1017
+ expression?: string;
1018
+ include?: string[];
1019
+ concurrently?: boolean;
1020
+ /** Hash-sharded index bucket count (CockroachDB `USING HASH WITH (bucket_count = N)`) */
1021
+ bucketCount?: number;
1022
+ /** Alias for `bucketCount` */
1023
+ shard?: number;
1024
+ }): Promise<void>;
1025
+ /**
1026
+ * Create a GIN index for full-text search
1027
+ * CockroachDB-specific GIN (Generalized Inverted Index) for tsvector
1028
+ */
1029
+ createGINIndex(tableName: string, indexName: string, column: string, options?: {
1030
+ config?: string;
1031
+ storageParameters?: Record<string, string | number>;
1032
+ }): Promise<void>;
1033
+ /**
1034
+ * Create an inverted (GIN) index over a JSONB column so containment/path
1035
+ * queries (`@>`, `->`, `->>`) on it can be index-accelerated. Unlike
1036
+ * {@link createGINIndex} (which wraps the column in `to_tsvector(...)` for
1037
+ * full-text search), this indexes the raw JSONB value directly:
1038
+ * `CREATE [UNIQUE] INVERTED INDEX <name> ON <table> (<column>)`.
1039
+ *
1040
+ * CockroachDB spells inverted indexes as `INVERTED INDEX ... (col)`
1041
+ * (equivalent to Postgres's `USING GIN (col)`); this helper emits the
1042
+ * CockroachDB-native form. Also usable for `ARRAY` columns.
1043
+ *
1044
+ * @see https://www.cockroachlabs.com/docs/stable/inverted-indexes
1045
+ */
1046
+ createInvertedIndex(tableName: string, indexName: string, column: string, options?: {
1047
+ ifNotExists?: boolean;
1048
+ storageParameters?: Record<string, string | number>;
1049
+ }): Promise<void>;
1050
+ /**
1051
+ * Build a to_tsvector expression
1052
+ * SQL: to_tsvector([config,] document)
1053
+ */
1054
+ buildTsVector(column: string | string[], config?: string): string;
1055
+ /**
1056
+ * Build a to_tsquery expression
1057
+ * SQL: to_tsquery([config,] query)
1058
+ */
1059
+ buildTsQuery(query: string, config?: string): string;
1060
+ /**
1061
+ * Build a plainto_tsquery expression (for phrase searching)
1062
+ * SQL: plainto_tsquery([config,] query)
1063
+ * Converts a phrase into a tsquery that matches documents containing all the words
1064
+ */
1065
+ buildPlainTsQuery(query: string, config?: string): string;
1066
+ /**
1067
+ * Build a phraseto_tsquery expression (for exact phrase matching)
1068
+ * SQL: phraseto_tsquery([config,] query)
1069
+ * Converts a phrase into a tsquery that matches documents containing the exact phrase
1070
+ */
1071
+ buildPhraseTsQuery(query: string, config?: string): string;
1072
+ /**
1073
+ * Build a websearch_to_tsquery expression (for web search style queries)
1074
+ * SQL: websearch_to_tsquery([config,] query)
1075
+ * Supports web search operators like +, -, "quotes", etc.
1076
+ */
1077
+ buildWebsearchTsQuery(query: string, config?: string): string;
1078
+ /**
1079
+ * Build a ts_rank expression for ranking full-text search results
1080
+ * SQL: ts_rank([weights,] vector, query [, normalization])
1081
+ */
1082
+ buildTsRank(vector: string, query: string, options?: {
1083
+ weights?: number[];
1084
+ normalization?: number;
1085
+ }): string;
1086
+ /**
1087
+ * Create a GIST index for spatial data
1088
+ * CockroachDB GIST (Generalized Search Tree) index for geometry/geography columns
1089
+ */
1090
+ createGISTIndex(tableName: string, indexName: string, column: string, options?: {
1091
+ /** Use geography instead of geometry */
1092
+ geography?: boolean;
1093
+ /** Geometry type constraint (e.g., 'POINT', 'POLYGON') */
1094
+ geometryType?: string;
1095
+ /** SRID constraint (e.g., 4326 for WGS84) */
1096
+ srid?: number;
1097
+ /** Storage parameters */
1098
+ fillFactor?: number;
1099
+ }): Promise<void>;
1100
+ /**
1101
+ * Create a GIN index for spatial data (PostGIS 2.1+)
1102
+ * GIN indexes are slower to build but faster for very large datasets with many overlapping geometries
1103
+ */
1104
+ createGINSpatialIndex(tableName: string, indexName: string, column: string): Promise<void>;
1105
+ /**
1106
+ * ST_Distance - calculate distance between two geometries
1107
+ * For geography, returns distance in meters
1108
+ */
1109
+ stDistance(geom1: string, geom2: string, useGeography?: boolean): string;
1110
+ /**
1111
+ * ST_DWithin - check if geometries are within a given distance
1112
+ * For geography, distance is in meters
1113
+ */
1114
+ stDWithin(geom1: string, geom2: string, distance: number, useGeography?: boolean): string;
1115
+ /**
1116
+ * ST_Within - check if geometry A is within geometry B
1117
+ */
1118
+ stWithin(geom1: string, geom2: string): string;
1119
+ /**
1120
+ * ST_Contains - check if geometry A contains geometry B
1121
+ */
1122
+ stContains(geom1: string, geom2: string): string;
1123
+ /**
1124
+ * ST_Intersects - check if two geometries intersect
1125
+ */
1126
+ stIntersects(geom1: string, geom2: string): string;
1127
+ /**
1128
+ * ST_Crosses - check if two geometries cross
1129
+ */
1130
+ stCrosses(geom1: string, geom2: string): string;
1131
+ /**
1132
+ * ST_Overlaps - check if two geometries overlap
1133
+ */
1134
+ stOverlaps(geom1: string, geom2: string): string;
1135
+ /**
1136
+ * ST_Touches - check if two geometries touch
1137
+ */
1138
+ stTouches(geom1: string, geom2: string): string;
1139
+ /**
1140
+ * ST_Equals - check if two geometries are equal
1141
+ */
1142
+ stEquals(geom1: string, geom2: string): string;
1143
+ /**
1144
+ * ST_IsValid - check if a geometry is valid
1145
+ */
1146
+ stIsValid(geom: string): string;
1147
+ /**
1148
+ * ST_GeomFromText - create geometry from WKT text
1149
+ */
1150
+ stGeomFromText(wkt: string, srid?: number): string;
1151
+ /**
1152
+ * ST_GeomFromGeoJSON - create geometry from GeoJSON
1153
+ */
1154
+ stGeomFromGeoJSON(geojson: string, srid?: number): string;
1155
+ /**
1156
+ * ST_AsGeoJSON - convert geometry to GeoJSON
1157
+ */
1158
+ stAsGeoJSON(geom: string, options?: {
1159
+ precision?: number;
1160
+ longCRS?: boolean;
1161
+ }): string;
1162
+ /**
1163
+ * ST_AsText - convert geometry to WKT
1164
+ */
1165
+ stAsText(geom: string): string;
1166
+ /**
1167
+ * ST_Centroid - get the centroid of a geometry
1168
+ */
1169
+ stCentroid(geom: string): string;
1170
+ /**
1171
+ * ST_Area - calculate the area of a polygon
1172
+ * For geography, returns area in square meters
1173
+ */
1174
+ stArea(geom: string, useGeography?: boolean): string;
1175
+ /**
1176
+ * ST_Length - calculate the length of a line
1177
+ * For geography, returns length in meters
1178
+ */
1179
+ stLength(geom: string, useGeography?: boolean): string;
1180
+ /**
1181
+ * ST_Point - create a point from coordinates
1182
+ */
1183
+ stPoint(long: string, lat: string): string;
1184
+ /**
1185
+ * ST_SetSRID - set the SRID of a geometry
1186
+ */
1187
+ stSetSRID(geom: string, srid: number): string;
1188
+ /**
1189
+ * ST_SRID - get the SRID of a geometry
1190
+ */
1191
+ stSRID(geom: string): string;
1192
+ /**
1193
+ * ST_X - get the X coordinate of a point
1194
+ */
1195
+ stX(geom: string): string;
1196
+ /**
1197
+ * ST_Y - get the Y coordinate of a point
1198
+ */
1199
+ stY(geom: string): string;
1200
+ /**
1201
+ * ST_Distance_Sphere - calculate distance using sphere (less accurate but faster)
1202
+ * Returns distance in meters
1203
+ */
1204
+ stDistanceSphere(geom1: string, geom2: string): string;
1205
+ /**
1206
+ * ST_Distance_Spheroid - calculate distance using spheroid (accurate)
1207
+ * Returns distance in meters
1208
+ */
1209
+ stDistanceSpheroid(geom1: string, geom2: string): string;
1210
+ /**
1211
+ * Drop an index from a table
1212
+ */
1213
+ dropIndex(tableName: string, indexName: string, options?: {
1214
+ ifExists?: boolean;
1215
+ cascade?: boolean;
1216
+ }): Promise<void>;
1217
+ /**
1218
+ * Create a constraint on a table
1219
+ */
1220
+ createConstraint(tableName: string, constraintDef: {
1221
+ name: string;
1222
+ type: 'PRIMARY KEY' | 'UNIQUE' | 'FOREIGN KEY' | 'CHECK';
1223
+ fields?: string[];
1224
+ references?: {
1225
+ table: string;
1226
+ field: string;
1227
+ onDelete?: string;
1228
+ onUpdate?: string;
1229
+ };
1230
+ check?: string;
1231
+ deferrable?: 'INITIALLY DEFERRED' | 'INITIALLY IMMEDIATE';
1232
+ }): Promise<void>;
1233
+ /**
1234
+ * Drop a constraint from a table
1235
+ */
1236
+ dropConstraint(tableName: string, constraintName: string, options?: {
1237
+ ifExists?: boolean;
1238
+ cascade?: boolean;
1239
+ }): Promise<void>;
1240
+ /**
1241
+ * Begin a new transaction
1242
+ */
1243
+ startTransaction(options?: CockroachRunTransactionOptions): Promise<Transaction>;
1244
+ /**
1245
+ * Set the priority of the *current* transaction
1246
+ * (`SET TRANSACTION PRIORITY {LOW|NORMAL|HIGH}`). Must be called on a
1247
+ * transaction's own client, before any statement in the transaction reads or
1248
+ * writes data. Prefer passing `priority` to {@link startTransaction} /
1249
+ * {@link runTransaction}; this helper is for adjusting an already-open
1250
+ * transaction created elsewhere.
1251
+ *
1252
+ * @see https://www.cockroachlabs.com/docs/stable/set-transaction
1253
+ */
1254
+ setTransactionPriority(transaction: Transaction, priority: CockroachTransactionPriority): Promise<void>;
1255
+ /**
1256
+ * Run a function inside a CockroachDB transaction, automatically retrying
1257
+ * the *entire transaction body* when it fails with a serialization failure
1258
+ * (SQLSTATE `40001`, surfaced as a "restart transaction" error).
1259
+ *
1260
+ * Under SERIALIZABLE isolation (CockroachDB's default and only isolation
1261
+ * level), conflicting concurrent transactions routinely abort with
1262
+ * `40001`; CockroachDB's documented client contract is to retry the whole
1263
+ * transaction from the beginning rather than treating it as a fatal error.
1264
+ * This implements that contract using the standard
1265
+ * `SAVEPOINT cockroach_restart` pattern: a savepoint is created right after
1266
+ * `BEGIN`, and on a retryable error the transaction is rolled back to that
1267
+ * savepoint (instead of being aborted outright) so `fn` can be re-run.
1268
+ *
1269
+ * @see https://www.cockroachlabs.com/docs/stable/transaction-retry-error-reference
1270
+ * @see https://www.cockroachlabs.com/docs/stable/transactions#client-side-intervention
1271
+ *
1272
+ * @param fn - Callback that receives the transaction and performs the work
1273
+ * to (re)try. It may be invoked more than once, so it should be
1274
+ * idempotent / avoid externally-visible side effects other than through
1275
+ * the database.
1276
+ * @param options - Transaction options, plus an optional `maxRetries`
1277
+ * (defaults to 5) capping how many times `fn` will be retried after a
1278
+ * `40001` before the error is rethrown.
1279
+ */
1280
+ runTransaction<T>(fn: (tx: CockroachDBTransaction) => Promise<T>, options?: CockroachRunTransactionOptions): Promise<T>;
1281
+ /**
1282
+ * Commit a transaction
1283
+ */
1284
+ commitTransaction(transaction: Transaction): Promise<void>;
1285
+ /**
1286
+ * Rollback a transaction
1287
+ */
1288
+ rollbackTransaction(transaction: Transaction): Promise<void>;
1289
+ /**
1290
+ * Get the SQL for a data type
1291
+ */
1292
+ getDataTypeSql(dataType: DataType): string;
1293
+ /**
1294
+ * Get the SQL for an ARRAY type
1295
+ */
1296
+ getArrayTypeSql(elementType: DataType): string;
1297
+ /**
1298
+ * Get the isolation level SQL
1299
+ */
1300
+ private getIsolationLevelSql;
1301
+ /**
1302
+ * Build a WHERE clause from a WhereOptions object
1303
+ */
1304
+ buildWhereClause(where: WhereOptions, options?: {
1305
+ replacements?: Record<string, unknown>;
1306
+ }): {
1307
+ sql: string;
1308
+ values: unknown[];
1309
+ };
1310
+ /**
1311
+ * Build an ORDER BY clause
1312
+ */
1313
+ buildOrderClause(order: Order, options?: {
1314
+ replacements?: Record<string, unknown>;
1315
+ }): string;
1316
+ /**
1317
+ * Build a LIMIT/OFFSET clause
1318
+ */
1319
+ buildLimitOffset(limit?: number | string, offset?: number | string): string;
1320
+ /**
1321
+ * Build an INSERT query with RETURNING support
1322
+ */
1323
+ buildInsertQuery(tableName: string, values: Record<string, unknown>, options?: CockroachInsertOptions): {
1324
+ sql: string;
1325
+ values: unknown[];
1326
+ };
1327
+ /**
1328
+ * Build an UPSERT query for CockroachDB
1329
+ * Uses `ON CONFLICT ... DO UPDATE SET` syntax by default, or CockroachDB's
1330
+ * native `UPSERT INTO ... VALUES (...)` shorthand when `options.nativeUpsert`
1331
+ * is set (which replaces the row matching the primary key wholesale and
1332
+ * needs no conflict target).
1333
+ * @see https://www.cockroachlabs.com/docs/stable/upsert
1334
+ */
1335
+ buildUpsertQuery(tableName: string, values: Record<string, unknown>, options?: CockroachUpsertQueryOptions): {
1336
+ sql: string;
1337
+ values: unknown[];
1338
+ };
1339
+ /**
1340
+ * Build an increment query
1341
+ * @param tableName - Table name
1342
+ * @param fields - Fields to increment
1343
+ * @param where - Where clause
1344
+ * @param options - Query options (by: number)
1345
+ */
1346
+ buildIncrementQuery(tableName: string, fields: string | string[] | Record<string, number>, where: WhereOptions, options?: {
1347
+ by?: number;
1348
+ }): {
1349
+ sql: string;
1350
+ values: unknown[];
1351
+ };
1352
+ /**
1353
+ * Build an UPDATE query with RETURNING support
1354
+ */
1355
+ buildUpdateQuery(tableName: string, values: Record<string, unknown>, where: WhereOptions, options?: DUpdateOptions): {
1356
+ sql: string;
1357
+ values: unknown[];
1358
+ };
1359
+ /**
1360
+ * Build a DELETE query with RETURNING support
1361
+ */
1362
+ buildDeleteQuery(tableName: string, where: WhereOptions, options?: DeleteOptions): {
1363
+ sql: string;
1364
+ values: unknown[];
1365
+ };
1366
+ /**
1367
+ * Check if a value is a function expression (fn('COUNT', ...))
1368
+ */
1369
+ private isFnExpression;
1370
+ /**
1371
+ * Check if a value is a column expression (col('name'))
1372
+ */
1373
+ private isColExpression;
1374
+ /**
1375
+ * Check if a value is a literal expression (literal('sql'))
1376
+ */
1377
+ /**
1378
+ * Render a literal expression, substituting any `bindings` into its `?`
1379
+ * placeholders with dialect-correct escaping. `literalExpr(sql)` with no
1380
+ * bindings is unchanged; `literalExpr('x > ?', [v])` no longer requires the
1381
+ * caller to concatenate the value into the string themselves.
1382
+ */
1383
+ private literalSql;
1384
+ private isLiteralExpression;
1385
+ /**
1386
+ * Compile a function expression to SQL
1387
+ */
1388
+ private compileFnExpression;
1389
+ /**
1390
+ * Build SELECT clause with support for function expressions and aliases
1391
+ * Handles: 'field', ['field'], ['field', 'alias'], [fn('COUNT', 'id'), 'count']
1392
+ */
1393
+ private buildSelectClause;
1394
+ /**
1395
+ * Build GROUP BY clause with support for function expressions and aliases
1396
+ * Handles: 'field', ['field1', 'field2'], [[fn('COUNT', 'id'), 'count']]
1397
+ */
1398
+ private buildGroupByClause;
1399
+ /**
1400
+ * Build a WHERE clause condition using standard operators (Op.gt, Op.eq, etc.)
1401
+ * CockroachDB uses $1, $2, etc. for parameter placeholders
1402
+ */
1403
+ private buildCondition;
1404
+ /**
1405
+ * Build a HAVING clause with support for standard Op operators
1406
+ */
1407
+ private buildHavingClause;
1408
+ /**
1409
+ * Build the expression used after `AS OF SYSTEM TIME` for CockroachDB
1410
+ * time-travel reads.
1411
+ *
1412
+ * Accepts:
1413
+ * - A relative interval shorthand, e.g. `'-10s'`, `'-500ms'`, `'-1h'`.
1414
+ * - An absolute ISO-8601 timestamp, e.g. `'2024-01-01T00:00:00Z'`.
1415
+ * - The literal function call `follower_read_timestamp()` (unquoted).
1416
+ *
1417
+ * The value is validated against a strict allow-list pattern before being
1418
+ * embedded in the SQL string (rather than passed as a bound parameter,
1419
+ * which CockroachDB's `AS OF SYSTEM TIME` clause does not accept) to avoid
1420
+ * SQL injection.
1421
+ *
1422
+ * @see https://www.cockroachlabs.com/docs/stable/as-of-system-time
1423
+ */
1424
+ private buildAsOfSystemTimeClause;
1425
+ /**
1426
+ * Run a SELECT query as of a historical timestamp using CockroachDB's
1427
+ * `AS OF SYSTEM TIME` time-travel read feature.
1428
+ *
1429
+ * @param options - Standard SelectOptions plus the historical timestamp.
1430
+ * @param asOfSystemTime - Relative interval (e.g. `'-10s'`), ISO timestamp,
1431
+ * or `'follower_read_timestamp()'`.
1432
+ */
1433
+ queryAsOfSystemTime(options: SelectOptions, asOfSystemTime: string): Promise<QueryResult>;
1434
+ /**
1435
+ * Build a SELECT query with CockroachDB-specific features
1436
+ */
1437
+ buildSelectQuery(options: SelectOptions): {
1438
+ sql: string;
1439
+ values: unknown[];
1440
+ };
1441
+ /**
1442
+ * Escape a value for use in a CockroachDB array literal
1443
+ */
1444
+ escapeArray(values: unknown[]): string;
1445
+ /**
1446
+ * Build an array contains operator query (@>)
1447
+ * SELECT * FROM table WHERE column @> ARRAY['elem1', 'elem2']
1448
+ */
1449
+ buildArrayContains(column: string, values: unknown[]): string;
1450
+ /**
1451
+ * Build an array contained by operator query (<@)
1452
+ * SELECT * FROM table WHERE column <@ ARRAY['elem1', 'elem2']
1453
+ */
1454
+ buildArrayContainedBy(column: string, values: unknown[]): string;
1455
+ /**
1456
+ * Build an array overlaps operator query (&&)
1457
+ * SELECT * FROM table WHERE column && ARRAY['elem1', 'elem2']
1458
+ */
1459
+ buildArrayOverlaps(column: string, values: unknown[]): string;
1460
+ /**
1461
+ * Build an array ANY operator query
1462
+ * SELECT * FROM table WHERE 'value' = ANY(column)
1463
+ */
1464
+ buildArrayAny(column: string, value: unknown): string;
1465
+ /**
1466
+ * Build an array ALL operator query
1467
+ * SELECT * FROM table WHERE 'value' = ALL(column)
1468
+ * or with comparison: SELECT * FROM table WHERE value > ALL(column)
1469
+ */
1470
+ buildArrayAll(column: string, value: unknown, operator?: string): string;
1471
+ /**
1472
+ * Build a full-text search query
1473
+ */
1474
+ buildFullTextSearchQuery(tableName: string, searchColumns: string[], searchTerm: string, options?: {
1475
+ language?: string;
1476
+ ranking?: 'ts_rank' | 'ts_rank_cd';
1477
+ orderBy?: Order;
1478
+ }): {
1479
+ sql: string;
1480
+ values: unknown[];
1481
+ };
1482
+ /**
1483
+ * Build a JSON/JSONB path query
1484
+ */
1485
+ buildJsonPathQuery(column: string, path: string, value: unknown, operator: '=' | '!=' | '>' | '<' | '>=' | '<=' | '~' | '~*' | '@>' | '<@' | '?' | '?|'): {
1486
+ sql: string;
1487
+ values: unknown[];
1488
+ };
1489
+ /**
1490
+ * Get CockroachDB specific lock options
1491
+ */
1492
+ getLockOptions(lock: any): {
1493
+ sql: string;
1494
+ params: unknown[];
1495
+ };
1496
+ /**
1497
+ * Escape a single-quoted string value (replace ' with '').
1498
+ */
1499
+ private escapeStringValue;
1500
+ /**
1501
+ * Build the shared WITH-clause attribute list used by both CREATE USER and
1502
+ * ALTER USER. Returns a (possibly empty) array of attribute tokens.
1503
+ */
1504
+ private buildUserAttributes;
1505
+ /**
1506
+ * Build a CREATE USER statement.
1507
+ *
1508
+ * CockroachDB treats users as roles with LOGIN. Supported options:
1509
+ * ifNotExists, password, superuser, createdb, createrole, login,
1510
+ * replication, bypassrls, maxConnections, accountLocked, expirePassword,
1511
+ * defaultRole, requireSSL (noted but skipped — not a standard PG attribute).
1512
+ */
1513
+ buildCreateUserQuery(username: string, options?: any): string;
1514
+ /**
1515
+ * Build an ALTER USER statement.
1516
+ *
1517
+ * Supports the same attribute options as buildCreateUserQuery plus
1518
+ * `options.renameTo` to rename the role.
1519
+ */
1520
+ buildAlterUserQuery(username: string, options: any): string;
1521
+ /**
1522
+ * Build a DROP USER statement.
1523
+ *
1524
+ * Options: ifExists, cascade, restrict.
1525
+ */
1526
+ buildDropUserQuery(username: string, options?: any): string;
1527
+ /**
1528
+ * Return a query that lists all CockroachDB users (roles with LOGIN).
1529
+ */
1530
+ getUsersQuery(): string;
1531
+ /**
1532
+ * Create a database user
1533
+ */
1534
+ createUser(username: string, options?: Record<string, any>): Promise<void>;
1535
+ /**
1536
+ * Map a generic privilege name to a CockroachDB privilege name.
1537
+ * Returns null when the privilege has no CockroachDB equivalent and
1538
+ * should be silently skipped.
1539
+ */
1540
+ private mapPrivilege;
1541
+ /**
1542
+ * Build the ON <scope> clause for GRANT / REVOKE.
1543
+ *
1544
+ * Scope shapes:
1545
+ * { level: 'global' }
1546
+ * { level: 'database', database: 'dbname' }
1547
+ * { level: 'schema', schema: 'schemaname' }
1548
+ * { level: 'table', table: 'tablename' }
1549
+ * { level: 'column', table: 'tablename', columns: ['col1', 'col2'] }
1550
+ * { level: 'sequence', schema: 'schemaname' }
1551
+ */
1552
+ private buildGrantScope;
1553
+ /**
1554
+ * Build a GRANT statement.
1555
+ *
1556
+ * options.privileges — string | string[] (e.g. ['SELECT', 'INSERT'])
1557
+ * options.on — scope object (see buildGrantScope)
1558
+ * options.to — string | string[] (grantees)
1559
+ * options.withGrantOption — boolean
1560
+ * options.asUser — string (GRANTED BY, PG 14+)
1561
+ *
1562
+ * For column-level grants (options.on.level === 'column') the columns are
1563
+ * embedded in each privilege token: SELECT (col1, col2).
1564
+ */
1565
+ buildGrantQuery(options: any): string;
1566
+ /**
1567
+ * Build a REVOKE statement.
1568
+ *
1569
+ * options.privileges — string | string[]
1570
+ * options.on — scope object (same as buildGrantQuery)
1571
+ * options.from — string | string[] (revokees)
1572
+ * options.grantOptionFor — boolean (revoke only the GRANT OPTION)
1573
+ * options.cascade — boolean
1574
+ * options.restrict — boolean
1575
+ */
1576
+ buildRevokeQuery(options: any): string;
1577
+ /**
1578
+ * Return a query that shows the privileges granted to a specific user/role.
1579
+ * The optional `host` parameter is ignored — CockroachDB has no host concept.
1580
+ */
1581
+ buildShowGrantsQuery(username: string, _host?: string): string;
1582
+ /**
1583
+ * CockroachDB applies privilege changes automatically — FLUSH PRIVILEGES is
1584
+ * a MySQL concept. Return a no-op with an explanatory comment.
1585
+ */
1586
+ buildFlushPrivilegesQuery(): string;
1587
+ /**
1588
+ * Build a CREATE ROLE statement.
1589
+ *
1590
+ * Unlike CREATE USER, NOLOGIN is the default for roles. Pass
1591
+ * `options.login = true` to enable login.
1592
+ *
1593
+ * Supported options: ifNotExists, login, password, superuser, createdb,
1594
+ * createrole, inherit, replication, bypassrls, maxConnections,
1595
+ * expirePassword, accountLocked.
1596
+ */
1597
+ buildCreateRoleQuery(roleName: string, options?: any): string;
1598
+ /**
1599
+ * Build a DROP ROLE statement.
1600
+ *
1601
+ * Options: ifExists, cascade.
1602
+ */
1603
+ buildDropRoleQuery(roleName: string, options?: any): string;
1604
+ /**
1605
+ * Build a GRANT <role> TO <members> statement.
1606
+ *
1607
+ * Options: withAdminOption.
1608
+ */
1609
+ buildGrantRoleQuery(role: string, to: string | string[], options?: any): string;
1610
+ /**
1611
+ * Build a REVOKE <role> FROM <members> statement.
1612
+ *
1613
+ * Options: adminOptionFor, cascade.
1614
+ */
1615
+ buildRevokeRoleQuery(role: string, from: string | string[], options?: any): string;
1616
+ /**
1617
+ * Return a query that lists all CockroachDB roles that cannot log in
1618
+ * (i.e. "group roles" as opposed to user roles).
1619
+ */
1620
+ getRolesQuery(): string;
1621
+ /**
1622
+ * Generate SQL for creating a CockroachDB database
1623
+ */
1624
+ createDatabaseSQL(options: {
1625
+ name: string;
1626
+ encoding?: string;
1627
+ lcCollate?: string;
1628
+ lcCtype?: string;
1629
+ template?: string;
1630
+ tablespace?: string;
1631
+ isTemplate?: boolean;
1632
+ }): string;
1633
+ /**
1634
+ * Generate SQL for dropping a CockroachDB database
1635
+ */
1636
+ dropDatabaseSQL(name: string): string;
1637
+ /**
1638
+ * Generate SQL for creating a savepoint
1639
+ */
1640
+ createSavepointSQL(name?: string): string;
1641
+ /**
1642
+ * Generate SQL for releasing a savepoint
1643
+ */
1644
+ releaseSavepointSQL(name: string): string;
1645
+ /**
1646
+ * Generate SQL for rolling back to a savepoint
1647
+ */
1648
+ rollbackToSavepointSQL(name: string): string;
1649
+ /**
1650
+ * Build a JSON_TABLE-equivalent expression to shred a JSON array into relational rows.
1651
+ * Not supported: CockroachDB implements a subset of Postgres's JSONB function surface
1652
+ * and has neither a native `JSON_TABLE` (PG17+) nor `json_to_recordset`/
1653
+ * `jsonb_to_recordset` (verified absent from CockroachDB's function reference as of
1654
+ * v23.x/v24.x). There is no row-shredding equivalent to fall back to.
1655
+ */
1656
+ buildJsonTable(_jsonExpression: string, _rowPath: string, _columns: Array<{
1657
+ name: string;
1658
+ type?: string;
1659
+ path?: string;
1660
+ forOrdinality?: boolean;
1661
+ }>, _alias: string): string;
1662
+ }
1663
+ /**
1664
+ * CockroachDB-specific transaction class with isolation level support and savepoints
1665
+ */
1666
+ export declare class CockroachDBTransaction implements Transaction {
1667
+ id: string;
1668
+ finished: boolean;
1669
+ options: TransactionOptions;
1670
+ parent: Transaction | null;
1671
+ savepoints: string[];
1672
+ client: PoolClient | null;
1673
+ private savepointCount;
1674
+ constructor(client: PoolClient, depth: number, options?: TransactionOptions);
1675
+ /**
1676
+ * Create a savepoint
1677
+ */
1678
+ createSavepoint(name?: string): Promise<string>;
1679
+ /**
1680
+ * Rollback to a savepoint
1681
+ */
1682
+ rollbackToSavepoint(name: string): Promise<void>;
1683
+ /**
1684
+ * Release a savepoint
1685
+ */
1686
+ releaseSavepoint(name: string): Promise<void>;
1687
+ commit(): Promise<void>;
1688
+ rollback(): Promise<void>;
1689
+ }
1690
+ export interface CockroachDBDialectOptions extends DialectOptions {
1691
+ host?: string;
1692
+ port?: number;
1693
+ database?: string;
1694
+ username?: string;
1695
+ password?: string;
1696
+ ssl?: any;
1697
+ max?: number;
1698
+ idleTimeoutMillis?: number;
1699
+ connectionTimeoutMillis?: number;
1700
+ statementTimeout?: number;
1701
+ queryTimeout?: number;
1702
+ types?: any;
1703
+ }
1704
+ /**
1705
+ * Create a new CockroachDB dialect instance
1706
+ */
1707
+ export declare function createCockroachDBDialect(options?: CockroachDBDialectOptions): CockroachDBDialect;
1708
+ export default CockroachDBDialect;