ts-prorm-orm 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (460) hide show
  1. package/CHANGELOG.md +83 -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 +711 -0
  239. package/dist/index.js +19 -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
@@ -2,16 +2,30 @@
2
2
  /**
3
3
  * SQLite dialect implementation
4
4
  */
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
5
  Object.defineProperty(exports, "__esModule", { value: true });
9
6
  exports.SQLiteTransaction = exports.SQLiteDialect = void 0;
10
7
  exports.createSQLiteDialect = createSQLiteDialect;
11
- const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
8
+ const operators_1 = require("../../operators");
9
+ // Lazily-loaded `better-sqlite3` driver. This native addon is only loaded the
10
+ // first time a connection is opened, so importing this ORM never dlopens the
11
+ // better-sqlite3 native binding.
12
+ let betterSqlite3Ctor = null;
13
+ function loadBetterSqlite3() {
14
+ if (!betterSqlite3Ctor) {
15
+ try {
16
+ betterSqlite3Ctor = require('better-sqlite3');
17
+ }
18
+ catch (err) {
19
+ throw new Error("The 'better-sqlite3' package is required to use the SQLite dialect but could not be loaded. " +
20
+ 'Install it with `npm install better-sqlite3`. Original error: ' +
21
+ (err instanceof Error ? err.message : String(err)));
22
+ }
23
+ }
24
+ return betterSqlite3Ctor;
25
+ }
12
26
  const stream_1 = require("stream");
13
27
  const prorm_1 = require("../../prorm");
14
- const operators_1 = require("../../operators");
28
+ const operators_2 = require("../../operators");
15
29
  const sqlite_advanced_1 = require("../../sqlite-advanced");
16
30
  /**
17
31
  * SQLite dialect class that implements the Dialect interface
@@ -40,7 +54,7 @@ class SQLiteDialect {
40
54
  timeout: this.config.timeout || 5000,
41
55
  verbose: this.config.verbose || undefined,
42
56
  };
43
- this.connection = new better_sqlite3_1.default(this.config.storage, options);
57
+ this.connection = new (loadBetterSqlite3())(this.config.storage, options);
44
58
  this._isConnected = true;
45
59
  // Enable foreign keys by default
46
60
  this.connection.pragma('foreign_keys = ON');
@@ -722,9 +736,13 @@ class SQLiteDialect {
722
736
  let fkSql = `${name}FOREIGN KEY (${fields}) `;
723
737
  // Handle composite foreign keys (string | string[])
724
738
  const refField = constraint.references.field;
739
+ // Both branches must parenthesize - the single-column case previously
740
+ // emitted `REFERENCES "users""id"` (no parens, and the two quoted
741
+ // identifiers running together), which SQLite rejects as a syntax error.
742
+ // Every other dialect wraps this branch; sqlite was the outlier.
725
743
  const refFieldSql = Array.isArray(refField)
726
744
  ? `(${refField.map((f) => this.escapeId(f)).join(', ')})`
727
- : this.escapeId(refField);
745
+ : `(${this.escapeId(refField)})`;
728
746
  fkSql += `REFERENCES ${this.escapeId(constraint.references.table)}${refFieldSql}`;
729
747
  if (constraint.references.onDelete) {
730
748
  fkSql += ` ON DELETE ${constraint.references.onDelete}`;
@@ -1178,32 +1196,110 @@ class SQLiteDialect {
1178
1196
  * @param options - VACUUM options
1179
1197
  */
1180
1198
  async vacuum(options) {
1181
- return this.advanced.vacuum(options);
1199
+ // Inlined (async) so it also works over the Turso/libSQL wire.
1200
+ let sql = 'VACUUM';
1201
+ if (options?.schema)
1202
+ sql += ` ${options.schema}`;
1203
+ if (options?.shrinkTo !== undefined)
1204
+ sql += ` INTO 'shrink_${options.shrinkTo}.db'`;
1205
+ await this.query(sql);
1206
+ if (options?.analyze)
1207
+ await this.analyze();
1182
1208
  }
1183
1209
  /**
1184
1210
  * ANALYZE the database - updates statistics for query optimizer
1185
1211
  * @param target - Optional table or index name
1186
1212
  */
1187
1213
  async analyze(target) {
1188
- return this.advanced.analyze(target);
1214
+ await this.query(target ? `ANALYZE ${this.escapeId(target)}` : 'ANALYZE');
1189
1215
  }
1190
1216
  /**
1191
1217
  * Get database information using PRAGMA
1192
1218
  */
1193
1219
  async getDatabaseInfo() {
1194
- return this.advanced.getDatabaseInfo();
1220
+ // Inlined via async PRAGMA queries so it also works over Turso/libSQL.
1221
+ const pragma = async (name) => (await this.query(`PRAGMA ${name}`)).rows[0];
1222
+ const [sv, uv, fk, jm, sy, cs, ps] = await Promise.all([
1223
+ pragma('schema_version'),
1224
+ pragma('user_version'),
1225
+ pragma('foreign_keys'),
1226
+ pragma('journal_mode'),
1227
+ pragma('synchronous'),
1228
+ pragma('cache_size'),
1229
+ pragma('page_size'),
1230
+ ]);
1231
+ return {
1232
+ schemaVersion: sv?.schema_version,
1233
+ userVersion: uv?.user_version,
1234
+ foreignKeys: fk?.foreign_keys === 1,
1235
+ journalingMode: jm?.journal_mode,
1236
+ synchronous: sy?.synchronous,
1237
+ cacheSize: cs?.cache_size,
1238
+ pageSize: ps?.page_size,
1239
+ };
1195
1240
  }
1196
1241
  /**
1197
1242
  * Create an FTS5 virtual table for full-text search
1198
1243
  */
1199
1244
  async createFTS5Table(tableName, columns, options) {
1200
- return this.advanced.createFTS5Table(tableName, columns, options);
1245
+ // Built inline (rather than delegating to the sync `.advanced` API) so
1246
+ // this works over any async connection, including the Turso/libSQL wire
1247
+ // (which has no synchronous better-sqlite3 handle to back `.advanced`).
1248
+ const columnDefs = columns
1249
+ .map((col) => {
1250
+ let def = this.escapeId(col.name);
1251
+ if (col.type)
1252
+ def += ` ${col.type}`;
1253
+ if (col.notindexed)
1254
+ def += ' NOTINDEXED';
1255
+ return def;
1256
+ })
1257
+ .join(', ');
1258
+ let sql = `CREATE VIRTUAL TABLE ${this.escapeId(tableName)} USING fts5(${columnDefs}`;
1259
+ if (options?.tokenizer) {
1260
+ sql += `, tokenize='${options.tokenizer}'`;
1261
+ }
1262
+ if (options?.content) {
1263
+ sql += `, content='${options.content}'`;
1264
+ }
1265
+ if (options?.contentRowId) {
1266
+ sql += `, content_rowid='${options.contentRowId}'`;
1267
+ }
1268
+ if (options?.prefix) {
1269
+ sql += `, prefix='${Array.isArray(options.prefix) ? options.prefix.join(' ') : options.prefix}'`;
1270
+ }
1271
+ sql += ')';
1272
+ await this.query(sql);
1201
1273
  }
1202
1274
  /**
1203
1275
  * Perform full-text search
1204
1276
  */
1205
1277
  async fullTextSearch(ftsTable, searchQuery, options) {
1206
- return this.advanced.fullTextSearch(ftsTable, searchQuery, options);
1278
+ // Built inline so it works over any async connection (incl. Turso/libSQL).
1279
+ let sql = 'SELECT';
1280
+ if (options?.bm25) {
1281
+ sql += ` bm25(${this.escapeId(ftsTable)}) AS score, `;
1282
+ }
1283
+ else {
1284
+ sql += ' 0 AS score, ';
1285
+ }
1286
+ if (options?.highlight) {
1287
+ const col = options.highlight.column || '*';
1288
+ sql += ` highlight(${this.escapeId(ftsTable)}, ${options.columns?.indexOf(col) ?? 0}${options.highlight.before ? `, '${options.highlight.before}'` : ''}${options.highlight.after ? `, '${options.highlight.after}'` : ''}) AS highlighted, `;
1289
+ }
1290
+ sql += options?.columns?.map((c) => this.escapeId(c)).join(', ') || '*';
1291
+ sql += ` FROM ${this.escapeId(ftsTable)}`;
1292
+ sql += ` WHERE ${this.escapeId(ftsTable)} MATCH ?`;
1293
+ if (options?.orderBy) {
1294
+ sql += ` ORDER BY ${options.orderBy
1295
+ .map((o) => `${this.escapeId(o.column)}${o.desc ? ' DESC' : ''}`)
1296
+ .join(', ')}`;
1297
+ }
1298
+ if (options?.limit)
1299
+ sql += ` LIMIT ${options.limit}`;
1300
+ if (options?.offset)
1301
+ sql += ` OFFSET ${options.offset}`;
1302
+ return this.query(sql, { replacements: [searchQuery] });
1207
1303
  }
1208
1304
  // ==================== Stored Procedures ====================
1209
1305
  // SQLite does not support stored procedures natively
@@ -1360,19 +1456,42 @@ class SQLiteDialect {
1360
1456
  * Create a trigger
1361
1457
  */
1362
1458
  async createTrigger(triggerName, timing, events, tableName, body, options) {
1363
- return this.advanced.createTrigger(triggerName, timing, events, tableName, body, options);
1459
+ // Built inline (rather than delegating to the sync `.advanced` API) so
1460
+ // triggers can be created over any async connection, including Turso/libSQL.
1461
+ // SQLite has no `CREATE OR REPLACE TRIGGER`; emulate `replace` by dropping first.
1462
+ if (options?.replace) {
1463
+ await this.dropTrigger(triggerName, { ifExists: true });
1464
+ }
1465
+ let sql = `CREATE TRIGGER ${this.escapeId(triggerName)}`;
1466
+ sql += ` ${timing} ${(events || []).join(' OR ')} ON ${this.escapeId(tableName)}`;
1467
+ if (options?.forEachRow)
1468
+ sql += ' FOR EACH ROW';
1469
+ if (options?.whenCondition)
1470
+ sql += ` WHEN ${options.whenCondition}`;
1471
+ sql += `\nBEGIN\n${body}\nEND`;
1472
+ await this.query(sql);
1364
1473
  }
1365
1474
  /**
1366
1475
  * Drop a trigger
1367
1476
  */
1368
1477
  async dropTrigger(triggerName, options) {
1369
- return this.advanced.dropTrigger(triggerName, options);
1478
+ let sql = 'DROP TRIGGER';
1479
+ if (options?.ifExists)
1480
+ sql += ' IF EXISTS';
1481
+ sql += ` ${this.escapeId(triggerName)}`;
1482
+ await this.query(sql);
1370
1483
  }
1371
- async hasTrigger(_triggerName, _tableName) {
1372
- // Check if trigger exists
1373
- const sql = `SELECT name FROM sqlite_master WHERE type='trigger' AND name=?`;
1374
- const result = await this.query(sql, { plain: true });
1375
- return !!result;
1484
+ async hasTrigger(triggerName, tableName) {
1485
+ // Bind the trigger name (the previous implementation passed `{ plain: true }`
1486
+ // as the options object, so the `?` placeholder was never bound and the
1487
+ // check matched *any* trigger). Optionally scope to a table.
1488
+ const sql = tableName
1489
+ ? `SELECT name FROM sqlite_master WHERE type='trigger' AND name = ? AND tbl_name = ?`
1490
+ : `SELECT name FROM sqlite_master WHERE type='trigger' AND name = ?`;
1491
+ const result = await this.query(sql, {
1492
+ replacements: tableName ? [triggerName, tableName] : [triggerName],
1493
+ });
1494
+ return result.rows.length > 0;
1376
1495
  }
1377
1496
  // ==================== Sequences ====================
1378
1497
  // SQLite does not have native sequences, but they can be simulated
@@ -2009,7 +2128,7 @@ class SQLiteDialect {
2009
2128
  const topSymbols = Object.getOwnPropertySymbols(rawCond);
2010
2129
  const normalizedCond = { ...rawCond };
2011
2130
  for (const sym of topSymbols) {
2012
- const strKey = (0, operators_1.operatorToWhereKey)(sym);
2131
+ const strKey = (0, operators_2.operatorToWhereKey)(sym);
2013
2132
  if (strKey)
2014
2133
  normalizedCond[strKey] = rawCond[sym];
2015
2134
  }
@@ -2064,7 +2183,7 @@ class SQLiteDialect {
2064
2183
  const symbolKeys = Object.getOwnPropertySymbols(rawValueObj);
2065
2184
  const normalizedObj = { ...rawValueObj };
2066
2185
  for (const sym of symbolKeys) {
2067
- const strKey = (0, operators_1.operatorToWhereKey)(sym);
2186
+ const strKey = (0, operators_2.operatorToWhereKey)(sym);
2068
2187
  if (strKey)
2069
2188
  normalizedObj[strKey] = rawValueObj[sym];
2070
2189
  }
@@ -2546,6 +2665,15 @@ class SQLiteDialect {
2546
2665
  /**
2547
2666
  * Check if a value is a literal expression (literal('sql'))
2548
2667
  */
2668
+ /**
2669
+ * Render a literal expression, substituting any `bindings` into its `?`
2670
+ * placeholders with dialect-correct escaping. `literalExpr(sql)` with no
2671
+ * bindings is unchanged; `literalExpr('x > ?', [v])` no longer requires the
2672
+ * caller to concatenate the value into the string themselves.
2673
+ */
2674
+ literalSql(expr) {
2675
+ return (0, operators_1.expandLiteralBindings)(expr, (v) => this.escape(v));
2676
+ }
2549
2677
  isLiteralExpression(value) {
2550
2678
  return value !== null && typeof value === 'object' && value.__type === 'literal';
2551
2679
  }
@@ -2589,7 +2717,7 @@ class SQLiteDialect {
2589
2717
  sql = this.escapeId(expr.col);
2590
2718
  }
2591
2719
  else if (this.isLiteralExpression(expr)) {
2592
- sql = expr.sql;
2720
+ sql = this.literalSql(expr);
2593
2721
  }
2594
2722
  else if (typeof expr === 'string') {
2595
2723
  // Check if it's a column reference or literal SQL
@@ -2613,7 +2741,7 @@ class SQLiteDialect {
2613
2741
  return this.escapeId(attr.col);
2614
2742
  }
2615
2743
  else if (this.isLiteralExpression(attr)) {
2616
- return attr.sql;
2744
+ return this.literalSql(attr);
2617
2745
  }
2618
2746
  else if (typeof attr === 'string') {
2619
2747
  // Plain column name
@@ -2653,7 +2781,7 @@ class SQLiteDialect {
2653
2781
  sql = this.escapeId(expr.col);
2654
2782
  }
2655
2783
  else if (this.isLiteralExpression(expr)) {
2656
- sql = expr.sql;
2784
+ sql = this.literalSql(expr);
2657
2785
  }
2658
2786
  else if (typeof expr === 'string') {
2659
2787
  sql = this.escapeId(expr);
@@ -2674,7 +2802,7 @@ class SQLiteDialect {
2674
2802
  return this.escapeId(field.col);
2675
2803
  }
2676
2804
  else if (this.isLiteralExpression(field)) {
2677
- return field.sql;
2805
+ return this.literalSql(field);
2678
2806
  }
2679
2807
  else if (typeof field === 'string') {
2680
2808
  if (field.includes('.')) {
@@ -2879,7 +3007,7 @@ class SQLiteDialect {
2879
3007
  // older { val }/{ fn }/{ col }/{ literal } shapes) and end up stringified
2880
3008
  // as "[object Object]", producing invalid SQL like "[object Object] AS alias".
2881
3009
  if (attr && typeof attr === 'object' && attr.__type === 'literal' && typeof attr.sql === 'string') {
2882
- return attr.sql;
3010
+ return this.literalSql(attr);
2883
3011
  }
2884
3012
  if (attr && typeof attr === 'object' && attr.__type === 'col' && typeof attr.col === 'string') {
2885
3013
  return this.escapeId(attr.col);
@@ -3211,9 +3339,7 @@ class SQLiteDialect {
3211
3339
  const lastParen = createSql.lastIndexOf(')');
3212
3340
  const newCreateSql = createSql.slice(0, lastParen).trimEnd() + `,\n ${fkClause}\n` + createSql.slice(lastParen);
3213
3341
  const tmpName = `${tableName}__fk_rebuild`;
3214
- // Setter PRAGMAs don't return rows, so run them via exec() rather than query()
3215
- // (which would try stmt.all() and throw "statement does not return data").
3216
- this.connection?.exec('PRAGMA foreign_keys=OFF');
3342
+ await this.setPragma('foreign_keys=OFF');
3217
3343
  try {
3218
3344
  await this.query(`ALTER TABLE ${this.quoteTable(tableName)} RENAME TO ${this.escapeId(tmpName)}`);
3219
3345
  await this.query(newCreateSql);
@@ -3221,9 +3347,21 @@ class SQLiteDialect {
3221
3347
  await this.query(`DROP TABLE ${this.escapeId(tmpName)}`);
3222
3348
  }
3223
3349
  finally {
3224
- this.connection?.exec('PRAGMA foreign_keys=ON');
3350
+ await this.setPragma('foreign_keys=ON');
3225
3351
  }
3226
3352
  }
3353
+ /**
3354
+ * Run a setter PRAGMA (one that returns no rows).
3355
+ *
3356
+ * On better-sqlite3 this must go through the synchronous `exec()` API:
3357
+ * routing it through `query()` would call `stmt.all()` and throw
3358
+ * "statement does not return data". Subclasses that don't have a
3359
+ * synchronous connection (e.g. TursoDialect over the libSQL wire) override
3360
+ * this to run the PRAGMA through their async driver instead.
3361
+ */
3362
+ async setPragma(pragma) {
3363
+ this.connection?.exec(`PRAGMA ${pragma}`);
3364
+ }
3227
3365
  /**
3228
3366
  * Rename a column
3229
3367
  */
@@ -0,0 +1,226 @@
1
+ /**
2
+ * TiDB dialect implementation for the TypeScript ORM
3
+ *
4
+ * TiDB is MySQL-wire-protocol compatible: it speaks the MySQL client/server
5
+ * protocol and understands (almost all of) MySQL's SQL grammar, so this
6
+ * dialect extends {@link MySQLDialect} and reuses MySQL's `mysql2` driver
7
+ * verbatim (connection pooling, escaping, query execution, streaming, most
8
+ * DDL/DML builders). Only the genuine TiDB grammar differences are overridden
9
+ * or added here.
10
+ *
11
+ * Differences from plain MySQL implemented in this dialect:
12
+ *
13
+ * - **Dialect identity**: `name` is `'tidb'` (the wire `library` stays
14
+ * `'mysql2'` since that's the actual driver in use).
15
+ * - **Default port 4000**: TiDB's default SQL port is 4000, not MySQL's 3306.
16
+ * The constructor injects it as a default that the caller can still override.
17
+ * - **AUTO_RANDOM primary keys**: TiDB offers `AUTO_RANDOM` as an alternative
18
+ * to `AUTO_INCREMENT` for (BIGINT) primary keys. It scatters generated IDs
19
+ * across the key space to avoid the write hot-spotting that a monotonic
20
+ * `AUTO_INCREMENT` key causes on a range-partitioned distributed store. A
21
+ * column flag (`autoRandom: true` or `autoRandom: <shardBits>`) emits
22
+ * `AUTO_RANDOM` / `AUTO_RANDOM(n)` instead of `AUTO_INCREMENT`.
23
+ * - **SHARD_ROW_ID_BITS / PRE_SPLIT_REGIONS**: TiDB table options (for tables
24
+ * without an integer PK) that shard the implicit `_tidb_rowid` and
25
+ * pre-split the table into multiple regions up front to spread write load.
26
+ * Both are supported as CREATE TABLE options and are not valid MySQL syntax.
27
+ * - **SPLIT TABLE**: TiDB-only statement to pre-split a table/index's key
28
+ * range into N regions (`SPLIT TABLE t BETWEEN (...) AND (...) REGIONS n`).
29
+ * Not standard MySQL, so it's exposed as a dedicated helper.
30
+ * - **Storage engines**: TiDB parses but effectively ignores MySQL
31
+ * storage-engine clauses such as `ENGINE=InnoDB` (all TiDB tables live in
32
+ * its distributed KV store / TiKV; there is no per-table pluggable engine).
33
+ * The `engine` table option is still emitted for MySQL source compatibility,
34
+ * but has no effect on TiDB — documented here so callers don't rely on it.
35
+ */
36
+ import { MySQLDialect, MySQLDialectOptions } from '../mysql/index';
37
+ import { ColumnDefinition, TableOptions, InsertOptions } from '../dialect';
38
+ import { DataType } from '../../types';
39
+ /**
40
+ * TiDB connection options. Identical to {@link MySQLDialectOptions} (the same
41
+ * `mysql2` driver is used); declared as its own type for clarity and so the
42
+ * default port can differ.
43
+ */
44
+ export interface TiDBDialectOptions extends MySQLDialectOptions {
45
+ }
46
+ /**
47
+ * TiDB-specific column definition: adds `autoRandom`, TiDB's alternative to
48
+ * `AUTO_INCREMENT` for primary-key columns.
49
+ */
50
+ export interface TiDBColumnDefinition extends ColumnDefinition {
51
+ /**
52
+ * Emit `AUTO_RANDOM` instead of `AUTO_INCREMENT` for this (BIGINT primary
53
+ * key) column. `true` emits a bare `AUTO_RANDOM`; a number emits
54
+ * `AUTO_RANDOM(n)` where `n` is the shard-bit count. Takes precedence over
55
+ * `autoIncrement` when both are set.
56
+ */
57
+ autoRandom?: boolean | number;
58
+ }
59
+ /**
60
+ * TiDB-specific CREATE TABLE options: `SHARD_ROW_ID_BITS` and
61
+ * `PRE_SPLIT_REGIONS`. Both are TiDB extensions (not valid in MySQL).
62
+ */
63
+ export interface TiDBTableOptions extends TableOptions {
64
+ /**
65
+ * `SHARD_ROW_ID_BITS = n` — number of bits used to shard the implicit
66
+ * `_tidb_rowid` for tables that have no integer primary key (or a non-clustered
67
+ * PK), spreading inserts across regions instead of appending to one hot region.
68
+ */
69
+ shardRowIdBits?: number;
70
+ /**
71
+ * `PRE_SPLIT_REGIONS = n` — pre-split the table into 2^n regions at creation
72
+ * time (used together with `SHARD_ROW_ID_BITS` / `AUTO_RANDOM`) so the write
73
+ * load is distributed immediately rather than after the table grows.
74
+ */
75
+ preSplitRegions?: number;
76
+ }
77
+ /**
78
+ * Options for {@link TiDBDialect.buildSplitTableSql} / {@link TiDBDialect.splitTable}.
79
+ */
80
+ export interface TiDBSplitTableOptions {
81
+ /**
82
+ * Inclusive lower and upper bound of the key range to split, as a
83
+ * `[lower, upper]` tuple. Each element is emitted inside `(...)` — a single
84
+ * value, or a comma-joined list for composite keys.
85
+ */
86
+ between: [unknown | unknown[], unknown | unknown[]];
87
+ /** Number of regions to split the range into. */
88
+ regions: number;
89
+ /**
90
+ * Optional index name. When provided, splits that index's key range
91
+ * (`SPLIT TABLE t INDEX idx BETWEEN ...`) instead of the table's row range.
92
+ */
93
+ index?: string;
94
+ }
95
+ /**
96
+ * TiDB dialect. MySQL-wire-compatible; reuses the `mysql2` driver via
97
+ * {@link MySQLDialect}. See the file header for the full list of differences.
98
+ */
99
+ export declare class TiDBDialect extends MySQLDialect {
100
+ readonly name = "tidb";
101
+ constructor(config?: TiDBDialectOptions);
102
+ /**
103
+ * Build the column-definition SQL fragment for a single column, with TiDB's
104
+ * `AUTO_RANDOM` support. MySQL's own column builder is `private`, so this
105
+ * dialect implements its own (covering the same common flags) rather than
106
+ * reusing it.
107
+ */
108
+ private buildColumnSql;
109
+ /** Escape single quotes/backslashes for embedding a string literal. */
110
+ private escapeSqlString;
111
+ /** Render a column DEFAULT value. */
112
+ private formatDefaultValue;
113
+ /**
114
+ * Build a TiDB `CREATE TABLE` statement, supporting `AUTO_RANDOM` primary
115
+ * keys and the `SHARD_ROW_ID_BITS` / `PRE_SPLIT_REGIONS` table options.
116
+ * Pure/synchronous — returns the SQL string without executing it.
117
+ */
118
+ buildCreateTableSql(tableName: string, columns: Record<string, TiDBColumnDefinition>, options?: TiDBTableOptions): string;
119
+ /**
120
+ * Create a table using TiDB grammar (AUTO_RANDOM, SHARD_ROW_ID_BITS,
121
+ * PRE_SPLIT_REGIONS). Overrides the MySQL implementation, whose private
122
+ * column builder cannot emit `AUTO_RANDOM`.
123
+ */
124
+ createTable(tableName: string, columns: Record<string, ColumnDefinition>, options?: TableOptions): Promise<void>;
125
+ /**
126
+ * Build an INSERT query. Identical to the MySQL builder except that when
127
+ * `options.upsert` is set, the `ON DUPLICATE KEY UPDATE` clause uses the
128
+ * TiDB-compatible `VALUES(col)` function form rather than MySQL 8.0.19's
129
+ * row-alias (`AS new_vals`) form, which TiDB rejects.
130
+ */
131
+ buildInsertQuery(tableName: string, values: Record<string, unknown>, options?: InsertOptions): {
132
+ sql: string;
133
+ values: unknown[];
134
+ };
135
+ /**
136
+ * Build an UPSERT query using TiDB-compatible `ON DUPLICATE KEY UPDATE col =
137
+ * VALUES(col)` syntax (the base MySQL dialect emits the row-alias form that
138
+ * TiDB does not accept). TiDB, like MySQL, has no `RETURNING` clause.
139
+ */
140
+ buildUpsertQuery(tableName: string, values: Record<string, unknown>, options?: {
141
+ conflictFields?: string[];
142
+ updateOnDuplicate?: string[];
143
+ returning?: boolean | string[];
144
+ }): {
145
+ sql: string;
146
+ values: unknown[];
147
+ };
148
+ /**
149
+ * Map an ORM {@link DataType} to TiDB column SQL. Delegates to the MySQL
150
+ * mapping for everything TiDB shares, but rejects the spatial/GIS types up
151
+ * front: TiDB implements no spatial data types (GEOMETRY, POINT, POLYGON,
152
+ * …), so emitting them would produce a `CREATE TABLE` that a real TiDB
153
+ * server rejects. Failing here gives a clear, actionable error instead of
154
+ * an opaque server-side parse error.
155
+ */
156
+ getDataTypeSql(dataType: DataType): string;
157
+ /**
158
+ * Build an `ALTER TABLE ... ADD CONSTRAINT` statement (synchronous).
159
+ */
160
+ buildAddConstraintSql(tableName: string, options: {
161
+ type: 'UNIQUE' | 'CHECK' | 'PRIMARY KEY' | 'FOREIGN KEY';
162
+ fields: string[];
163
+ name?: string;
164
+ references?: {
165
+ table: string;
166
+ fields: string[];
167
+ };
168
+ check?: string;
169
+ }): string;
170
+ /**
171
+ * Build an `ALTER TABLE ... DROP ...` statement for a constraint
172
+ * (synchronous). TiDB (like MySQL) drops each constraint kind with a
173
+ * different clause, so the caller passes the constraint `type`; when omitted
174
+ * a generic `DROP CONSTRAINT` (valid for CHECK constraints) is emitted.
175
+ */
176
+ buildDropConstraintSql(tableName: string, constraintName: string, type?: 'UNIQUE' | 'CHECK' | 'PRIMARY KEY' | 'FOREIGN KEY'): string;
177
+ /**
178
+ * Add a constraint to an existing table (TiDB supports this; MySQL base
179
+ * throws). Executes {@link buildAddConstraintSql}.
180
+ */
181
+ addConstraint(tableName: string, options: {
182
+ type: 'UNIQUE' | 'CHECK' | 'PRIMARY KEY' | 'FOREIGN KEY';
183
+ fields: string[];
184
+ name?: string;
185
+ references?: {
186
+ table: string;
187
+ fields: string[];
188
+ };
189
+ check?: string;
190
+ }): Promise<void>;
191
+ /**
192
+ * Drop a constraint from a table by name. Emits a generic
193
+ * `ALTER TABLE ... DROP CONSTRAINT name` (valid on TiDB for CHECK
194
+ * constraints); for foreign keys / unique keys / primary keys use
195
+ * {@link buildDropConstraintSql} with an explicit `type`.
196
+ */
197
+ removeConstraint(tableName: string, constraintName: string): Promise<void>;
198
+ /**
199
+ * TiDB implements no spatial/GIS data types, so a spatial index has nothing
200
+ * to index and a real server rejects it. Fail up front with a clear,
201
+ * actionable error (mirrors {@link getDataTypeSql}'s spatial-type rejection)
202
+ * instead of surfacing an opaque server-side parse error.
203
+ */
204
+ createSpatialIndex(_tableName: string, _indexName: string, _fields: string[], _options?: {
205
+ storage?: string;
206
+ srid?: number;
207
+ }): Promise<void>;
208
+ /**
209
+ * Build a TiDB `SPLIT TABLE` statement. This pre-splits a table's (or an
210
+ * index's) key range into `regions` regions, distributing write load before
211
+ * data arrives. Not standard MySQL. Pure/synchronous.
212
+ *
213
+ * @example
214
+ * // SPLIT TABLE `t` BETWEEN (0) AND (1000000) REGIONS 16
215
+ * dialect.buildSplitTableSql('t', { between: [0, 1000000], regions: 16 });
216
+ */
217
+ buildSplitTableSql(tableName: string, options: TiDBSplitTableOptions): string;
218
+ /**
219
+ * Execute a {@link buildSplitTableSql} statement.
220
+ */
221
+ splitTable(tableName: string, options: TiDBSplitTableOptions): Promise<void>;
222
+ }
223
+ /**
224
+ * Convenience factory mirroring `createMySQLDialect`.
225
+ */
226
+ export declare function createTiDBDialect(options?: TiDBDialectOptions): TiDBDialect;
@@ -341,6 +341,16 @@ class TiDBDialect extends index_1.MySQLDialect {
341
341
  async removeConstraint(tableName, constraintName) {
342
342
  await this.query(this.buildDropConstraintSql(tableName, constraintName));
343
343
  }
344
+ /**
345
+ * TiDB implements no spatial/GIS data types, so a spatial index has nothing
346
+ * to index and a real server rejects it. Fail up front with a clear,
347
+ * actionable error (mirrors {@link getDataTypeSql}'s spatial-type rejection)
348
+ * instead of surfacing an opaque server-side parse error.
349
+ */
350
+ async createSpatialIndex(_tableName, _indexName, _fields, _options) {
351
+ throw new Error('TiDB does not support spatial indexes (it has no spatial/GIS data types). ' +
352
+ 'Store geometry as JSON/TEXT or numeric columns and index those instead.');
353
+ }
344
354
  /**
345
355
  * Build a TiDB `SPLIT TABLE` statement. This pre-splits a table's (or an
346
356
  * index's) key range into `regions` regions, distributing write load before