relq 1.0.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 (305) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +862 -0
  3. package/dist/addons/buffer.js +1869 -0
  4. package/dist/addons/pg-cursor.js +1425 -0
  5. package/dist/addons/pg-format.js +2248 -0
  6. package/dist/addons/pg.js +4790 -0
  7. package/dist/bin/relq.js +2 -0
  8. package/dist/cjs/cache/index.cjs +9 -0
  9. package/dist/cjs/cache/query-cache.cjs +311 -0
  10. package/dist/cjs/cli/commands/add.cjs +82 -0
  11. package/dist/cjs/cli/commands/commit.cjs +145 -0
  12. package/dist/cjs/cli/commands/diff.cjs +84 -0
  13. package/dist/cjs/cli/commands/export.cjs +333 -0
  14. package/dist/cjs/cli/commands/fetch.cjs +59 -0
  15. package/dist/cjs/cli/commands/generate.cjs +242 -0
  16. package/dist/cjs/cli/commands/history.cjs +165 -0
  17. package/dist/cjs/cli/commands/import.cjs +524 -0
  18. package/dist/cjs/cli/commands/init.cjs +437 -0
  19. package/dist/cjs/cli/commands/introspect.cjs +142 -0
  20. package/dist/cjs/cli/commands/log.cjs +62 -0
  21. package/dist/cjs/cli/commands/migrate.cjs +167 -0
  22. package/dist/cjs/cli/commands/pull.cjs +410 -0
  23. package/dist/cjs/cli/commands/push.cjs +165 -0
  24. package/dist/cjs/cli/commands/rollback.cjs +169 -0
  25. package/dist/cjs/cli/commands/status.cjs +110 -0
  26. package/dist/cjs/cli/commands/sync.cjs +79 -0
  27. package/dist/cjs/cli/index.cjs +275 -0
  28. package/dist/cjs/cli/utils/change-tracker.cjs +446 -0
  29. package/dist/cjs/cli/utils/commit-manager.cjs +239 -0
  30. package/dist/cjs/cli/utils/config-loader.cjs +127 -0
  31. package/dist/cjs/cli/utils/env-loader.cjs +62 -0
  32. package/dist/cjs/cli/utils/fast-introspect.cjs +398 -0
  33. package/dist/cjs/cli/utils/git-utils.cjs +404 -0
  34. package/dist/cjs/cli/utils/migration-generator.cjs +269 -0
  35. package/dist/cjs/cli/utils/relqignore.cjs +114 -0
  36. package/dist/cjs/cli/utils/repo-manager.cjs +515 -0
  37. package/dist/cjs/cli/utils/schema-comparator.cjs +313 -0
  38. package/dist/cjs/cli/utils/schema-diff.cjs +284 -0
  39. package/dist/cjs/cli/utils/schema-hash.cjs +108 -0
  40. package/dist/cjs/cli/utils/schema-introspect.cjs +455 -0
  41. package/dist/cjs/cli/utils/snapshot-manager.cjs +223 -0
  42. package/dist/cjs/cli/utils/spinner.cjs +108 -0
  43. package/dist/cjs/cli/utils/sql-generator.cjs +520 -0
  44. package/dist/cjs/cli/utils/sql-parser.cjs +999 -0
  45. package/dist/cjs/cli/utils/type-generator.cjs +2061 -0
  46. package/dist/cjs/condition/array-condition-builder.cjs +503 -0
  47. package/dist/cjs/condition/array-numeric-condition-builder.cjs +186 -0
  48. package/dist/cjs/condition/array-specialized-condition-builder.cjs +206 -0
  49. package/dist/cjs/condition/array-string-condition-builder.cjs +146 -0
  50. package/dist/cjs/condition/base-condition-builder.cjs +2 -0
  51. package/dist/cjs/condition/condition-collector.cjs +284 -0
  52. package/dist/cjs/condition/fulltext-condition-builder.cjs +61 -0
  53. package/dist/cjs/condition/geometric-condition-builder.cjs +208 -0
  54. package/dist/cjs/condition/index.cjs +25 -0
  55. package/dist/cjs/condition/jsonb-condition-builder.cjs +160 -0
  56. package/dist/cjs/condition/network-condition-builder.cjs +230 -0
  57. package/dist/cjs/condition/range-condition-builder.cjs +82 -0
  58. package/dist/cjs/config/config.cjs +190 -0
  59. package/dist/cjs/config/index.cjs +9 -0
  60. package/dist/cjs/constants/pg-values.cjs +68 -0
  61. package/dist/cjs/copy/copy-builder.cjs +316 -0
  62. package/dist/cjs/copy/index.cjs +6 -0
  63. package/dist/cjs/core/query-builder.cjs +440 -0
  64. package/dist/cjs/core/relq-client.cjs +1831 -0
  65. package/dist/cjs/core/typed-kuery-client.cjs +2 -0
  66. package/dist/cjs/count/count-builder.cjs +88 -0
  67. package/dist/cjs/count/index.cjs +5 -0
  68. package/dist/cjs/cte/cte-builder.cjs +89 -0
  69. package/dist/cjs/cte/index.cjs +5 -0
  70. package/dist/cjs/ddl/function.cjs +48 -0
  71. package/dist/cjs/ddl/index.cjs +7 -0
  72. package/dist/cjs/ddl/sql.cjs +54 -0
  73. package/dist/cjs/delete/delete-builder.cjs +135 -0
  74. package/dist/cjs/delete/index.cjs +5 -0
  75. package/dist/cjs/errors/relq-errors.cjs +329 -0
  76. package/dist/cjs/examples/fulltext-search-test.cjs +122 -0
  77. package/dist/cjs/explain/explain-builder.cjs +99 -0
  78. package/dist/cjs/explain/index.cjs +5 -0
  79. package/dist/cjs/function/create-function-builder.cjs +196 -0
  80. package/dist/cjs/function/index.cjs +6 -0
  81. package/dist/cjs/functions/advanced-functions.cjs +241 -0
  82. package/dist/cjs/functions/case-builder.cjs +66 -0
  83. package/dist/cjs/functions/geometric-functions.cjs +104 -0
  84. package/dist/cjs/functions/index.cjs +184 -0
  85. package/dist/cjs/functions/network-functions.cjs +86 -0
  86. package/dist/cjs/functions/sql-functions.cjs +431 -0
  87. package/dist/cjs/index.cjs +164 -0
  88. package/dist/cjs/indexing/create-index-builder.cjs +187 -0
  89. package/dist/cjs/indexing/drop-index-builder.cjs +89 -0
  90. package/dist/cjs/indexing/index-types.cjs +2 -0
  91. package/dist/cjs/indexing/index.cjs +8 -0
  92. package/dist/cjs/insert/conflict-builder.cjs +173 -0
  93. package/dist/cjs/insert/index.cjs +5 -0
  94. package/dist/cjs/insert/insert-builder.cjs +254 -0
  95. package/dist/cjs/introspect/index.cjs +229 -0
  96. package/dist/cjs/maintenance/index.cjs +6 -0
  97. package/dist/cjs/maintenance/vacuum-builder.cjs +166 -0
  98. package/dist/cjs/pubsub/index.cjs +7 -0
  99. package/dist/cjs/pubsub/listen-notify-builder.cjs +57 -0
  100. package/dist/cjs/pubsub/listener-connection.cjs +180 -0
  101. package/dist/cjs/raw/index.cjs +5 -0
  102. package/dist/cjs/raw/raw-query-builder.cjs +27 -0
  103. package/dist/cjs/schema/index.cjs +15 -0
  104. package/dist/cjs/schema/schema-builder.cjs +1167 -0
  105. package/dist/cjs/schema-builder.cjs +21 -0
  106. package/dist/cjs/schema-definition/column-types.cjs +829 -0
  107. package/dist/cjs/schema-definition/index.cjs +62 -0
  108. package/dist/cjs/schema-definition/introspection.cjs +620 -0
  109. package/dist/cjs/schema-definition/partitions.cjs +129 -0
  110. package/dist/cjs/schema-definition/pg-enum.cjs +76 -0
  111. package/dist/cjs/schema-definition/pg-function.cjs +91 -0
  112. package/dist/cjs/schema-definition/pg-sequence.cjs +56 -0
  113. package/dist/cjs/schema-definition/pg-trigger.cjs +108 -0
  114. package/dist/cjs/schema-definition/relations.cjs +98 -0
  115. package/dist/cjs/schema-definition/sql-expressions.cjs +202 -0
  116. package/dist/cjs/schema-definition/table-definition.cjs +636 -0
  117. package/dist/cjs/select/aggregate-builder.cjs +179 -0
  118. package/dist/cjs/select/index.cjs +5 -0
  119. package/dist/cjs/select/select-builder.cjs +233 -0
  120. package/dist/cjs/sequence/index.cjs +7 -0
  121. package/dist/cjs/sequence/sequence-builder.cjs +264 -0
  122. package/dist/cjs/table/alter-table-builder.cjs +146 -0
  123. package/dist/cjs/table/constraint-builder.cjs +102 -0
  124. package/dist/cjs/table/create-table-builder.cjs +248 -0
  125. package/dist/cjs/table/index.cjs +17 -0
  126. package/dist/cjs/table/partition-builder.cjs +131 -0
  127. package/dist/cjs/table/truncate-builder.cjs +70 -0
  128. package/dist/cjs/transaction/index.cjs +6 -0
  129. package/dist/cjs/transaction/transaction-builder.cjs +78 -0
  130. package/dist/cjs/trigger/create-trigger-builder.cjs +174 -0
  131. package/dist/cjs/trigger/index.cjs +6 -0
  132. package/dist/cjs/types/aggregate-types.cjs +2 -0
  133. package/dist/cjs/types/config-types.cjs +40 -0
  134. package/dist/cjs/types/inference-types.cjs +18 -0
  135. package/dist/cjs/types/pagination-types.cjs +7 -0
  136. package/dist/cjs/types/result-types.cjs +2 -0
  137. package/dist/cjs/types/schema-types.cjs +2 -0
  138. package/dist/cjs/types/subscription-types.cjs +2 -0
  139. package/dist/cjs/types.cjs +2 -0
  140. package/dist/cjs/update/array-update-builder.cjs +205 -0
  141. package/dist/cjs/update/index.cjs +13 -0
  142. package/dist/cjs/update/update-builder.cjs +195 -0
  143. package/dist/cjs/utils/case-converter.cjs +58 -0
  144. package/dist/cjs/utils/environment-detection.cjs +120 -0
  145. package/dist/cjs/utils/index.cjs +10 -0
  146. package/dist/cjs/utils/pool-defaults.cjs +106 -0
  147. package/dist/cjs/utils/type-coercion.cjs +118 -0
  148. package/dist/cjs/view/create-view-builder.cjs +180 -0
  149. package/dist/cjs/view/index.cjs +7 -0
  150. package/dist/cjs/window/index.cjs +5 -0
  151. package/dist/cjs/window/window-builder.cjs +80 -0
  152. package/dist/config.cjs +1 -0
  153. package/dist/config.d.ts +655 -0
  154. package/dist/config.js +1 -0
  155. package/dist/esm/cache/index.js +1 -0
  156. package/dist/esm/cache/query-cache.js +303 -0
  157. package/dist/esm/cli/commands/add.js +78 -0
  158. package/dist/esm/cli/commands/commit.js +109 -0
  159. package/dist/esm/cli/commands/diff.js +81 -0
  160. package/dist/esm/cli/commands/export.js +297 -0
  161. package/dist/esm/cli/commands/fetch.js +56 -0
  162. package/dist/esm/cli/commands/generate.js +206 -0
  163. package/dist/esm/cli/commands/history.js +129 -0
  164. package/dist/esm/cli/commands/import.js +488 -0
  165. package/dist/esm/cli/commands/init.js +401 -0
  166. package/dist/esm/cli/commands/introspect.js +106 -0
  167. package/dist/esm/cli/commands/log.js +59 -0
  168. package/dist/esm/cli/commands/migrate.js +131 -0
  169. package/dist/esm/cli/commands/pull.js +374 -0
  170. package/dist/esm/cli/commands/push.js +129 -0
  171. package/dist/esm/cli/commands/rollback.js +133 -0
  172. package/dist/esm/cli/commands/status.js +107 -0
  173. package/dist/esm/cli/commands/sync.js +76 -0
  174. package/dist/esm/cli/index.js +240 -0
  175. package/dist/esm/cli/utils/change-tracker.js +405 -0
  176. package/dist/esm/cli/utils/commit-manager.js +191 -0
  177. package/dist/esm/cli/utils/config-loader.js +86 -0
  178. package/dist/esm/cli/utils/env-loader.js +57 -0
  179. package/dist/esm/cli/utils/fast-introspect.js +362 -0
  180. package/dist/esm/cli/utils/git-utils.js +347 -0
  181. package/dist/esm/cli/utils/migration-generator.js +263 -0
  182. package/dist/esm/cli/utils/relqignore.js +74 -0
  183. package/dist/esm/cli/utils/repo-manager.js +444 -0
  184. package/dist/esm/cli/utils/schema-comparator.js +307 -0
  185. package/dist/esm/cli/utils/schema-diff.js +276 -0
  186. package/dist/esm/cli/utils/schema-hash.js +69 -0
  187. package/dist/esm/cli/utils/schema-introspect.js +418 -0
  188. package/dist/esm/cli/utils/snapshot-manager.js +179 -0
  189. package/dist/esm/cli/utils/spinner.js +101 -0
  190. package/dist/esm/cli/utils/sql-generator.js +504 -0
  191. package/dist/esm/cli/utils/sql-parser.js +992 -0
  192. package/dist/esm/cli/utils/type-generator.js +2058 -0
  193. package/dist/esm/condition/array-condition-builder.js +495 -0
  194. package/dist/esm/condition/array-numeric-condition-builder.js +182 -0
  195. package/dist/esm/condition/array-specialized-condition-builder.js +200 -0
  196. package/dist/esm/condition/array-string-condition-builder.js +142 -0
  197. package/dist/esm/condition/base-condition-builder.js +1 -0
  198. package/dist/esm/condition/condition-collector.js +275 -0
  199. package/dist/esm/condition/fulltext-condition-builder.js +53 -0
  200. package/dist/esm/condition/geometric-condition-builder.js +200 -0
  201. package/dist/esm/condition/index.js +7 -0
  202. package/dist/esm/condition/jsonb-condition-builder.js +152 -0
  203. package/dist/esm/condition/network-condition-builder.js +222 -0
  204. package/dist/esm/condition/range-condition-builder.js +74 -0
  205. package/dist/esm/config/config.js +150 -0
  206. package/dist/esm/config/index.js +1 -0
  207. package/dist/esm/constants/pg-values.js +63 -0
  208. package/dist/esm/copy/copy-builder.js +308 -0
  209. package/dist/esm/copy/index.js +1 -0
  210. package/dist/esm/core/query-builder.js +426 -0
  211. package/dist/esm/core/relq-client.js +1791 -0
  212. package/dist/esm/core/typed-kuery-client.js +1 -0
  213. package/dist/esm/count/count-builder.js +81 -0
  214. package/dist/esm/count/index.js +1 -0
  215. package/dist/esm/cte/cte-builder.js +82 -0
  216. package/dist/esm/cte/index.js +1 -0
  217. package/dist/esm/ddl/function.js +45 -0
  218. package/dist/esm/ddl/index.js +2 -0
  219. package/dist/esm/ddl/sql.js +51 -0
  220. package/dist/esm/delete/delete-builder.js +128 -0
  221. package/dist/esm/delete/index.js +1 -0
  222. package/dist/esm/errors/relq-errors.js +310 -0
  223. package/dist/esm/examples/fulltext-search-test.js +117 -0
  224. package/dist/esm/explain/explain-builder.js +95 -0
  225. package/dist/esm/explain/index.js +1 -0
  226. package/dist/esm/function/create-function-builder.js +188 -0
  227. package/dist/esm/function/index.js +1 -0
  228. package/dist/esm/functions/advanced-functions.js +231 -0
  229. package/dist/esm/functions/case-builder.js +58 -0
  230. package/dist/esm/functions/geometric-functions.js +97 -0
  231. package/dist/esm/functions/index.js +171 -0
  232. package/dist/esm/functions/network-functions.js +79 -0
  233. package/dist/esm/functions/sql-functions.js +421 -0
  234. package/dist/esm/index.js +34 -0
  235. package/dist/esm/indexing/create-index-builder.js +180 -0
  236. package/dist/esm/indexing/drop-index-builder.js +81 -0
  237. package/dist/esm/indexing/index-types.js +1 -0
  238. package/dist/esm/indexing/index.js +2 -0
  239. package/dist/esm/insert/conflict-builder.js +162 -0
  240. package/dist/esm/insert/index.js +1 -0
  241. package/dist/esm/insert/insert-builder.js +247 -0
  242. package/dist/esm/introspect/index.js +224 -0
  243. package/dist/esm/maintenance/index.js +1 -0
  244. package/dist/esm/maintenance/vacuum-builder.js +158 -0
  245. package/dist/esm/pubsub/index.js +1 -0
  246. package/dist/esm/pubsub/listen-notify-builder.js +48 -0
  247. package/dist/esm/pubsub/listener-connection.js +173 -0
  248. package/dist/esm/raw/index.js +1 -0
  249. package/dist/esm/raw/raw-query-builder.js +20 -0
  250. package/dist/esm/schema/index.js +1 -0
  251. package/dist/esm/schema/schema-builder.js +1150 -0
  252. package/dist/esm/schema-builder.js +2 -0
  253. package/dist/esm/schema-definition/column-types.js +738 -0
  254. package/dist/esm/schema-definition/index.js +10 -0
  255. package/dist/esm/schema-definition/introspection.js +614 -0
  256. package/dist/esm/schema-definition/partitions.js +123 -0
  257. package/dist/esm/schema-definition/pg-enum.js +70 -0
  258. package/dist/esm/schema-definition/pg-function.js +85 -0
  259. package/dist/esm/schema-definition/pg-sequence.js +50 -0
  260. package/dist/esm/schema-definition/pg-trigger.js +102 -0
  261. package/dist/esm/schema-definition/relations.js +90 -0
  262. package/dist/esm/schema-definition/sql-expressions.js +193 -0
  263. package/dist/esm/schema-definition/table-definition.js +630 -0
  264. package/dist/esm/select/aggregate-builder.js +172 -0
  265. package/dist/esm/select/index.js +1 -0
  266. package/dist/esm/select/select-builder.js +226 -0
  267. package/dist/esm/sequence/index.js +1 -0
  268. package/dist/esm/sequence/sequence-builder.js +255 -0
  269. package/dist/esm/table/alter-table-builder.js +138 -0
  270. package/dist/esm/table/constraint-builder.js +95 -0
  271. package/dist/esm/table/create-table-builder.js +241 -0
  272. package/dist/esm/table/index.js +5 -0
  273. package/dist/esm/table/partition-builder.js +121 -0
  274. package/dist/esm/table/truncate-builder.js +63 -0
  275. package/dist/esm/transaction/index.js +1 -0
  276. package/dist/esm/transaction/transaction-builder.js +70 -0
  277. package/dist/esm/trigger/create-trigger-builder.js +166 -0
  278. package/dist/esm/trigger/index.js +1 -0
  279. package/dist/esm/types/aggregate-types.js +1 -0
  280. package/dist/esm/types/config-types.js +36 -0
  281. package/dist/esm/types/inference-types.js +12 -0
  282. package/dist/esm/types/pagination-types.js +4 -0
  283. package/dist/esm/types/result-types.js +1 -0
  284. package/dist/esm/types/schema-types.js +1 -0
  285. package/dist/esm/types/subscription-types.js +1 -0
  286. package/dist/esm/types.js +1 -0
  287. package/dist/esm/update/array-update-builder.js +192 -0
  288. package/dist/esm/update/index.js +2 -0
  289. package/dist/esm/update/update-builder.js +188 -0
  290. package/dist/esm/utils/case-converter.js +55 -0
  291. package/dist/esm/utils/environment-detection.js +113 -0
  292. package/dist/esm/utils/index.js +2 -0
  293. package/dist/esm/utils/pool-defaults.js +100 -0
  294. package/dist/esm/utils/type-coercion.js +110 -0
  295. package/dist/esm/view/create-view-builder.js +171 -0
  296. package/dist/esm/view/index.js +1 -0
  297. package/dist/esm/window/index.js +1 -0
  298. package/dist/esm/window/window-builder.js +73 -0
  299. package/dist/index.cjs +1 -0
  300. package/dist/index.d.ts +10341 -0
  301. package/dist/index.js +1 -0
  302. package/dist/schema-builder.cjs +1 -0
  303. package/dist/schema-builder.d.ts +2272 -0
  304. package/dist/schema-builder.js +1 -0
  305. package/package.json +55 -0
@@ -0,0 +1,2272 @@
1
+ export declare const EMPTY_OBJECT: unique symbol;
2
+ export declare const EMPTY_ARRAY: unique symbol;
3
+ export interface ColumnConfig<T = unknown> {
4
+ $type: string;
5
+ $sqlType?: string;
6
+ $tsType?: T;
7
+ $nullable?: boolean;
8
+ $default?: T | (() => T) | string | object | typeof EMPTY_OBJECT | typeof EMPTY_ARRAY;
9
+ $primaryKey?: boolean;
10
+ $unique?: boolean;
11
+ $references?: {
12
+ table: string;
13
+ column: string;
14
+ onDelete?: string;
15
+ onUpdate?: string;
16
+ };
17
+ $check?: string;
18
+ $checkValues?: readonly string[];
19
+ $generated?: {
20
+ expression: string;
21
+ stored?: boolean;
22
+ };
23
+ $array?: boolean;
24
+ $dimensions?: number;
25
+ $length?: number;
26
+ $precision?: number;
27
+ $scale?: number;
28
+ $withTimezone?: boolean;
29
+ $columnName?: string;
30
+ }
31
+ /** Table column references for generated columns - each column becomes a ChainableExpr */
32
+ export type GeneratedTableRefs<T extends Record<string, ColumnConfig>> = {
33
+ [K in keyof T]: ChainableExpr;
34
+ };
35
+ /** Chainable expression for fluent arithmetic operations */
36
+ export interface ChainableExpr extends GeneratedExpr {
37
+ /** Add another value: col.add(otherCol) or col.add(5) */
38
+ add(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
39
+ /** Alias for add */
40
+ plus(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
41
+ /** Subtract another value: col.subtract(otherCol) or col.subtract(5) */
42
+ subtract(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
43
+ /** Alias for subtract */
44
+ minus(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
45
+ /** Multiply by another value: col.multiply(otherCol) or col.multiply(5) */
46
+ multiply(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
47
+ /** Alias for multiply */
48
+ times(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
49
+ /** Divide by another value: col.divide(otherCol) or col.divide(5) */
50
+ divide(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
51
+ /** Alias for divide */
52
+ dividedBy(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
53
+ /** Modulo operation: col.mod(5) */
54
+ mod(value: ChainableExpr | GeneratedExpr | number): ChainableExpr;
55
+ /** Concatenate strings: col.concat(otherCol, ' ', anotherCol) */
56
+ concat(...args: (ChainableExpr | GeneratedExpr | string)[]): ChainableExpr;
57
+ }
58
+ /** SQL functions for generated column expressions */
59
+ export interface GeneratedFn {
60
+ /**
61
+ * Call F directly on a column to start a chainable expression
62
+ * @example F(table.unitPrice).multiply(table.quantity)
63
+ */
64
+ (col: ChainableExpr | GeneratedExpr): ChainableExpr;
65
+ lower(col: ChainableExpr | GeneratedExpr): ChainableExpr;
66
+ upper(col: ChainableExpr | GeneratedExpr): ChainableExpr;
67
+ trim(col: ChainableExpr | GeneratedExpr): ChainableExpr;
68
+ ltrim(col: ChainableExpr | GeneratedExpr): ChainableExpr;
69
+ rtrim(col: ChainableExpr | GeneratedExpr): ChainableExpr;
70
+ length(col: ChainableExpr | GeneratedExpr): ChainableExpr;
71
+ substring(col: ChainableExpr | GeneratedExpr, start: number, length?: number): ChainableExpr;
72
+ concat(...args: (ChainableExpr | GeneratedExpr | string)[]): ChainableExpr;
73
+ replace(col: ChainableExpr | GeneratedExpr, from: string, to: string): ChainableExpr;
74
+ left(col: ChainableExpr | GeneratedExpr, n: number): ChainableExpr;
75
+ right(col: ChainableExpr | GeneratedExpr, n: number): ChainableExpr;
76
+ abs(col: ChainableExpr | GeneratedExpr): ChainableExpr;
77
+ ceil(col: ChainableExpr | GeneratedExpr): ChainableExpr;
78
+ floor(col: ChainableExpr | GeneratedExpr): ChainableExpr;
79
+ round(col: ChainableExpr | GeneratedExpr, decimals?: number): ChainableExpr;
80
+ trunc(col: ChainableExpr | GeneratedExpr, decimals?: number): ChainableExpr;
81
+ sign(col: ChainableExpr | GeneratedExpr): ChainableExpr;
82
+ power(col: ChainableExpr | GeneratedExpr, exponent: number): ChainableExpr;
83
+ sqrt(col: ChainableExpr | GeneratedExpr): ChainableExpr;
84
+ exp(col: ChainableExpr | GeneratedExpr): ChainableExpr;
85
+ ln(col: ChainableExpr | GeneratedExpr): ChainableExpr;
86
+ log(col: ChainableExpr | GeneratedExpr, base?: number): ChainableExpr;
87
+ greatest(...args: (ChainableExpr | GeneratedExpr | number)[]): ChainableExpr;
88
+ least(...args: (ChainableExpr | GeneratedExpr | number)[]): ChainableExpr;
89
+ add(a: ChainableExpr | GeneratedExpr | number, b: ChainableExpr | GeneratedExpr | number): ChainableExpr;
90
+ subtract(a: ChainableExpr | GeneratedExpr | number, b: ChainableExpr | GeneratedExpr | number): ChainableExpr;
91
+ multiply(a: ChainableExpr | GeneratedExpr | number, b: ChainableExpr | GeneratedExpr | number): ChainableExpr;
92
+ divide(a: ChainableExpr | GeneratedExpr | number, b: ChainableExpr | GeneratedExpr | number): ChainableExpr;
93
+ mod(a: ChainableExpr | GeneratedExpr | number, b: ChainableExpr | GeneratedExpr | number): ChainableExpr;
94
+ asText(col: ChainableExpr | GeneratedExpr): ChainableExpr;
95
+ asInteger(col: ChainableExpr | GeneratedExpr): ChainableExpr;
96
+ asNumeric(col: ChainableExpr | GeneratedExpr): ChainableExpr;
97
+ asBoolean(col: ChainableExpr | GeneratedExpr): ChainableExpr;
98
+ asDate(col: ChainableExpr | GeneratedExpr): ChainableExpr;
99
+ asTimestamp(col: ChainableExpr | GeneratedExpr): ChainableExpr;
100
+ coalesce(...args: (ChainableExpr | GeneratedExpr | string | number | null)[]): ChainableExpr;
101
+ nullif(col: ChainableExpr | GeneratedExpr, value: ChainableExpr | GeneratedExpr | string | number): ChainableExpr;
102
+ ifNull(col: ChainableExpr | GeneratedExpr, defaultValue: ChainableExpr | GeneratedExpr | string | number): ChainableExpr;
103
+ case(): CaseBuilder;
104
+ jsonExtract(col: ChainableExpr | GeneratedExpr, path: string): ChainableExpr;
105
+ jsonExtractText(col: ChainableExpr | GeneratedExpr, path: string): ChainableExpr;
106
+ jsonbExtract(col: ChainableExpr | GeneratedExpr, path: string): ChainableExpr;
107
+ jsonbExtractText(col: ChainableExpr | GeneratedExpr, path: string): ChainableExpr;
108
+ jsonArrayLength(col: ChainableExpr | GeneratedExpr): ChainableExpr;
109
+ extract(field: "year" | "month" | "day" | "hour" | "minute" | "second" | "dow" | "doy" | "week" | "quarter" | "epoch", col: ChainableExpr | GeneratedExpr): ChainableExpr;
110
+ datePart(field: string, col: ChainableExpr | GeneratedExpr): ChainableExpr;
111
+ age(col1: ChainableExpr | GeneratedExpr, col2: ChainableExpr | GeneratedExpr): ChainableExpr;
112
+ toTsvector(config: string, col: ChainableExpr | GeneratedExpr): ChainableExpr;
113
+ similarity(col1: ChainableExpr | GeneratedExpr, col2: ChainableExpr | GeneratedExpr | string): ChainableExpr;
114
+ point(x: ChainableExpr | GeneratedExpr | number, y: ChainableExpr | GeneratedExpr | number): ChainableExpr;
115
+ arrayLength(col: ChainableExpr | GeneratedExpr, dim?: number): ChainableExpr;
116
+ arrayPosition(arr: ChainableExpr | GeneratedExpr, elem: ChainableExpr | GeneratedExpr | string | number): ChainableExpr;
117
+ md5(col: ChainableExpr | GeneratedExpr): ChainableExpr;
118
+ sha256(col: ChainableExpr | GeneratedExpr): ChainableExpr;
119
+ }
120
+ /** CASE expression builder */
121
+ export interface CaseBuilder {
122
+ when(condition: ChainableExpr | GeneratedExpr | string, result: ChainableExpr | GeneratedExpr | string | number): CaseBuilder;
123
+ else(result: ChainableExpr | GeneratedExpr | string | number): ChainableExpr;
124
+ end(): ChainableExpr;
125
+ }
126
+ /** Expression result for generated columns */
127
+ export interface GeneratedExpr {
128
+ readonly $sql: string;
129
+ readonly $expr: true;
130
+ }
131
+ export type ColumnBuilder<T, Config extends ColumnConfig<T> = ColumnConfig<T>> = Config & {
132
+ notNull(): ColumnBuilder<T, Config & {
133
+ $nullable: false;
134
+ }>;
135
+ nullable(): ColumnBuilder<T, Config & {
136
+ $nullable: true;
137
+ }>;
138
+ default<V extends T | (() => T)>(value: V): ColumnBuilder<T, Config & {
139
+ $default: V;
140
+ }>;
141
+ primaryKey(): ColumnBuilder<T, Config & {
142
+ $primaryKey: true;
143
+ }>;
144
+ unique(): ColumnBuilder<T, Config & {
145
+ $unique: true;
146
+ }>;
147
+ references(table: string, column: string, options?: {
148
+ onDelete?: string;
149
+ onUpdate?: string;
150
+ }): ColumnBuilder<T, Config>;
151
+ /**
152
+ * Add CHECK constraint with enum-like values.
153
+ * Narrows the column type to the union of provided values.
154
+ * @param values - Allowed string values
155
+ * @example
156
+ * .check('active', 'inactive', 'banned')
157
+ * // Type becomes 'active' | 'inactive' | 'banned'
158
+ */
159
+ check<V extends string>(...values: V[]): ColumnBuilder<V, ColumnConfig<V> & {
160
+ $check: string;
161
+ $checkValues: readonly V[];
162
+ }>;
163
+ /**
164
+ * Add CHECK constraint that excludes specific values.
165
+ * Narrows the column type to exclude provided values.
166
+ * @param values - Disallowed string values
167
+ * @example
168
+ * .checkNot('deleted', 'archived')
169
+ * // Column cannot have these values
170
+ */
171
+ checkNot<V extends string>(...values: V[]): ColumnBuilder<T, Config & {
172
+ $checkNot: string;
173
+ $checkNotValues: readonly V[];
174
+ }>;
175
+ /** @deprecated Use generatedAlwaysAs with callback instead */
176
+ generatedAs(expression: string, stored?: boolean): ColumnBuilder<T, Config & {
177
+ $generated: {
178
+ expression: string;
179
+ stored?: boolean;
180
+ };
181
+ }>;
182
+ /**
183
+ * GENERATED ALWAYS AS computed column with typed expression builder
184
+ * @param callback - Expression builder callback: (table, F) => F.subtract(table.quantityOnHand, table.quantityReserved)
185
+ * @param options - { stored: true } for STORED (default), { stored: false } for VIRTUAL
186
+ * @example
187
+ * // Arithmetic with sibling columns
188
+ * quantityAvailable: integer().generatedAlwaysAs(
189
+ * (table, F) => F.subtract(table.quantityOnHand, table.quantityReserved)
190
+ * )
191
+ *
192
+ * // With SQL function
193
+ * emailLower: text().generatedAlwaysAs(
194
+ * (table, F) => F.lower(table.email)
195
+ * )
196
+ *
197
+ * // String concatenation
198
+ * fullName: text().generatedAlwaysAs(
199
+ * (table, F) => F.concat(table.firstName, ' ', table.lastName)
200
+ * )
201
+ */
202
+ generatedAlwaysAs<Cols extends Record<string, ColumnConfig>>(callback: (table: GeneratedTableRefs<Cols>, F: GeneratedFn) => GeneratedExpr, options?: {
203
+ stored?: boolean;
204
+ }): ColumnBuilder<T, Config & {
205
+ $generated: {
206
+ expression: string;
207
+ stored?: boolean;
208
+ };
209
+ }>;
210
+ /**
211
+ * Make this column an array type. Returns properly typed T[].
212
+ * @param dimensions - Number of dimensions (default: 1)
213
+ * @example
214
+ * tags: text().array() // text[] -> string[]
215
+ * matrix: integer().array(2) // integer[][] -> number[][]
216
+ * settings: jsonb<Settings>().array() // jsonb[] -> Settings[]
217
+ */
218
+ array(dimensions?: number): ColumnBuilder<T[], ColumnConfig<T[]> & {
219
+ $array: true;
220
+ }>;
221
+ /**
222
+ * Override the inferred TypeScript type for this column.
223
+ * Useful for branded types, custom type mappings, or narrowing types.
224
+ * @example
225
+ * // Branded type
226
+ * userId: text('user_id').$type<UserId>()
227
+ * // Override numeric string to number
228
+ * amount: numeric('amount').$type<number>()
229
+ * // Narrow to specific string literals
230
+ * status: text('status').$type<'active' | 'inactive'>()
231
+ */
232
+ $type<U>(): ColumnBuilder<U, ColumnConfig<U>>;
233
+ length(len: number): ColumnBuilder<T, Config & {
234
+ $length: number;
235
+ }>;
236
+ precision(p: number): ColumnBuilder<T, Config & {
237
+ $precision: number;
238
+ }>;
239
+ scale(s: number): ColumnBuilder<T, Config & {
240
+ $scale: number;
241
+ }>;
242
+ withTimezone(): ColumnBuilder<T, Config & {
243
+ $withTimezone: true;
244
+ }>;
245
+ dimensions(d: number): ColumnBuilder<T, Config & {
246
+ $dimensions: number;
247
+ }>;
248
+ };
249
+ export declare const integer: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
250
+ export declare const int: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
251
+ export declare const int4: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
252
+ export declare const smallint: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
253
+ export declare const int2: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
254
+ export declare const bigint: (columnName?: string) => ColumnBuilder<bigint, ColumnConfig<bigint>>;
255
+ export declare const int8: (columnName?: string) => ColumnBuilder<bigint, ColumnConfig<bigint>>;
256
+ export declare const serial: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
257
+ export declare const serial4: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
258
+ export declare const smallserial: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
259
+ export declare const serial2: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
260
+ export declare const bigserial: (columnName?: string) => ColumnBuilder<bigint, ColumnConfig<bigint>>;
261
+ export declare const serial8: (columnName?: string) => ColumnBuilder<bigint, ColumnConfig<bigint>>;
262
+ export declare const decimal: (columnNameOrOpts?: string | number | {
263
+ precision?: number;
264
+ scale?: number;
265
+ }, scale?: number) => ColumnBuilder<string>;
266
+ export declare const numeric: (columnNameOrOpts?: string | number | {
267
+ precision?: number;
268
+ scale?: number;
269
+ }, scale?: number) => ColumnBuilder<string>;
270
+ export declare const real: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
271
+ export declare const float4: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
272
+ export declare const doublePrecision: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
273
+ export declare const float8: (columnName?: string) => ColumnBuilder<number, ColumnConfig<number>>;
274
+ export declare const money: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
275
+ export interface VarcharOptions {
276
+ length?: number;
277
+ }
278
+ export declare function varchar(): ColumnBuilder<string>;
279
+ export declare function varchar(length: number): ColumnBuilder<string>;
280
+ export declare function varchar(options: VarcharOptions): ColumnBuilder<string>;
281
+ export declare function varchar(columnName: string): ColumnBuilder<string>;
282
+ export declare function varchar(columnName: string, options: VarcharOptions): ColumnBuilder<string>;
283
+ export declare const characterVarying: typeof varchar;
284
+ export interface CharOptions {
285
+ length?: number;
286
+ }
287
+ export declare function char(): ColumnBuilder<string>;
288
+ export declare function char(length: number): ColumnBuilder<string>;
289
+ export declare function char(options: CharOptions): ColumnBuilder<string>;
290
+ export declare function char(columnName: string): ColumnBuilder<string>;
291
+ export declare function char(columnName: string, options: CharOptions): ColumnBuilder<string>;
292
+ export declare const character: typeof char;
293
+ export declare const text: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
294
+ export declare const bytea: (columnName?: string) => ColumnBuilder<Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>, ColumnConfig<Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>>>;
295
+ export interface TimestampOptions {
296
+ precision?: number;
297
+ withTimezone?: boolean;
298
+ }
299
+ export declare function timestamp(): ColumnBuilder<Date>;
300
+ export declare function timestamp(precision: number): ColumnBuilder<Date>;
301
+ export declare function timestamp(options: TimestampOptions): ColumnBuilder<Date>;
302
+ export declare function timestamp(columnName: string): ColumnBuilder<Date>;
303
+ export declare function timestamp(columnName: string, options: TimestampOptions): ColumnBuilder<Date>;
304
+ export declare function timestamptz(): ColumnBuilder<Date>;
305
+ export declare function timestamptz(precision: number): ColumnBuilder<Date>;
306
+ export declare function timestamptz(options: {
307
+ precision?: number;
308
+ }): ColumnBuilder<Date>;
309
+ export declare function timestamptz(columnName: string): ColumnBuilder<Date>;
310
+ export declare function timestamptz(columnName: string, options: {
311
+ precision?: number;
312
+ }): ColumnBuilder<Date>;
313
+ export declare const timestampWithTimeZone: typeof timestamptz;
314
+ export declare const date: (columnName?: string) => ColumnBuilder<string | Date, ColumnConfig<string | Date>>;
315
+ export declare function time(columnName?: string, opts?: {
316
+ precision?: number;
317
+ withTimezone?: boolean;
318
+ }): ColumnBuilder<string>;
319
+ export declare function time(opts?: {
320
+ precision?: number;
321
+ withTimezone?: boolean;
322
+ }): ColumnBuilder<string>;
323
+ export declare function timetz(columnName?: string, opts?: {
324
+ precision?: number;
325
+ }): ColumnBuilder<string>;
326
+ export declare function timetz(opts?: {
327
+ precision?: number;
328
+ }): ColumnBuilder<string>;
329
+ export declare const timeWithTimeZone: typeof timetz;
330
+ export declare function interval(columnName?: string, fields?: string): ColumnBuilder<string>;
331
+ export declare function interval(fields?: string): ColumnBuilder<string>;
332
+ export declare const boolean: (columnName?: string) => ColumnBuilder<boolean, ColumnConfig<boolean>>;
333
+ export declare const bool: (columnName?: string) => ColumnBuilder<boolean, ColumnConfig<boolean>>;
334
+ export declare const point: (columnName?: string) => ColumnBuilder<{
335
+ x: number;
336
+ y: number;
337
+ }, ColumnConfig<{
338
+ x: number;
339
+ y: number;
340
+ }>>;
341
+ export declare const line: (columnName?: string) => ColumnBuilder<{
342
+ a: number;
343
+ b: number;
344
+ c: number;
345
+ }, ColumnConfig<{
346
+ a: number;
347
+ b: number;
348
+ c: number;
349
+ }>>;
350
+ export declare const lseg: (columnName?: string) => ColumnBuilder<[
351
+ [
352
+ number,
353
+ number
354
+ ],
355
+ [
356
+ number,
357
+ number
358
+ ]
359
+ ], ColumnConfig<[
360
+ [
361
+ number,
362
+ number
363
+ ],
364
+ [
365
+ number,
366
+ number
367
+ ]
368
+ ]>>;
369
+ export declare const box: (columnName?: string) => ColumnBuilder<[
370
+ [
371
+ number,
372
+ number
373
+ ],
374
+ [
375
+ number,
376
+ number
377
+ ]
378
+ ], ColumnConfig<[
379
+ [
380
+ number,
381
+ number
382
+ ],
383
+ [
384
+ number,
385
+ number
386
+ ]
387
+ ]>>;
388
+ export declare const path: (columnName?: string) => ColumnBuilder<{
389
+ x: number;
390
+ y: number;
391
+ }[], ColumnConfig<{
392
+ x: number;
393
+ y: number;
394
+ }[]>>;
395
+ export declare const polygon: (columnName?: string) => ColumnBuilder<{
396
+ x: number;
397
+ y: number;
398
+ }[], ColumnConfig<{
399
+ x: number;
400
+ y: number;
401
+ }[]>>;
402
+ export declare const circle: (columnName?: string) => ColumnBuilder<{
403
+ x: number;
404
+ y: number;
405
+ r: number;
406
+ }, ColumnConfig<{
407
+ x: number;
408
+ y: number;
409
+ r: number;
410
+ }>>;
411
+ export declare const cidr: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
412
+ export declare const inet: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
413
+ export declare const macaddr: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
414
+ export declare const macaddr8: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
415
+ export declare const bit: (length?: number) => ColumnBuilder<string, ColumnConfig<string>>;
416
+ export declare const bitVarying: (length?: number) => ColumnBuilder<string, ColumnConfig<string>>;
417
+ export declare const varbit: (length?: number) => ColumnBuilder<string, ColumnConfig<string>>;
418
+ export declare const tsvector: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
419
+ export declare const tsquery: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
420
+ export declare const uuid: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
421
+ export declare const xml: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
422
+ export declare const json: <T = unknown>(columnName?: string) => ColumnBuilder<T, ColumnConfig<T>>;
423
+ export declare const jsonb: <T = unknown>(columnName?: string) => ColumnBuilder<T, ColumnConfig<T>>;
424
+ export declare const int4range: () => ColumnBuilder<string, ColumnConfig<string>>;
425
+ export declare const int8range: () => ColumnBuilder<string, ColumnConfig<string>>;
426
+ export declare const numrange: () => ColumnBuilder<string, ColumnConfig<string>>;
427
+ export declare const tsrange: () => ColumnBuilder<string, ColumnConfig<string>>;
428
+ export declare const tstzrange: () => ColumnBuilder<string, ColumnConfig<string>>;
429
+ export declare const daterange: () => ColumnBuilder<string, ColumnConfig<string>>;
430
+ export declare const int4multirange: () => ColumnBuilder<string, ColumnConfig<string>>;
431
+ export declare const int8multirange: () => ColumnBuilder<string, ColumnConfig<string>>;
432
+ export declare const nummultirange: () => ColumnBuilder<string, ColumnConfig<string>>;
433
+ export declare const tsmultirange: () => ColumnBuilder<string, ColumnConfig<string>>;
434
+ export declare const tstzmultirange: () => ColumnBuilder<string, ColumnConfig<string>>;
435
+ export declare const datemultirange: () => ColumnBuilder<string, ColumnConfig<string>>;
436
+ export declare const oid: () => ColumnBuilder<number, ColumnConfig<number>>;
437
+ export declare const regclass: () => ColumnBuilder<string, ColumnConfig<string>>;
438
+ export declare const regproc: () => ColumnBuilder<string, ColumnConfig<string>>;
439
+ export declare const regtype: () => ColumnBuilder<string, ColumnConfig<string>>;
440
+ export declare const pgLsn: () => ColumnBuilder<string, ColumnConfig<string>>;
441
+ export declare const pgSnapshot: () => ColumnBuilder<string, ColumnConfig<string>>;
442
+ /**
443
+ * Case-insensitive text type (requires citext extension)
444
+ * @example
445
+ * email: citext('email').notNull().unique()
446
+ */
447
+ export declare const citext: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
448
+ /**
449
+ * Hierarchical tree-like data type (requires ltree extension)
450
+ * @example
451
+ * path: ltree('path').notNull()
452
+ * // Values like 'root.parent.child'
453
+ */
454
+ export declare const ltree: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
455
+ /**
456
+ * Label tree query type (requires ltree extension)
457
+ * Used for querying ltree columns
458
+ */
459
+ export declare const lquery: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
460
+ /**
461
+ * Label tree text query type (requires ltree extension)
462
+ * Used for full-text-like queries on ltree
463
+ */
464
+ export declare const ltxtquery: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
465
+ /**
466
+ * Key-value store type (requires hstore extension)
467
+ * @example
468
+ * metadata: hstore('metadata')
469
+ * // Values like '"key1"=>"value1", "key2"=>"value2"'
470
+ */
471
+ export declare const hstore: (columnName?: string) => ColumnBuilder<Record<string, string | null>, ColumnConfig<Record<string, string | null>>>;
472
+ /**
473
+ * Cube data type for multi-dimensional points (requires cube extension)
474
+ * @example
475
+ * coordinates: cube('coordinates')
476
+ */
477
+ export declare const cube: (columnName?: string) => ColumnBuilder<number[], ColumnConfig<number[]>>;
478
+ /**
479
+ * Semantic version type (requires semver extension)
480
+ * @example
481
+ * version: semver('version').notNull()
482
+ */
483
+ export declare const semver: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
484
+ /** GeoJSON-compatible geometry type for PostGIS */
485
+ export interface GeoJsonGeometry {
486
+ type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon" | "GeometryCollection";
487
+ coordinates: unknown;
488
+ crs?: {
489
+ type: string;
490
+ properties: {
491
+ name: string;
492
+ };
493
+ };
494
+ }
495
+ /**
496
+ * PostGIS geometry type (requires PostGIS extension)
497
+ * @param srid - Spatial Reference System Identifier (e.g., 4326 for WGS84)
498
+ * @param geometryType - Specific geometry type (POINT, LINESTRING, POLYGON, etc.)
499
+ * @example
500
+ * location: geometry('location', 4326, 'POINT')
501
+ * boundary: geometry('boundary', 4326, 'POLYGON')
502
+ */
503
+ export declare const geometry: (columnName?: string, srid?: number, geometryType?: "POINT" | "LINESTRING" | "POLYGON" | "MULTIPOINT" | "MULTILINESTRING" | "MULTIPOLYGON" | "GEOMETRYCOLLECTION") => ColumnBuilder<GeoJsonGeometry, ColumnConfig<GeoJsonGeometry>>;
504
+ /**
505
+ * PostGIS geography type for geodetic calculations (requires PostGIS extension)
506
+ * Uses spherical math for accurate distance calculations on Earth
507
+ * @param srid - Spatial Reference System Identifier (default: 4326 for WGS84)
508
+ * @param geometryType - Specific geometry type
509
+ * @example
510
+ * location: geography('location', 4326, 'POINT')
511
+ */
512
+ export declare const geography: (columnName?: string, srid?: number, geometryType?: "POINT" | "LINESTRING" | "POLYGON" | "MULTIPOINT" | "MULTILINESTRING" | "MULTIPOLYGON") => ColumnBuilder<GeoJsonGeometry, ColumnConfig<GeoJsonGeometry>>;
513
+ /**
514
+ * PostGIS point type - shorthand for geometry point
515
+ * @example
516
+ * location: geoPoint('location') // GEOMETRY(POINT, 4326)
517
+ */
518
+ export declare const geoPoint: (columnName?: string, srid?: number) => ColumnBuilder<{
519
+ x: number;
520
+ y: number;
521
+ srid?: number;
522
+ }, ColumnConfig<{
523
+ x: number;
524
+ y: number;
525
+ srid?: number;
526
+ }>>;
527
+ /**
528
+ * PostGIS box2d type
529
+ */
530
+ export declare const box2d: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
531
+ /**
532
+ * PostGIS box3d type
533
+ */
534
+ export declare const box3d: (columnName?: string) => ColumnBuilder<string, ColumnConfig<string>>;
535
+ export interface DomainConfig<T> {
536
+ /** Domain type name */
537
+ $domainName: string;
538
+ /** Base type */
539
+ $baseType: string;
540
+ /** Constraints */
541
+ $constraints?: string[];
542
+ /** Default value */
543
+ $domainDefault?: T;
544
+ /** Whether NULL is allowed */
545
+ $notNull?: boolean;
546
+ /** Collation */
547
+ $collation?: string;
548
+ /** Base ColumnBuilder for type inference */
549
+ $columnBuilder?: ColumnBuilder<T>;
550
+ }
551
+ /**
552
+ * Domain check condition - represents a CHECK constraint expression
553
+ * Can be combined with .and() / .or() and optionally named with .as()
554
+ */
555
+ export interface DomainCheckCondition {
556
+ /** The SQL expression */
557
+ $sql: string;
558
+ /** Optional constraint name */
559
+ $name?: string;
560
+ /** JS validation function */
561
+ $validate: (val: any) => boolean;
562
+ /** Combine with AND */
563
+ and(other: DomainCheckCondition): DomainCheckCondition;
564
+ /** Combine with OR */
565
+ or(other: DomainCheckCondition): DomainCheckCondition;
566
+ /** Give the constraint a name */
567
+ as(name: string): DomainCheckCondition;
568
+ }
569
+ /**
570
+ * Domain VALUE expression - provides typed methods for domain check constraints
571
+ * VALUE is the PostgreSQL keyword for the domain input value
572
+ *
573
+ * @example
574
+ * // Check that percentage is between 0 and 100
575
+ * (value) => [value.gte('0').and(value.lte('100'))]
576
+ */
577
+ export interface DomainValueExpr<T> {
578
+ /**
579
+ * Equals - SQL: `VALUE = n`
580
+ * @example value.eq('100') // VALUE = '100'
581
+ */
582
+ eq(value: T | string): DomainCheckCondition;
583
+ /**
584
+ * Not equals - SQL: `VALUE <> n`
585
+ * @example value.neq('0') // VALUE <> '0'
586
+ */
587
+ neq(value: T | string): DomainCheckCondition;
588
+ /**
589
+ * Greater than - SQL: `VALUE > n`
590
+ * @example value.gt('0') // VALUE > 0
591
+ */
592
+ gt(value: T | string): DomainCheckCondition;
593
+ /**
594
+ * Greater than or equal - SQL: `VALUE >= n`
595
+ * @example value.gte('0') // VALUE >= 0
596
+ */
597
+ gte(value: T | string): DomainCheckCondition;
598
+ /**
599
+ * Less than - SQL: `VALUE < n`
600
+ * @example value.lt('100') // VALUE < 100
601
+ */
602
+ lt(value: T | string): DomainCheckCondition;
603
+ /**
604
+ * Less than or equal - SQL: `VALUE <= n`
605
+ * @example value.lte('100') // VALUE <= 100
606
+ */
607
+ lte(value: T | string): DomainCheckCondition;
608
+ /**
609
+ * Between range - SQL: `VALUE BETWEEN min AND max`
610
+ * @example value.between('0', '100') // VALUE BETWEEN 0 AND 100
611
+ */
612
+ between(min: T | string, max: T | string): DomainCheckCondition;
613
+ /**
614
+ * In list - SQL: `VALUE IN (v1, v2, ...)`
615
+ * @example value.in(['active', 'pending']) // VALUE IN ('active', 'pending')
616
+ */
617
+ in(values: (T | string)[]): DomainCheckCondition;
618
+ /**
619
+ * Not in list - SQL: `VALUE NOT IN (v1, v2, ...)`
620
+ * @example value.notIn(['deleted', 'banned']) // VALUE NOT IN ('deleted', 'banned')
621
+ */
622
+ notIn(values: (T | string)[]): DomainCheckCondition;
623
+ /**
624
+ * Is null - SQL: `VALUE IS NULL`
625
+ */
626
+ isNull(): DomainCheckCondition;
627
+ /**
628
+ * Is not null - SQL: `VALUE IS NOT NULL`
629
+ */
630
+ isNotNull(): DomainCheckCondition;
631
+ /**
632
+ * Like pattern (case sensitive) - SQL: `VALUE LIKE 'pattern'`
633
+ * @example value.like('%@gmail.com') // VALUE LIKE '%@gmail.com'
634
+ */
635
+ like(pattern: string): DomainCheckCondition;
636
+ /**
637
+ * Not like pattern - SQL: `VALUE NOT LIKE 'pattern'`
638
+ * @example value.notLike('%..%') // VALUE NOT LIKE '%..%'
639
+ */
640
+ notLike(pattern: string): DomainCheckCondition;
641
+ /**
642
+ * Like pattern (case insensitive) - SQL: `VALUE ILIKE 'pattern'`
643
+ * @example value.ilike('%test%') // VALUE ILIKE '%test%'
644
+ */
645
+ ilike(pattern: string): DomainCheckCondition;
646
+ /**
647
+ * Not like pattern (case insensitive) - SQL: `VALUE NOT ILIKE 'pattern'`
648
+ * @example value.notIlike('%test%') // VALUE NOT ILIKE '%test%'
649
+ */
650
+ notIlike(pattern: string): DomainCheckCondition;
651
+ /**
652
+ * Regex match (case insensitive) - SQL: `VALUE ~* 'regex'`
653
+ * @example value.matches('^[a-z0-9]+$') // VALUE ~* '^[a-z0-9]+$'
654
+ */
655
+ matches(regex: string): DomainCheckCondition;
656
+ /**
657
+ * Regex match (case sensitive) - SQL: `VALUE ~ 'regex'`
658
+ * @example value.matchesCaseSensitive('^[A-Z]+$') // VALUE ~ '^[A-Z]+$'
659
+ */
660
+ matchesCaseSensitive(regex: string): DomainCheckCondition;
661
+ /**
662
+ * Length greater than - SQL: `LENGTH(VALUE) > n`
663
+ * @example value.lengthGt(5) // LENGTH(VALUE) > 5
664
+ */
665
+ lengthGt(n: number): DomainCheckCondition;
666
+ /**
667
+ * Length greater than or equal - SQL: `LENGTH(VALUE) >= n`
668
+ * @example value.lengthGte(1) // LENGTH(VALUE) >= 1
669
+ */
670
+ lengthGte(n: number): DomainCheckCondition;
671
+ /**
672
+ * Length less than - SQL: `LENGTH(VALUE) < n`
673
+ * @example value.lengthLt(256) // LENGTH(VALUE) < 256
674
+ */
675
+ lengthLt(n: number): DomainCheckCondition;
676
+ /**
677
+ * Length less than or equal - SQL: `LENGTH(VALUE) <= n`
678
+ * @example value.lengthLte(100) // LENGTH(VALUE) <= 100
679
+ */
680
+ lengthLte(n: number): DomainCheckCondition;
681
+ /**
682
+ * Length equals - SQL: `LENGTH(VALUE) = n`
683
+ * @example value.lengthEq(10) // LENGTH(VALUE) = 10
684
+ */
685
+ lengthEq(n: number): DomainCheckCondition;
686
+ }
687
+ /**
688
+ * Define a PostgreSQL domain type (constrained base type)
689
+ * @param name - Domain type name
690
+ * @param baseType - Base type as ColumnBuilder (e.g., integer(), text(), numeric().precision(5).scale(2))
691
+ * @param checks - Optional callback to define CHECK constraints using typed DomainValueExpr
692
+ * @example
693
+ * // Simple domain with no constraints
694
+ * export const emailDomain = pgDomain('email', citext());
695
+ *
696
+ * // Domain with check constraint
697
+ * export const positiveDomain = pgDomain('positive_int',
698
+ * integer(),
699
+ * (value) => [value.gt(0)]
700
+ * );
701
+ *
702
+ * // Domain with compound check and name
703
+ * export const percentageDomain = pgDomain('percentage',
704
+ * numeric().precision(5).scale(2),
705
+ * (value) => [value.gte(0).and(value.lte(100)).as('valid_percentage')]
706
+ * );
707
+ *
708
+ * // Use in table
709
+ * email: emailDomain('email').notNull()
710
+ */
711
+ export declare function pgDomain<T>(name: string, baseType: ColumnBuilder<T>, checks?: (value: DomainValueExpr<T>) => DomainCheckCondition[]): ((columnName?: string) => ColumnBuilder<T>) & DomainConfig<T>;
712
+ /**
713
+ * Generate CREATE DOMAIN SQL
714
+ */
715
+ export declare function generateDomainSQL<T>(domain: DomainConfig<T>): string;
716
+ export interface CompositeTypeConfig<T extends Record<string, ColumnConfig>> {
717
+ /** Composite type name */
718
+ $typeName: string;
719
+ /** Fields/attributes of the composite type */
720
+ $fields: T;
721
+ /** Infer TypeScript type */
722
+ $inferType: {
723
+ [K in keyof T]: T[K] extends ColumnConfig<infer U> ? U : unknown;
724
+ };
725
+ }
726
+ /**
727
+ * Define a PostgreSQL composite type
728
+ * @param name - Composite type name
729
+ * @param fields - Object defining the composite type fields
730
+ * @example
731
+ * // Define composite type
732
+ * export const addressType = pgComposite('address_type', {
733
+ * street: text(),
734
+ * city: text(),
735
+ * state: varchar().length(2),
736
+ * zip: varchar().length(10),
737
+ * country: varchar().length(2).default('US'),
738
+ * });
739
+ *
740
+ * // Use in table
741
+ * address: addressType('address')
742
+ * addresses: addressType('addresses').array()
743
+ *
744
+ * // Get TypeScript type
745
+ * type Address = typeof addressType.$inferType;
746
+ */
747
+ export declare function pgComposite<T extends Record<string, ColumnConfig>>(name: string, fields: T): ((columnName?: string) => ColumnBuilder<{
748
+ [K in keyof T]: T[K] extends ColumnConfig<infer U> ? U : unknown;
749
+ }>) & CompositeTypeConfig<T>;
750
+ /**
751
+ * Generate CREATE TYPE ... AS SQL for composite type
752
+ */
753
+ export declare function generateCompositeTypeSQL<T extends Record<string, ColumnConfig>>(composite: CompositeTypeConfig<T>): string;
754
+ /**
755
+ * Create a column with a custom PostgreSQL type
756
+ * @param typeName - The PostgreSQL type name
757
+ * @param columnName - Optional explicit column name
758
+ * @example
759
+ * // Basic usage
760
+ * data: customType('my_custom_type')
761
+ * // With column name
762
+ * data: customType<MyType>('my_custom_type', 'data_column')
763
+ * // With chaining
764
+ * data: customType('my_type').notNull().array()
765
+ */
766
+ export declare const customType: <T = string>(typeName: string, columnName?: string) => ColumnBuilder<T, ColumnConfig<T>>;
767
+ export declare const enumType: <T extends string>(name: string, values: readonly T[], columnName?: string) => ColumnConfig<T> & {
768
+ notNull(): ColumnBuilder<T, ColumnConfig<T> & {
769
+ $nullable: false;
770
+ }>;
771
+ nullable(): ColumnBuilder<T, ColumnConfig<T> & {
772
+ $nullable: true;
773
+ }>;
774
+ default<V extends T | (() => T)>(value: V): ColumnBuilder<T, ColumnConfig<T> & {
775
+ $default: V;
776
+ }>;
777
+ primaryKey(): ColumnBuilder<T, ColumnConfig<T> & {
778
+ $primaryKey: true;
779
+ }>;
780
+ unique(): ColumnBuilder<T, ColumnConfig<T> & {
781
+ $unique: true;
782
+ }>;
783
+ references(table: string, column: string, options?: {
784
+ onDelete?: string;
785
+ onUpdate?: string;
786
+ }): ColumnBuilder<T, ColumnConfig<T>>;
787
+ /**
788
+ * Add CHECK constraint with enum-like values.
789
+ * Narrows the column type to the union of provided values.
790
+ * @param values - Allowed string values
791
+ * @example
792
+ * .check('active', 'inactive', 'banned')
793
+ * // Type becomes 'active' | 'inactive' | 'banned'
794
+ */
795
+ check<V extends string>(...values: V[]): ColumnBuilder<V, ColumnConfig<V> & {
796
+ $check: string;
797
+ $checkValues: readonly V[];
798
+ }>;
799
+ /**
800
+ * Add CHECK constraint that excludes specific values.
801
+ * Narrows the column type to exclude provided values.
802
+ * @param values - Disallowed string values
803
+ * @example
804
+ * .checkNot('deleted', 'archived')
805
+ * // Column cannot have these values
806
+ */
807
+ checkNot<V extends string>(...values: V[]): ColumnBuilder<T, ColumnConfig<T> & {
808
+ $checkNot: string;
809
+ $checkNotValues: readonly V[];
810
+ }>;
811
+ /** @deprecated Use generatedAlwaysAs with callback instead */
812
+ generatedAs(expression: string, stored?: boolean): ColumnBuilder<T, ColumnConfig<T> & {
813
+ $generated: {
814
+ expression: string;
815
+ stored?: boolean;
816
+ };
817
+ }>;
818
+ /**
819
+ * GENERATED ALWAYS AS computed column with typed expression builder
820
+ * @param callback - Expression builder callback: (table, F) => F.subtract(table.quantityOnHand, table.quantityReserved)
821
+ * @param options - { stored: true } for STORED (default), { stored: false } for VIRTUAL
822
+ * @example
823
+ * // Arithmetic with sibling columns
824
+ * quantityAvailable: integer().generatedAlwaysAs(
825
+ * (table, F) => F.subtract(table.quantityOnHand, table.quantityReserved)
826
+ * )
827
+ *
828
+ * // With SQL function
829
+ * emailLower: text().generatedAlwaysAs(
830
+ * (table, F) => F.lower(table.email)
831
+ * )
832
+ *
833
+ * // String concatenation
834
+ * fullName: text().generatedAlwaysAs(
835
+ * (table, F) => F.concat(table.firstName, ' ', table.lastName)
836
+ * )
837
+ */
838
+ generatedAlwaysAs<Cols extends Record<string, ColumnConfig>>(callback: (table: GeneratedTableRefs<Cols>, F: GeneratedFn) => GeneratedExpr, options?: {
839
+ stored?: boolean;
840
+ }): ColumnBuilder<T, ColumnConfig<T> & {
841
+ $generated: {
842
+ expression: string;
843
+ stored?: boolean;
844
+ };
845
+ }>;
846
+ /**
847
+ * Make this column an array type. Returns properly typed T[].
848
+ * @param dimensions - Number of dimensions (default: 1)
849
+ * @example
850
+ * tags: text().array() // text[] -> string[]
851
+ * matrix: integer().array(2) // integer[][] -> number[][]
852
+ * settings: jsonb<Settings>().array() // jsonb[] -> Settings[]
853
+ */
854
+ array(dimensions?: number): ColumnBuilder<T[], ColumnConfig<T[]> & {
855
+ $array: true;
856
+ }>;
857
+ /**
858
+ * Override the inferred TypeScript type for this column.
859
+ * Useful for branded types, custom type mappings, or narrowing types.
860
+ * @example
861
+ * // Branded type
862
+ * userId: text('user_id').$type<UserId>()
863
+ * // Override numeric string to number
864
+ * amount: numeric('amount').$type<number>()
865
+ * // Narrow to specific string literals
866
+ * status: text('status').$type<'active' | 'inactive'>()
867
+ */
868
+ $type<U>(): ColumnBuilder<U, ColumnConfig<U>>;
869
+ length(len: number): ColumnBuilder<T, ColumnConfig<T> & {
870
+ $length: number;
871
+ }>;
872
+ precision(p: number): ColumnBuilder<T, ColumnConfig<T> & {
873
+ $precision: number;
874
+ }>;
875
+ scale(s: number): ColumnBuilder<T, ColumnConfig<T> & {
876
+ $scale: number;
877
+ }>;
878
+ withTimezone(): ColumnBuilder<T, ColumnConfig<T> & {
879
+ $withTimezone: true;
880
+ }>;
881
+ dimensions(d: number): ColumnBuilder<T, ColumnConfig<T> & {
882
+ $dimensions: number;
883
+ }>;
884
+ } & {
885
+ $enumValues: readonly T[];
886
+ };
887
+ /** @deprecated Use pgComposite() instead for better type inference */
888
+ export declare const compositeType: <T>(typeName: string, columnName?: string) => ColumnBuilder<T, ColumnConfig<T>>;
889
+ declare const SQL_BRAND: unique symbol;
890
+ export type SqlExpression<T> = T & {
891
+ readonly [SQL_BRAND]: true;
892
+ readonly $sql: string;
893
+ };
894
+ /**
895
+ * Use gen_random_uuid() as default value for UUID columns
896
+ * @returns SqlExpression<string> - compatible with uuid().default()
897
+ */
898
+ export declare const genRandomUuid: () => SqlExpression<string>;
899
+ /**
900
+ * Use uuid_generate_v4() as default value for UUID columns
901
+ * @returns SqlExpression<string> - compatible with uuid().default()
902
+ */
903
+ export declare const uuidV4: () => SqlExpression<string>;
904
+ /**
905
+ * Use NOW() as default value for timestamp columns
906
+ * @returns SqlExpression<Date> - compatible with timestamp().default()
907
+ */
908
+ export declare const now: () => SqlExpression<Date>;
909
+ /**
910
+ * Use CURRENT_TIMESTAMP as default value for timestamp columns
911
+ * @returns SqlExpression<Date> - compatible with timestamp().default()
912
+ */
913
+ export declare const currentTimestamp: () => SqlExpression<Date>;
914
+ /**
915
+ * Use CURRENT_DATE as default value for date columns
916
+ * @returns SqlExpression<Date | string> - compatible with date().default()
917
+ */
918
+ export declare const currentDate: () => SqlExpression<Date | string>;
919
+ /**
920
+ * Empty JSON object '{}' as default value
921
+ * Returns a typed marker that gets serialized to '{}' in SQL
922
+ * @example jsonb<MyType>().default(emptyObject())
923
+ */
924
+ export declare const emptyObject: <T = Record<string, unknown>>() => SqlExpression<T>;
925
+ /**
926
+ * Empty JSON array '[]' as default value
927
+ * Returns a typed marker that gets serialized to '[]' in SQL
928
+ * @example tags: text().array().default(emptyArray())
929
+ */
930
+ export declare const emptyArray: <T = unknown[]>() => SqlExpression<T>;
931
+ /**
932
+ * Raw SQL expression wrapper
933
+ */
934
+ export declare const raw: <T = unknown>(expression: string) => SqlExpression<T>;
935
+ export interface IndexDef {
936
+ name: string;
937
+ columns: string[];
938
+ unique?: boolean;
939
+ isUnique?: boolean;
940
+ using?: string;
941
+ method?: string;
942
+ where?: string;
943
+ }
944
+ export interface IndexOnResult {
945
+ name: string;
946
+ columns: string[];
947
+ unique(): IndexDef;
948
+ using(method: "BTREE" | "HASH" | "GIN" | "GIST" | "BRIN" | "SPGIST"): IndexDef;
949
+ }
950
+ export declare const index: (name: string) => {
951
+ name: string;
952
+ on: (...columns: string[]) => IndexOnResult;
953
+ };
954
+ /**
955
+ * Partition Types and Builders
956
+ *
957
+ * Provides type-safe, elegant API for PostgreSQL partitioning.
958
+ * Supports LIST, RANGE, HASH and multi-level subpartitioning.
959
+ */
960
+ export type PartitionType = "LIST" | "RANGE" | "HASH";
961
+ /**
962
+ * Partition strategy definition
963
+ */
964
+ export interface PartitionStrategyDef {
965
+ readonly $type: PartitionType;
966
+ readonly $column: string;
967
+ readonly $modulus?: number;
968
+ readonly $subpartition?: PartitionStrategyDef;
969
+ }
970
+ /**
971
+ * Partition strategy builder - LIST
972
+ */
973
+ export interface ListPartitionBuilder {
974
+ readonly $type: "LIST";
975
+ readonly $column: string;
976
+ readonly $subpartition?: PartitionStrategyDef;
977
+ /** Add subpartition strategy */
978
+ sub(fn: (p: PartitionStrategyFactory) => PartitionStrategyDef): ListPartitionBuilder & {
979
+ $subpartition: PartitionStrategyDef;
980
+ };
981
+ }
982
+ /**
983
+ * Partition strategy builder - RANGE
984
+ */
985
+ export interface RangePartitionBuilder {
986
+ readonly $type: "RANGE";
987
+ readonly $column: string;
988
+ readonly $subpartition?: PartitionStrategyDef;
989
+ /** Add subpartition strategy */
990
+ sub(fn: (p: PartitionStrategyFactory) => PartitionStrategyDef): RangePartitionBuilder & {
991
+ $subpartition: PartitionStrategyDef;
992
+ };
993
+ }
994
+ /**
995
+ * Partition strategy builder - HASH (no subpartitioning allowed)
996
+ */
997
+ export interface HashPartitionBuilder {
998
+ readonly $type: "HASH";
999
+ readonly $column: string;
1000
+ readonly $modulus: number;
1001
+ }
1002
+ /**
1003
+ * Factory for creating partition strategies
1004
+ */
1005
+ export interface PartitionStrategyFactory {
1006
+ /** List partition on column */
1007
+ list(column: {
1008
+ $columnName?: string;
1009
+ name?: string;
1010
+ } | string): ListPartitionBuilder;
1011
+ /** Range partition on column */
1012
+ range(column: {
1013
+ $columnName?: string;
1014
+ name?: string;
1015
+ } | string): RangePartitionBuilder;
1016
+ /** Hash partition on column with modulus */
1017
+ hash(column: {
1018
+ $columnName?: string;
1019
+ name?: string;
1020
+ } | string, modulus: number): HashPartitionBuilder;
1021
+ }
1022
+ /**
1023
+ * Child partition definition
1024
+ */
1025
+ export interface ChildPartitionDef {
1026
+ readonly $name: string;
1027
+ readonly $partitionType: "LIST" | "RANGE" | "HASH" | "DEFAULT";
1028
+ readonly $values?: string[];
1029
+ readonly $from?: string;
1030
+ readonly $to?: string;
1031
+ readonly $modulus?: number;
1032
+ readonly $remainder?: number;
1033
+ readonly $isDefault?: boolean;
1034
+ }
1035
+ /**
1036
+ * Partition child builder
1037
+ */
1038
+ export interface PartitionChildBuilder {
1039
+ readonly $name: string;
1040
+ /** LIST partition - for values (string or array) */
1041
+ in(values: string | string[]): ChildPartitionDef;
1042
+ /** RANGE partition - from value */
1043
+ from(value: string | number | Date): RangePartitionFromBuilder;
1044
+ /** HASH partition - remainder */
1045
+ remainder(value: number): ChildPartitionDef;
1046
+ /** DEFAULT partition */
1047
+ default(): ChildPartitionDef;
1048
+ }
1049
+ /**
1050
+ * RANGE from builder - needs to()
1051
+ */
1052
+ export interface RangePartitionFromBuilder {
1053
+ /** RANGE partition - to value */
1054
+ to(value: string | number | Date): ChildPartitionDef;
1055
+ }
1056
+ /**
1057
+ * Partition strategy factory - passed to partitionBy callback
1058
+ */
1059
+ export declare const partitionStrategyFactory: PartitionStrategyFactory;
1060
+ /**
1061
+ * Generate partition strategy SQL (PARTITION BY clause)
1062
+ */
1063
+ export declare function generatePartitionBySQL(strategy: PartitionStrategyDef): string;
1064
+ /**
1065
+ * Generate child partition SQL
1066
+ */
1067
+ export declare function generateChildPartitionSQL(parentTable: string, child: ChildPartitionDef, subpartitionStrategy?: PartitionStrategyDef): string;
1068
+ export type PartitionByCallback<T> = (table: T, p: PartitionStrategyFactory) => PartitionStrategyDef;
1069
+ /** Factory function for creating partition children */
1070
+ export type PartitionFactory = (name: string) => PartitionChildBuilder;
1071
+ export type PartitionsCallback = (partitionFn: PartitionFactory) => ChildPartitionDef[];
1072
+ /**
1073
+ * SQL Expression Builders for DDL
1074
+ * Provides fully typed SQL functions for use in indexes, generated columns, etc.
1075
+ * NO raw SQL strings - everything is typed and composable.
1076
+ */
1077
+ /** Represents a SQL expression that can be used in DDL */
1078
+ export interface SqlExpr {
1079
+ /** The SQL string representation */
1080
+ readonly $sql: string;
1081
+ /** Brand to distinguish from plain strings */
1082
+ readonly $expr: true;
1083
+ }
1084
+ /** Column reference in expressions with ordering support */
1085
+ export interface ColumnRef extends SqlExpr {
1086
+ readonly $column: string;
1087
+ /** Sort descending */
1088
+ desc(): OrderedColumnRef;
1089
+ /** Sort ascending (default) */
1090
+ asc(): OrderedColumnRef;
1091
+ }
1092
+ /** Column reference with ordering applied */
1093
+ export interface OrderedColumnRef extends SqlExpr {
1094
+ readonly $column: string;
1095
+ /** NULLS LAST - nulls appear after all non-null values */
1096
+ nullsLast(): SqlExpr;
1097
+ /** NULLS FIRST - nulls appear before all non-null values */
1098
+ nullsFirst(): SqlExpr;
1099
+ }
1100
+ export interface SqlFunctions {
1101
+ lower(col: ColumnRef | SqlExpr): SqlExpr;
1102
+ upper(col: ColumnRef | SqlExpr): SqlExpr;
1103
+ trim(col: ColumnRef | SqlExpr): SqlExpr;
1104
+ ltrim(col: ColumnRef | SqlExpr): SqlExpr;
1105
+ rtrim(col: ColumnRef | SqlExpr): SqlExpr;
1106
+ length(col: ColumnRef | SqlExpr): SqlExpr;
1107
+ substring(col: ColumnRef | SqlExpr, start: number, length?: number): SqlExpr;
1108
+ concat(...args: (ColumnRef | SqlExpr | string)[]): SqlExpr;
1109
+ replace(col: ColumnRef | SqlExpr, from: string, to: string): SqlExpr;
1110
+ left(col: ColumnRef | SqlExpr, n: number): SqlExpr;
1111
+ right(col: ColumnRef | SqlExpr, n: number): SqlExpr;
1112
+ abs(col: ColumnRef | SqlExpr): SqlExpr;
1113
+ ceil(col: ColumnRef | SqlExpr): SqlExpr;
1114
+ floor(col: ColumnRef | SqlExpr): SqlExpr;
1115
+ round(col: ColumnRef | SqlExpr, decimals?: number): SqlExpr;
1116
+ trunc(col: ColumnRef | SqlExpr, decimals?: number): SqlExpr;
1117
+ mod(col: ColumnRef | SqlExpr, divisor: number): SqlExpr;
1118
+ power(col: ColumnRef | SqlExpr, exp: number): SqlExpr;
1119
+ sqrt(col: ColumnRef | SqlExpr): SqlExpr;
1120
+ now(): SqlExpr;
1121
+ currentDate(): SqlExpr;
1122
+ currentTime(): SqlExpr;
1123
+ currentTimestamp(): SqlExpr;
1124
+ extract(field: "year" | "month" | "day" | "hour" | "minute" | "second" | "dow" | "doy" | "week" | "quarter", col: ColumnRef | SqlExpr): SqlExpr;
1125
+ datePart(field: string, col: ColumnRef | SqlExpr): SqlExpr;
1126
+ age(col: ColumnRef | SqlExpr, col2?: ColumnRef | SqlExpr): SqlExpr;
1127
+ dateTrunc(field: string, col: ColumnRef | SqlExpr): SqlExpr;
1128
+ cast(col: ColumnRef | SqlExpr, type: string): SqlExpr;
1129
+ asText(col: ColumnRef | SqlExpr): SqlExpr;
1130
+ asInteger(col: ColumnRef | SqlExpr): SqlExpr;
1131
+ asNumeric(col: ColumnRef | SqlExpr): SqlExpr;
1132
+ asTimestamp(col: ColumnRef | SqlExpr): SqlExpr;
1133
+ asDate(col: ColumnRef | SqlExpr): SqlExpr;
1134
+ coalesce(...args: (ColumnRef | SqlExpr | string | number | null)[]): SqlExpr;
1135
+ nullif(col: ColumnRef | SqlExpr, value: string | number): SqlExpr;
1136
+ ifNull(col: ColumnRef | SqlExpr, defaultValue: string | number): SqlExpr;
1137
+ jsonExtract(col: ColumnRef | SqlExpr, path: string): SqlExpr;
1138
+ jsonExtractText(col: ColumnRef | SqlExpr, path: string): SqlExpr;
1139
+ jsonbExtract(col: ColumnRef | SqlExpr, path: string): SqlExpr;
1140
+ jsonbExtractText(col: ColumnRef | SqlExpr, path: string): SqlExpr;
1141
+ arrayLength(col: ColumnRef | SqlExpr, dim?: number): SqlExpr;
1142
+ unnest(col: ColumnRef | SqlExpr): SqlExpr;
1143
+ arrayAgg(col: ColumnRef | SqlExpr): SqlExpr;
1144
+ toTsvector(config: string, col: ColumnRef | SqlExpr): SqlExpr;
1145
+ toTsquery(config: string, query: string): SqlExpr;
1146
+ similarity(col1: ColumnRef | SqlExpr, col2: ColumnRef | SqlExpr | string): SqlExpr;
1147
+ genRandomUuid(): SqlExpr;
1148
+ add(col: ColumnRef | SqlExpr, value: number | ColumnRef | SqlExpr): SqlExpr;
1149
+ subtract(col: ColumnRef | SqlExpr, value: number | ColumnRef | SqlExpr): SqlExpr;
1150
+ multiply(col: ColumnRef | SqlExpr, value: number | ColumnRef | SqlExpr): SqlExpr;
1151
+ divide(col: ColumnRef | SqlExpr, value: number | ColumnRef | SqlExpr): SqlExpr;
1152
+ raw(sql: string): SqlExpr;
1153
+ }
1154
+ /** SQL functions implementation */
1155
+ export declare const sqlFunctions: SqlFunctions;
1156
+ export interface WhereCondition extends SqlExpr {
1157
+ and(other: WhereCondition): WhereCondition;
1158
+ or(other: WhereCondition): WhereCondition;
1159
+ }
1160
+ export interface WhereBuilder<T extends Record<string, unknown>> {
1161
+ eq<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1162
+ neq<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1163
+ gt<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1164
+ gte<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1165
+ lt<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1166
+ lte<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1167
+ isNull<K extends keyof T>(col: K): WhereCondition;
1168
+ isNotNull<K extends keyof T>(col: K): WhereCondition;
1169
+ like<K extends keyof T>(col: K, pattern: string): WhereCondition;
1170
+ ilike<K extends keyof T>(col: K, pattern: string): WhereCondition;
1171
+ in<K extends keyof T>(col: K, values: T[K][]): WhereCondition;
1172
+ notIn<K extends keyof T>(col: K, values: T[K][]): WhereCondition;
1173
+ isTrue<K extends keyof T>(col: K): WhereCondition;
1174
+ isFalse<K extends keyof T>(col: K): WhereCondition;
1175
+ between<K extends keyof T>(col: K, min: T[K], max: T[K]): WhereCondition;
1176
+ raw(sql: string): WhereCondition;
1177
+ expr(expression: SqlExpr, op: "=" | "!=" | ">" | ">=" | "<" | "<=" | "IS NULL" | "IS NOT NULL", value?: unknown): WhereCondition;
1178
+ }
1179
+ /** Create a where builder for typed conditions */
1180
+ export declare function createWhereBuilder<T extends Record<string, unknown>>(columnMap: Record<keyof T, string>): WhereBuilder<T>;
1181
+ export interface GeneratedExprBuilder<T extends Record<string, unknown>> {
1182
+ /** Reference a column */
1183
+ col<K extends keyof T>(name: K): ColumnRef;
1184
+ /** SQL functions */
1185
+ fn: SqlFunctions;
1186
+ /** Arithmetic */
1187
+ add(a: ColumnRef | SqlExpr | number, b: ColumnRef | SqlExpr | number): SqlExpr;
1188
+ subtract(a: ColumnRef | SqlExpr | number, b: ColumnRef | SqlExpr | number): SqlExpr;
1189
+ multiply(a: ColumnRef | SqlExpr | number, b: ColumnRef | SqlExpr | number): SqlExpr;
1190
+ divide(a: ColumnRef | SqlExpr | number, b: ColumnRef | SqlExpr | number): SqlExpr;
1191
+ /** Concatenation with || */
1192
+ concat(...parts: (ColumnRef | SqlExpr | string)[]): SqlExpr;
1193
+ }
1194
+ /** Create a generated expression builder */
1195
+ export declare function createGeneratedExprBuilder<T extends Record<string, unknown>>(columnMap: Record<keyof T, string>): GeneratedExprBuilder<T>;
1196
+ /** Create column references for index building */
1197
+ export declare function createTableColumnRefs<T extends Record<string, unknown>>(columns: T): {
1198
+ [K in keyof T]: ColumnRef;
1199
+ };
1200
+ /** Common PostgreSQL extensions */
1201
+ export type PgExtension = "uuid-ossp" | "pgcrypto" | "pg_trgm" | "btree_gin" | "btree_gist" | "hstore" | "ltree" | "cube" | "earthdistance" | "citext" | "intarray" | "postgis" | "postgis_topology" | "fuzzystrmatch" | "unaccent" | "tablefunc" | "pg_stat_statements" | "plpgsql" | (string & {});
1202
+ export interface PgExtensionsConfig {
1203
+ /** List of enabled extensions */
1204
+ extensions: readonly PgExtension[];
1205
+ /** Generate CREATE EXTENSION SQL */
1206
+ toSQL(): string[];
1207
+ }
1208
+ /**
1209
+ * Define PostgreSQL extensions for your database
1210
+ * @example
1211
+ * export const extensions = pgExtensions('uuid-ossp', 'pgcrypto', 'pg_trgm', 'citext');
1212
+ */
1213
+ export declare function pgExtensions<T extends readonly PgExtension[]>(...extensions: T): PgExtensionsConfig & {
1214
+ extensions: T;
1215
+ };
1216
+ export declare function getSql(expr: SqlExpr): string;
1217
+ /** Expression builder for index expressions - extends SqlFunctions with col() */
1218
+ export interface ExpressionBuilder extends SqlFunctions {
1219
+ /** Reference a column by name */
1220
+ col(name: string): ColumnRef;
1221
+ }
1222
+ /** Create an expression builder for index expressions */
1223
+ export declare function createExpressionBuilder(): ExpressionBuilder;
1224
+ /** Singleton expression builder */
1225
+ export declare const expressionBuilder: ExpressionBuilder;
1226
+ export interface IndexStorageOptions {
1227
+ /** Fill factor (10-100). Lower values leave more space for updates. Default varies by index type. */
1228
+ fillfactor?: number;
1229
+ /** For GIN indexes: enable fast update technique */
1230
+ fastupdate?: boolean;
1231
+ /** For GIN indexes: pending list limit in KB */
1232
+ ginPendingListLimit?: number;
1233
+ /** For BRIN indexes: pages per range */
1234
+ pagesPerRange?: number;
1235
+ /** For BRIN indexes: enable auto-summarization */
1236
+ autosummarize?: boolean;
1237
+ /** Number of leaf pages to buffer for GiST indexes */
1238
+ buffering?: "auto" | "on" | "off";
1239
+ }
1240
+ export interface IndexDefinition {
1241
+ name: string;
1242
+ columns: string[];
1243
+ unique?: boolean;
1244
+ using?: "BTREE" | "HASH" | "GIN" | "GIST" | "BRIN" | "SPGIST";
1245
+ where?: string;
1246
+ isUnique?: boolean;
1247
+ /** Index storage options like fillfactor */
1248
+ with?: IndexStorageOptions;
1249
+ /** Tablespace for the index */
1250
+ tablespace?: string;
1251
+ /** Nulls ordering: first or last */
1252
+ nulls?: "first" | "last";
1253
+ /** Sort order */
1254
+ order?: "asc" | "desc";
1255
+ /** Include columns (covering index) */
1256
+ include?: string[];
1257
+ /** Expression for expression-based indexes */
1258
+ expression?: string;
1259
+ }
1260
+ export interface IndexBuilder {
1261
+ name: string;
1262
+ columns: string[];
1263
+ unique(): IndexBuilder;
1264
+ using(method: "BTREE" | "HASH" | "GIN" | "GIST" | "BRIN" | "SPGIST"): IndexBuilder;
1265
+ /** Partial index with typed WHERE callback */
1266
+ where<T extends Record<string, unknown>>(callback: (w: IndexWhereBuilder<T>) => WhereCondition): IndexBuilder;
1267
+ /** Partial index with string condition (legacy) */
1268
+ where(condition: string): IndexBuilder;
1269
+ with(options: IndexStorageOptions): IndexBuilder;
1270
+ tablespace(name: string): IndexBuilder;
1271
+ nullsFirst(): IndexBuilder;
1272
+ nullsLast(): IndexBuilder;
1273
+ asc(): IndexBuilder;
1274
+ desc(): IndexBuilder;
1275
+ include(...columns: string[]): IndexBuilder;
1276
+ /** Expression-based index with typed callback */
1277
+ on<T>(callback: (F: SqlFunctions) => SqlExpr): IndexBuilder;
1278
+ /** Expression-based index columns */
1279
+ on(...columns: string[]): IndexBuilder;
1280
+ }
1281
+ /** Where builder for index conditions */
1282
+ export interface IndexWhereBuilder<T extends Record<string, unknown>> {
1283
+ /** Column reference */
1284
+ col(name: keyof T): ColumnExpr;
1285
+ /** Comparison operators */
1286
+ eq<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1287
+ neq<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1288
+ gt<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1289
+ gte<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1290
+ lt<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1291
+ lte<K extends keyof T>(col: K, value: T[K]): WhereCondition;
1292
+ /** Null checks */
1293
+ isNull<K extends keyof T>(col: K): WhereCondition;
1294
+ isNotNull<K extends keyof T>(col: K): WhereCondition;
1295
+ /** Between */
1296
+ between<K extends keyof T>(col: K, min: T[K], max: T[K]): WhereCondition;
1297
+ /** SQL functions */
1298
+ fn: SqlFunctions;
1299
+ /** Date/time helpers */
1300
+ currentDate(): ColumnExpr;
1301
+ currentTimestamp(): ColumnExpr;
1302
+ now(): ColumnExpr;
1303
+ interval(value: string): SqlExpr;
1304
+ }
1305
+ /** Check constraint expression with column access and comparison methods */
1306
+ /**
1307
+ * Check expression for use in CHECK constraints
1308
+ * Provides typed methods for building SQL constraint conditions
1309
+ *
1310
+ * @template T - The TypeScript type of the column value (e.g., `number` for integer columns)
1311
+ *
1312
+ * @example
1313
+ * // In checkConstraints callback
1314
+ * checkConstraints: (table, check) => [
1315
+ * check.constraint('positive_level', table.level.gte(1)),
1316
+ * check.constraint('valid_range', table.amount.between(0, 100))
1317
+ * ]
1318
+ */
1319
+ export interface CheckExpr<T = unknown> extends SqlExpr {
1320
+ /**
1321
+ * Greater than or equal - SQL: `column >= value`
1322
+ * @example table.level.gte(1) // level >= 1
1323
+ */
1324
+ gte(value: T | CheckExpr<T> | number): WhereCondition;
1325
+ /**
1326
+ * Less than or equal - SQL: `column <= value`
1327
+ * @example table.age.lte(100) // age <= 100
1328
+ */
1329
+ lte(value: T | CheckExpr<T> | number): WhereCondition;
1330
+ /**
1331
+ * Greater than - SQL: `column > value`
1332
+ * @example table.count.gt(0) // count > 0
1333
+ */
1334
+ gt(value: T | CheckExpr<T> | number): WhereCondition;
1335
+ /**
1336
+ * Less than - SQL: `column < value`
1337
+ * @example table.priority.lt(10) // priority < 10
1338
+ */
1339
+ lt(value: T | CheckExpr<T> | number): WhereCondition;
1340
+ /**
1341
+ * Equals - SQL: `column = value`
1342
+ * @example table.status.eq('active') // status = 'active'
1343
+ */
1344
+ eq(value: T | CheckExpr<T>): WhereCondition;
1345
+ /**
1346
+ * Not equals - SQL: `column <> value`
1347
+ * @example table.role.neq('banned') // role <> 'banned'
1348
+ */
1349
+ neq(value: T | CheckExpr<T>): WhereCondition;
1350
+ /**
1351
+ * Is null - SQL: `column IS NULL`
1352
+ * @example table.deletedAt.isNull() // deleted_at IS NULL
1353
+ */
1354
+ isNull(): WhereCondition;
1355
+ /**
1356
+ * Is not null - SQL: `column IS NOT NULL`
1357
+ * @example table.email.isNotNull() // email IS NOT NULL
1358
+ */
1359
+ isNotNull(): WhereCondition;
1360
+ /**
1361
+ * In list - SQL: `column IN (v1, v2, ...)`
1362
+ * @example table.status.in(['active', 'pending']) // status IN ('active', 'pending')
1363
+ */
1364
+ in(values: (T | CheckExpr<T>)[]): WhereCondition;
1365
+ /**
1366
+ * Not in list - SQL: `column NOT IN (v1, v2, ...)`
1367
+ * @example table.role.notIn(['banned', 'deleted']) // role NOT IN ('banned', 'deleted')
1368
+ */
1369
+ notIn(values: (T | CheckExpr<T>)[]): WhereCondition;
1370
+ /**
1371
+ * Between range (inclusive) - SQL: `column BETWEEN min AND max`
1372
+ * @example table.percentage.between(0, 100) // percentage BETWEEN 0 AND 100
1373
+ */
1374
+ between(min: T | CheckExpr<T> | number, max: T | CheckExpr<T> | number): WhereCondition;
1375
+ /**
1376
+ * Like pattern (case sensitive) - SQL: `column LIKE 'pattern'`
1377
+ * @example table.email.like('%@gmail.com') // email LIKE '%@gmail.com'
1378
+ */
1379
+ like(pattern: string): WhereCondition;
1380
+ /**
1381
+ * Like pattern (case insensitive) - SQL: `column ILIKE 'pattern'`
1382
+ * @example table.name.ilike('%test%') // name ILIKE '%test%'
1383
+ */
1384
+ ilike(pattern: string): WhereCondition;
1385
+ /**
1386
+ * Regex match (case sensitive) - SQL: `column ~ 'regex'`
1387
+ * @example table.code.matches('^[A-Z]{3}$') // code ~ '^[A-Z]{3}$'
1388
+ */
1389
+ matches(pattern: string): WhereCondition;
1390
+ /**
1391
+ * Regex match (case insensitive) - SQL: `column ~* 'regex'`
1392
+ * @example table.slug.matchesInsensitive('^[a-z0-9-]+$') // slug ~* '^[a-z0-9-]+$'
1393
+ */
1394
+ matchesInsensitive(pattern: string): WhereCondition;
1395
+ /**
1396
+ * Add to expression - SQL: `column + value`
1397
+ * @example table.quantity.plus(1) // quantity + 1
1398
+ */
1399
+ plus(value: CheckExpr<T> | number): CheckExpr<T>;
1400
+ /**
1401
+ * Subtract from expression - SQL: `column - value`
1402
+ * @example table.stock.minus(reserved) // stock - reserved
1403
+ */
1404
+ minus(value: CheckExpr<T> | number): CheckExpr<T>;
1405
+ /**
1406
+ * Multiply expression - SQL: `column * value`
1407
+ * @example table.price.times(quantity) // price * quantity
1408
+ */
1409
+ times(value: CheckExpr<T> | number): CheckExpr<T>;
1410
+ /**
1411
+ * Divide expression - SQL: `column / value`
1412
+ * @example table.total.dividedBy(count) // total / count
1413
+ */
1414
+ dividedBy(value: CheckExpr<T> | number): CheckExpr<T>;
1415
+ /**
1416
+ * Get string length - SQL: `LENGTH(column)`
1417
+ * @example table.email.length().gte(5) // LENGTH(email) >= 5
1418
+ */
1419
+ length(): CheckExpr<number>;
1420
+ /**
1421
+ * Cast to text - SQL: `column::text`
1422
+ * @example table.id.asText() // id::text
1423
+ */
1424
+ asText(): CheckExpr<string>;
1425
+ /**
1426
+ * Absolute value - SQL: `ABS(column)`
1427
+ * @example table.balance.abs().lte(1000) // ABS(balance) <= 1000
1428
+ */
1429
+ abs(): CheckExpr<number>;
1430
+ }
1431
+ /** Check constraint definition */
1432
+ export interface CheckConstraintDef {
1433
+ name: string;
1434
+ expression: string;
1435
+ }
1436
+ /** Check constraint builder for typed constraint expressions */
1437
+ export interface CheckConstraintBuilder<T extends Record<string, unknown>> {
1438
+ /** Reference a column */
1439
+ col(name: keyof T): CheckExpr;
1440
+ /** Create a named check constraint */
1441
+ constraint(name: string, condition: WhereCondition): CheckConstraintDef;
1442
+ }
1443
+ /** Column expression for use in where conditions */
1444
+ export interface ColumnExpr extends SqlExpr {
1445
+ eq(value: unknown): WhereCondition;
1446
+ neq(value: unknown): WhereCondition;
1447
+ gt(value: unknown): WhereCondition;
1448
+ gte(value: unknown): WhereCondition;
1449
+ lt(value: unknown): WhereCondition;
1450
+ lte(value: unknown): WhereCondition;
1451
+ isNull(): WhereCondition;
1452
+ isNotNull(): WhereCondition;
1453
+ in(values: unknown[]): WhereCondition;
1454
+ notIn(values: unknown[]): WhereCondition;
1455
+ between(min: unknown, max: unknown): WhereCondition;
1456
+ like(pattern: string): WhereCondition;
1457
+ ilike(pattern: string): WhereCondition;
1458
+ /** Add interval to column: col.plus(interval('30 days')) */
1459
+ plus(value: SqlExpr | number): ColumnExpr;
1460
+ /** Subtract interval from column: col.minus(interval('1 hour')) */
1461
+ minus(value: SqlExpr | number): ColumnExpr;
1462
+ }
1463
+ export type IndexInput = IndexDefinition | IndexBuilder | IndexBuilderChain | {
1464
+ name: string;
1465
+ columns: string[];
1466
+ unique?: boolean | (() => any);
1467
+ isUnique?: boolean;
1468
+ using?: string | ((method: any) => any);
1469
+ method?: string;
1470
+ where?: string | ((condition: any) => any);
1471
+ with?: IndexStorageOptions | ((options: any) => any);
1472
+ tablespace?: string | ((name: any) => any);
1473
+ nulls?: "first" | "last";
1474
+ order?: "asc" | "desc";
1475
+ include?: string[];
1476
+ };
1477
+ /** Index function factory - provides index() builder and SQL functions */
1478
+ export interface IndexFactory {
1479
+ /** Create a named index */
1480
+ (name: string): IndexBuilderStart;
1481
+ }
1482
+ /** Starting point for index builder - must call .on() or .expression() first */
1483
+ export interface IndexBuilderStart {
1484
+ /** Index on columns (use column names or table.columnName) */
1485
+ on(...columns: (string | SqlExpr)[]): IndexBuilderChain;
1486
+ /** Expression-based index with callback: .expression(exp => exp.lower(exp.col('email'))) */
1487
+ expression(callback: (exp: ExpressionBuilder) => SqlExpr): IndexBuilderChain;
1488
+ }
1489
+ /** Chainable index builder methods */
1490
+ export interface IndexBuilderChain {
1491
+ name: string;
1492
+ columns: string[];
1493
+ unique(): IndexBuilderChain;
1494
+ using(method: "BTREE" | "HASH" | "GIN" | "GIST" | "BRIN" | "SPGIST"): IndexBuilderChain;
1495
+ /** Partial index with typed WHERE condition callback */
1496
+ where(condition: WhereCondition | ((w: IndexWhereBuilder<any>) => WhereCondition)): IndexBuilderChain;
1497
+ with(options: IndexStorageOptions): IndexBuilderChain;
1498
+ tablespace(name: string): IndexBuilderChain;
1499
+ nullsFirst(): IndexBuilderChain;
1500
+ nullsLast(): IndexBuilderChain;
1501
+ asc(): IndexBuilderChain;
1502
+ desc(): IndexBuilderChain;
1503
+ include(...columns: string[]): IndexBuilderChain;
1504
+ opclass(opclass: string): IndexBuilderChain;
1505
+ }
1506
+ export interface TableConfig<T extends Record<string, ColumnConfig>> {
1507
+ columns: T;
1508
+ schema?: string;
1509
+ primaryKey?: string[];
1510
+ uniqueConstraints?: Array<{
1511
+ columns: string[];
1512
+ name?: string;
1513
+ }>;
1514
+ /**
1515
+ * CHECK constraints with typed callback API
1516
+ * @example
1517
+ * checkConstraints: (table, check) => [
1518
+ * check.constraint('positive_amount', table.amount.gte(0)),
1519
+ * check.constraint('valid_range', table.minValue.lte(table.maxValue)),
1520
+ * check.constraint('email_format', table.email.isNotNull().and(table.email.asText().length().gte(5))),
1521
+ * ]
1522
+ */
1523
+ checkConstraints?: ((table: CheckTableRefs<T>, check: CheckConstraintBuilder<T>) => CheckConstraintDef[]);
1524
+ foreignKeys?: Array<{
1525
+ columns: string[];
1526
+ references: {
1527
+ table: string;
1528
+ columns: string[];
1529
+ };
1530
+ onDelete?: "CASCADE" | "SET NULL" | "SET DEFAULT" | "RESTRICT" | "NO ACTION";
1531
+ onUpdate?: "CASCADE" | "SET NULL" | "SET DEFAULT" | "RESTRICT" | "NO ACTION";
1532
+ name?: string;
1533
+ }>;
1534
+ /** Index definitions - use (table, index, F) => [index('name').on(F.lower(table.email))] */
1535
+ indexes?: IndexInput[] | ((table: ColumnRefs<T>, index: IndexFactory, F: SqlFunctions) => IndexInput[]);
1536
+ inherits?: string[];
1537
+ /** Partition strategy - use (table, p) => p.list(table.col) / p.range(table.col) / p.hash(table.col, modulus) */
1538
+ partitionBy?: (table: ColumnRefs<T>, p: PartitionStrategyFactory) => PartitionStrategyDef;
1539
+ /** Child partition definitions - use (partition) => [partition('name').in([...]), ...] */
1540
+ partitions?: (partition: PartitionFactory) => ChildPartitionDef[];
1541
+ tablespace?: string;
1542
+ withOptions?: Record<string, unknown>;
1543
+ }
1544
+ type ColumnRef$1 = string & {
1545
+ __columnRef: true;
1546
+ };
1547
+ export type ColumnRefs<T extends Record<string, ColumnConfig>> = {
1548
+ [K in keyof T]: ColumnRef$1;
1549
+ };
1550
+ /**
1551
+ * Table refs for check constraints - each column is a typed CheckExpr
1552
+ * The type is inferred from the column's ColumnConfig type parameter
1553
+ *
1554
+ * @template T - Record of column names to ColumnConfig types
1555
+ *
1556
+ * @example
1557
+ * // If table has: { level: ColumnConfig<number>, name: ColumnConfig<string> }
1558
+ * // Then CheckTableRefs will be:
1559
+ * // { level: CheckExpr<number>, name: CheckExpr<string> }
1560
+ */
1561
+ export type CheckTableRefs<T extends Record<string, ColumnConfig>> = {
1562
+ [K in keyof T]: T[K] extends ColumnConfig<infer U> ? CheckExpr<U> : CheckExpr<unknown>;
1563
+ };
1564
+ export type IsSerialType<T extends string> = T extends "SERIAL" | "BIGSERIAL" | "SMALLSERIAL" | "SERIAL4" | "SERIAL2" | "SERIAL8" ? true : false;
1565
+ export type HasDefault<C> = C extends {
1566
+ $default: undefined;
1567
+ } ? false : C extends {
1568
+ $default: infer D;
1569
+ } ? D extends undefined ? false : true : false;
1570
+ export type HasGenerated<C> = C extends {
1571
+ $generated: undefined;
1572
+ } ? false : C extends {
1573
+ $generated: infer G;
1574
+ } ? G extends undefined ? false : true : false;
1575
+ export type GetColumnType<C> = C extends {
1576
+ $type: infer T;
1577
+ } ? T extends string ? T : string : string;
1578
+ /**
1579
+ * Check if column is explicitly marked NOT NULL
1580
+ * - $nullable: false → explicitly NOT NULL (via .notNull())
1581
+ * - $nullable: true → explicitly nullable (via .nullable())
1582
+ * - $nullable: undefined → implicitly nullable (PostgreSQL default)
1583
+ */
1584
+ export type IsExplicitlyNotNull<C> = C extends {
1585
+ $nullable: false;
1586
+ } ? true : false;
1587
+ /**
1588
+ * Check if column is a PRIMARY KEY
1589
+ * PRIMARY KEY columns are implicitly NOT NULL in PostgreSQL
1590
+ */
1591
+ export type IsPrimaryKey<C> = C extends {
1592
+ $primaryKey: true;
1593
+ } ? true : false;
1594
+ /**
1595
+ * Determine if a column is required for INSERT:
1596
+ * REQUIRED when: (explicitly NOT NULL or PRIMARY KEY) AND no default/generated value
1597
+ * OPTIONAL when: has default, is generated, is serial, or is nullable (explicit or implicit)
1598
+ */
1599
+ export type IsRequiredForInsert<C> = HasDefault<C> extends true ? false : HasGenerated<C> extends true ? false : IsSerialType<GetColumnType<C>> extends true ? false : IsExplicitlyNotNull<C> extends true ? true : IsPrimaryKey<C> extends true ? true : false;
1600
+ /**
1601
+ * Determine if a column is required for SELECT:
1602
+ * REQUIRED when: explicitly NOT NULL, has default, is generated, or is PRIMARY KEY
1603
+ * OPTIONAL when: nullable (no NOT NULL constraint)
1604
+ */
1605
+ export type IsRequiredForSelect<C> = IsExplicitlyNotNull<C> extends true ? true : IsPrimaryKey<C> extends true ? true : HasDefault<C> extends true ? true : HasGenerated<C> extends true ? true : IsSerialType<GetColumnType<C>> extends true ? true : false;
1606
+ export type InferSelectType<T extends TableDefinition<any>> = T["$inferSelect"];
1607
+ export type InferInsertType<T extends TableDefinition<any>> = T["$inferInsert"];
1608
+ export type InferUpdateType<T extends TableDefinition<any>> = Partial<T["$inferInsert"]>;
1609
+ /**
1610
+ * Build SELECT type with smart required/optional:
1611
+ * - Required: NOT NULL, PRIMARY KEY, has DEFAULT/GENERATED columns
1612
+ * - Optional: Nullable columns without constraints
1613
+ */
1614
+ export type BuildSelectType<T extends Record<string, ColumnConfig>> = {
1615
+ [K in keyof T as IsRequiredForSelect<T[K]> extends true ? K : never]: T[K] extends ColumnConfig<infer U> ? T[K] extends {
1616
+ $nullable: true;
1617
+ } ? U | null : U : unknown;
1618
+ } & {
1619
+ [K in keyof T as IsRequiredForSelect<T[K]> extends true ? never : K]?: T[K] extends ColumnConfig<infer U> ? U | null : unknown;
1620
+ };
1621
+ export type BuildInsertType<T extends Record<string, ColumnConfig>> = {
1622
+ [K in keyof T as IsRequiredForInsert<T[K]> extends true ? K : never]: T[K] extends ColumnConfig<infer U> ? U : unknown;
1623
+ } & {
1624
+ [K in keyof T as IsRequiredForInsert<T[K]> extends true ? never : K]?: T[K] extends ColumnConfig<infer U> ? T[K] extends {
1625
+ $nullable: true;
1626
+ } ? U | null : U : unknown;
1627
+ };
1628
+ export interface TableDefinition<T extends Record<string, ColumnConfig>> {
1629
+ $name: string;
1630
+ $schema?: string;
1631
+ $columns: T;
1632
+ $primaryKey?: string[];
1633
+ $uniqueConstraints?: Array<{
1634
+ columns: string[];
1635
+ name?: string;
1636
+ }>;
1637
+ $checkConstraints?: Array<{
1638
+ expression: string;
1639
+ name?: string;
1640
+ }>;
1641
+ $foreignKeys?: Array<{
1642
+ columns: string[];
1643
+ references: {
1644
+ table: string;
1645
+ columns: string[];
1646
+ };
1647
+ onDelete?: string;
1648
+ onUpdate?: string;
1649
+ name?: string;
1650
+ }>;
1651
+ $indexes?: IndexDefinition[];
1652
+ $inherits?: string[];
1653
+ $partitionBy?: PartitionStrategyDef;
1654
+ $tablespace?: string;
1655
+ $withOptions?: Record<string, unknown>;
1656
+ $inferSelect: BuildSelectType<T>;
1657
+ $inferInsert: BuildInsertType<T>;
1658
+ toSQL(): string;
1659
+ toCreateIndexSQL(): string[];
1660
+ }
1661
+ export declare function defineTable<T extends Record<string, ColumnConfig>>(name: string, columns: T, options?: Partial<Omit<TableConfig<T>, "columns">>): TableDefinition<T>;
1662
+ export interface ParsedColumn {
1663
+ name: string;
1664
+ type: string;
1665
+ nullable: boolean;
1666
+ primaryKey: boolean;
1667
+ unique: boolean;
1668
+ default?: string;
1669
+ references?: {
1670
+ table: string;
1671
+ column: string;
1672
+ onDelete?: string;
1673
+ onUpdate?: string;
1674
+ };
1675
+ check?: string;
1676
+ generated?: {
1677
+ expression: string;
1678
+ stored: boolean;
1679
+ };
1680
+ array: boolean;
1681
+ arrayDimensions: number;
1682
+ }
1683
+ export interface ParsedTable {
1684
+ name: string;
1685
+ schema?: string;
1686
+ columns: ParsedColumn[];
1687
+ primaryKey?: string[];
1688
+ uniqueConstraints: Array<{
1689
+ columns: string[];
1690
+ name?: string;
1691
+ }>;
1692
+ checkConstraints: Array<{
1693
+ expression: string;
1694
+ name?: string;
1695
+ }>;
1696
+ foreignKeys: Array<{
1697
+ columns: string[];
1698
+ references: {
1699
+ table: string;
1700
+ columns: string[];
1701
+ };
1702
+ onDelete?: string;
1703
+ onUpdate?: string;
1704
+ name?: string;
1705
+ }>;
1706
+ }
1707
+ export declare function parseCreateTable(sql: string): ParsedTable;
1708
+ export declare function generateSchemaCode(table: ParsedTable, options?: {
1709
+ exportName?: string;
1710
+ }): string;
1711
+ export declare function introspectSQL(sql: string): {
1712
+ parsed: ParsedTable;
1713
+ code: string;
1714
+ };
1715
+ export declare function introspectMultiple(sql: string): Array<{
1716
+ parsed: ParsedTable;
1717
+ code: string;
1718
+ }>;
1719
+ export interface RelationConfig {
1720
+ from: string;
1721
+ to: string;
1722
+ through?: string;
1723
+ foreignKey?: string;
1724
+ references?: string;
1725
+ }
1726
+ export interface Relation<TFrom extends TableDefinition<Record<string, ColumnConfig>> = TableDefinition<Record<string, ColumnConfig>>, TTo extends TableDefinition<Record<string, ColumnConfig>> = TableDefinition<Record<string, ColumnConfig>>, TType extends "one" | "many" | "manyToMany" = "one" | "many" | "manyToMany"> {
1727
+ $type: TType;
1728
+ $from: TFrom;
1729
+ $to: TTo;
1730
+ $foreignKey: string;
1731
+ $references: string;
1732
+ $through?: TableDefinition<Record<string, ColumnConfig>>;
1733
+ $throughFromKey?: string;
1734
+ $throughToKey?: string;
1735
+ }
1736
+ export interface OneRelation<TFrom extends TableDefinition<Record<string, ColumnConfig>>, TTo extends TableDefinition<Record<string, ColumnConfig>>> extends Relation<TFrom, TTo, "one"> {
1737
+ $type: "one";
1738
+ }
1739
+ export interface ManyRelation<TFrom extends TableDefinition<Record<string, ColumnConfig>>, TTo extends TableDefinition<Record<string, ColumnConfig>>> extends Relation<TFrom, TTo, "many"> {
1740
+ $type: "many";
1741
+ }
1742
+ export interface ManyToManyRelation<TFrom extends TableDefinition<Record<string, ColumnConfig>>, TTo extends TableDefinition<Record<string, ColumnConfig>>, TThrough extends TableDefinition<Record<string, ColumnConfig>>> extends Relation<TFrom, TTo, "manyToMany"> {
1743
+ $type: "manyToMany";
1744
+ $through: TThrough;
1745
+ $throughFromKey: string;
1746
+ $throughToKey: string;
1747
+ }
1748
+ export declare function one<TFrom extends TableDefinition<Record<string, ColumnConfig>>, TTo extends TableDefinition<Record<string, ColumnConfig>>>(from: TFrom, to: TTo, options?: {
1749
+ foreignKey?: string;
1750
+ references?: string;
1751
+ }): OneRelation<TFrom, TTo>;
1752
+ export declare function many<TFrom extends TableDefinition<Record<string, ColumnConfig>>, TTo extends TableDefinition<Record<string, ColumnConfig>>>(from: TFrom, to: TTo, options?: {
1753
+ foreignKey?: string;
1754
+ references?: string;
1755
+ }): ManyRelation<TFrom, TTo>;
1756
+ export declare function manyToMany<TFrom extends TableDefinition<Record<string, ColumnConfig>>, TTo extends TableDefinition<Record<string, ColumnConfig>>, TThrough extends TableDefinition<Record<string, ColumnConfig>>>(from: TFrom, to: TTo, through: TThrough, options?: {
1757
+ fromKey?: string;
1758
+ toKey?: string;
1759
+ throughFromKey?: string;
1760
+ throughToKey?: string;
1761
+ }): ManyToManyRelation<TFrom, TTo, TThrough>;
1762
+ export interface PgEnumConfig<T extends readonly string[]> {
1763
+ /** Enum type name in PostgreSQL */
1764
+ $enumName: string;
1765
+ /** Allowed values */
1766
+ $enumValues: T;
1767
+ /** Creates a column using this enum type */
1768
+ (columnName?: string): ColumnBuilder<T[number]> & {
1769
+ $enumName: string;
1770
+ };
1771
+ /** Infer TypeScript type from enum */
1772
+ $inferEnum: T[number];
1773
+ /** Get enum values array */
1774
+ values: T;
1775
+ /** Get enum type name */
1776
+ name: string;
1777
+ /** Check if value is valid enum member (type guard) */
1778
+ includes(value: unknown): value is T[number];
1779
+ }
1780
+ /**
1781
+ * Create a PostgreSQL ENUM type
1782
+ *
1783
+ * @param name - PostgreSQL enum type name
1784
+ * @param values - Array of allowed values (literal types are automatically inferred)
1785
+ * @returns Enum config with column builder and helpers
1786
+ *
1787
+ * @example
1788
+ * ```typescript
1789
+ * export const roleEnum = pgEnum('user_role', ['admin', 'user', 'guest']);
1790
+ *
1791
+ * // In table definition
1792
+ * role: roleEnum('role').notNull().default('user'),
1793
+ *
1794
+ * // TypeScript type
1795
+ * type Role = typeof roleEnum.$inferEnum; // 'admin' | 'user' | 'guest'
1796
+ * ```
1797
+ */
1798
+ export declare function pgEnum<const T extends readonly string[]>(name: string, values: T): PgEnumConfig<T>;
1799
+ /**
1800
+ * Generate CREATE TYPE SQL for enum
1801
+ */
1802
+ export declare function generateEnumSQL(name: string, values: readonly string[]): string;
1803
+ /**
1804
+ * Generate DROP TYPE SQL for enum
1805
+ */
1806
+ export declare function dropEnumSQL(name: string): string;
1807
+ /**
1808
+ * Generate ALTER TYPE ADD VALUE SQL for adding new enum value
1809
+ */
1810
+ export declare function addEnumValueSQL(enumName: string, newValue: string, position?: {
1811
+ before?: string;
1812
+ after?: string;
1813
+ }): string;
1814
+ /**
1815
+ * PostgreSQL Function Definition for Schema Builder
1816
+ *
1817
+ * Provides type-safe function definitions that can be used in schema.ts
1818
+ * and referenced by triggers.
1819
+ */
1820
+ export type FunctionVolatility = "VOLATILE" | "STABLE" | "IMMUTABLE";
1821
+ export type FunctionParallel = "UNSAFE" | "RESTRICTED" | "SAFE";
1822
+ export type FunctionSecurity = "INVOKER" | "DEFINER";
1823
+ export interface FunctionArgument {
1824
+ /** Argument name */
1825
+ name: string;
1826
+ /** PostgreSQL type */
1827
+ type: string;
1828
+ /** Argument mode: IN (default), OUT, INOUT, VARIADIC */
1829
+ mode?: "IN" | "OUT" | "INOUT" | "VARIADIC";
1830
+ /** Default value (SQL expression) */
1831
+ default?: string;
1832
+ }
1833
+ export interface FunctionOptions {
1834
+ /** Function arguments */
1835
+ args?: FunctionArgument[];
1836
+ /** Return type (e.g., 'INTEGER', 'TRIGGER', 'SETOF UUID', 'TABLE(...)') */
1837
+ returns: string;
1838
+ /** Language (default: 'plpgsql') */
1839
+ language?: string;
1840
+ /** Volatility category */
1841
+ volatility?: FunctionVolatility;
1842
+ /** Parallel safety */
1843
+ parallel?: FunctionParallel;
1844
+ /** Security context */
1845
+ security?: FunctionSecurity;
1846
+ /** Is function STRICT (returns NULL if any arg is NULL) */
1847
+ strict?: boolean;
1848
+ /** Is function LEAKPROOF */
1849
+ leakproof?: boolean;
1850
+ /** Estimated execution cost */
1851
+ cost?: number;
1852
+ /** Estimated number of rows returned (for SETOF/TABLE) */
1853
+ rows?: number;
1854
+ /** SET configuration parameters */
1855
+ setConfig?: Record<string, string>;
1856
+ /**
1857
+ * Function body (between $$ and $$)
1858
+ * Use this for simple/medium complexity functions
1859
+ */
1860
+ body?: string;
1861
+ /**
1862
+ * Raw SQL body for complex functions
1863
+ * This is the complete body content between $$ and $$
1864
+ * including DECLARE block if needed
1865
+ */
1866
+ raw?: string;
1867
+ }
1868
+ export interface FunctionConfig {
1869
+ /** Function name */
1870
+ $functionName: string;
1871
+ /** Full configuration */
1872
+ $options: FunctionOptions;
1873
+ /** Marker for function type */
1874
+ $type: "function";
1875
+ }
1876
+ /**
1877
+ * Generate SQL for a function definition
1878
+ */
1879
+ export declare function generateFunctionSQL(config: FunctionConfig): string;
1880
+ /**
1881
+ * Generate DROP FUNCTION SQL
1882
+ */
1883
+ export declare function dropFunctionSQL(config: FunctionConfig, ifExists?: boolean): string;
1884
+ /**
1885
+ * Define a PostgreSQL function for use in schema definitions
1886
+ *
1887
+ * @example
1888
+ * ```typescript
1889
+ * // Simple trigger function
1890
+ * export const updateTimestamp = pgFunction('update_timestamp', {
1891
+ * returns: 'TRIGGER',
1892
+ * language: 'plpgsql',
1893
+ * body: `
1894
+ * NEW.updated_at = NOW();
1895
+ * RETURN NEW;
1896
+ * `
1897
+ * });
1898
+ *
1899
+ * // Function with arguments
1900
+ * export const calculateTotal = pgFunction('calculate_total', {
1901
+ * args: [
1902
+ * { name: 'base_amount', type: 'NUMERIC' },
1903
+ * { name: 'tax_rate', type: 'NUMERIC', default: '0.1' }
1904
+ * ],
1905
+ * returns: 'NUMERIC',
1906
+ * language: 'plpgsql',
1907
+ * volatility: 'STABLE',
1908
+ * body: `
1909
+ * RETURN base_amount * (1 + tax_rate);
1910
+ * `
1911
+ * });
1912
+ *
1913
+ * // Complex function with raw SQL
1914
+ * export const auditChanges = pgFunction('audit_changes', {
1915
+ * returns: 'TRIGGER',
1916
+ * language: 'plpgsql',
1917
+ * raw: `
1918
+ * DECLARE
1919
+ * payload JSONB;
1920
+ * BEGIN
1921
+ * IF TG_OP = 'INSERT' THEN
1922
+ * payload := to_jsonb(NEW);
1923
+ * ELSIF TG_OP = 'UPDATE' THEN
1924
+ * payload := jsonb_build_object('old', to_jsonb(OLD), 'new', to_jsonb(NEW));
1925
+ * ELSIF TG_OP = 'DELETE' THEN
1926
+ * payload := to_jsonb(OLD);
1927
+ * END IF;
1928
+ *
1929
+ * INSERT INTO audit_log (table_name, operation, data)
1930
+ * VALUES (TG_TABLE_NAME, TG_OP, payload);
1931
+ *
1932
+ * RETURN COALESCE(NEW, OLD);
1933
+ * END;
1934
+ * `
1935
+ * });
1936
+ * ```
1937
+ */
1938
+ export declare function pgFunction(name: string, options: FunctionOptions): FunctionConfig;
1939
+ /**
1940
+ * Check if a value is a FunctionConfig
1941
+ */
1942
+ export declare function isFunctionConfig(value: unknown): value is FunctionConfig;
1943
+ export type TriggerTiming = "BEFORE" | "AFTER" | "INSTEAD OF";
1944
+ export type TriggerEvent = "INSERT" | "UPDATE" | "DELETE" | "TRUNCATE";
1945
+ export type TriggerLevel = "ROW" | "STATEMENT";
1946
+ export interface TriggerOptions<TTable = unknown> {
1947
+ /**
1948
+ * Table the trigger is attached to
1949
+ * Can be a TableDefinition for type safety or a string
1950
+ */
1951
+ on: TTable | string;
1952
+ /**
1953
+ * BEFORE timing with events
1954
+ * Use this OR after/insteadOf, not multiple
1955
+ */
1956
+ before?: TriggerEvent | TriggerEvent[];
1957
+ /**
1958
+ * AFTER timing with events
1959
+ */
1960
+ after?: TriggerEvent | TriggerEvent[];
1961
+ /**
1962
+ * INSTEAD OF timing with events (for views only)
1963
+ */
1964
+ insteadOf?: TriggerEvent | TriggerEvent[];
1965
+ /**
1966
+ * UPDATE OF specific columns (only valid with UPDATE event)
1967
+ */
1968
+ updateOf?: string[];
1969
+ /**
1970
+ * FOR EACH ROW (default: true for row-level trigger)
1971
+ */
1972
+ forEachRow?: boolean;
1973
+ /**
1974
+ * FOR EACH STATEMENT
1975
+ */
1976
+ forEachStatement?: boolean;
1977
+ /**
1978
+ * WHEN condition (SQL expression)
1979
+ * Can reference OLD and NEW
1980
+ */
1981
+ when?: string;
1982
+ /**
1983
+ * REFERENCING clause for transition tables (PG10+)
1984
+ */
1985
+ referencing?: {
1986
+ oldTable?: string;
1987
+ newTable?: string;
1988
+ };
1989
+ /**
1990
+ * CONSTRAINT trigger (deferrable)
1991
+ */
1992
+ constraint?: boolean;
1993
+ /**
1994
+ * DEFERRABLE (only for constraint triggers)
1995
+ */
1996
+ deferrable?: boolean;
1997
+ /**
1998
+ * INITIALLY DEFERRED or INITIALLY IMMEDIATE
1999
+ */
2000
+ initially?: "DEFERRED" | "IMMEDIATE";
2001
+ /**
2002
+ * Function to execute
2003
+ * Can be a FunctionConfig for type safety or a string
2004
+ */
2005
+ execute: FunctionConfig | string;
2006
+ /**
2007
+ * Arguments to pass to the function
2008
+ */
2009
+ executeArgs?: string[];
2010
+ }
2011
+ export interface TriggerConfig<TTable = unknown> {
2012
+ /** Trigger name */
2013
+ $triggerName: string;
2014
+ /** Full configuration */
2015
+ $options: TriggerOptions<TTable>;
2016
+ /** Marker for trigger type */
2017
+ $type: "trigger";
2018
+ }
2019
+ /**
2020
+ * Generate SQL for a trigger definition
2021
+ */
2022
+ export declare function generateTriggerSQL(config: TriggerConfig): string;
2023
+ /**
2024
+ * Generate DROP TRIGGER SQL
2025
+ */
2026
+ export declare function dropTriggerSQL(config: TriggerConfig, ifExists?: boolean): string;
2027
+ /**
2028
+ * Define a PostgreSQL trigger for use in schema definitions
2029
+ *
2030
+ * @example
2031
+ * ```typescript
2032
+ * // Simple BEFORE UPDATE trigger
2033
+ * export const trgUpdateTimestamp = pgTrigger('trg_update_timestamp', {
2034
+ * on: usersTable,
2035
+ * before: 'UPDATE',
2036
+ * forEachRow: true,
2037
+ * execute: updateTimestampFunc
2038
+ * });
2039
+ *
2040
+ * // AFTER trigger on multiple events
2041
+ * export const trgAudit = pgTrigger('trg_audit', {
2042
+ * on: ordersTable,
2043
+ * after: ['INSERT', 'UPDATE', 'DELETE'],
2044
+ * forEachRow: true,
2045
+ * execute: auditChangesFunc
2046
+ * });
2047
+ *
2048
+ * // Trigger with WHEN condition
2049
+ * export const trgStatusChange = pgTrigger('trg_status_change', {
2050
+ * on: usersTable,
2051
+ * after: 'UPDATE',
2052
+ * updateOf: ['status'],
2053
+ * forEachRow: true,
2054
+ * when: 'OLD.status IS DISTINCT FROM NEW.status',
2055
+ * execute: notifyStatusChangeFunc
2056
+ * });
2057
+ *
2058
+ * // Statement-level trigger with transition tables
2059
+ * export const trgBulkUpdate = pgTrigger('trg_bulk_update', {
2060
+ * on: productsTable,
2061
+ * after: 'UPDATE',
2062
+ * forEachStatement: true,
2063
+ * referencing: {
2064
+ * oldTable: 'old_products',
2065
+ * newTable: 'new_products'
2066
+ * },
2067
+ * execute: processBulkUpdateFunc
2068
+ * });
2069
+ *
2070
+ * // INSTEAD OF trigger for views
2071
+ * export const trgViewInsert = pgTrigger('trg_view_insert', {
2072
+ * on: 'users_view',
2073
+ * insteadOf: 'INSERT',
2074
+ * forEachRow: true,
2075
+ * execute: handleViewInsertFunc
2076
+ * });
2077
+ *
2078
+ * // Constraint trigger (deferrable)
2079
+ * export const trgConstraint = pgTrigger('trg_constraint', {
2080
+ * on: ordersTable,
2081
+ * after: 'INSERT',
2082
+ * constraint: true,
2083
+ * deferrable: true,
2084
+ * initially: 'DEFERRED',
2085
+ * forEachRow: true,
2086
+ * execute: validateOrderFunc
2087
+ * });
2088
+ * ```
2089
+ */
2090
+ export declare function pgTrigger<TTable = unknown>(name: string, options: TriggerOptions<TTable>): TriggerConfig<TTable>;
2091
+ /**
2092
+ * Check if a value is a TriggerConfig
2093
+ */
2094
+ export declare function isTriggerConfig(value: unknown): value is TriggerConfig;
2095
+ /**
2096
+ * PostgreSQL Sequence Definition for Schema Builder
2097
+ *
2098
+ * Provides type-safe sequence definitions that can be used in schema.ts
2099
+ * and referenced by column defaults.
2100
+ */
2101
+ export interface SequenceOptions {
2102
+ /** Data type: smallint, integer (default), or bigint */
2103
+ as?: "smallint" | "integer" | "bigint";
2104
+ /** Starting value */
2105
+ start?: number;
2106
+ /** Increment by (can be negative for descending) */
2107
+ increment?: number;
2108
+ /** Minimum value (null for type default) */
2109
+ minValue?: number | null;
2110
+ /** Maximum value (null for type default) */
2111
+ maxValue?: number | null;
2112
+ /** Number of values to cache */
2113
+ cache?: number;
2114
+ /** Whether sequence wraps around at limits */
2115
+ cycle?: boolean;
2116
+ /** Owner table.column (e.g., 'users.id') */
2117
+ ownedBy?: string;
2118
+ }
2119
+ export interface SequenceConfig {
2120
+ readonly _type: "sequence";
2121
+ readonly name: string;
2122
+ readonly options: SequenceOptions;
2123
+ }
2124
+ /**
2125
+ * Define a PostgreSQL sequence
2126
+ *
2127
+ * @example
2128
+ * ```ts
2129
+ * // Simple sequence
2130
+ * export const orderSeq = pgSequence('order_seq');
2131
+ *
2132
+ * // Sequence with options
2133
+ * export const invoiceSeq = pgSequence('invoice_seq', {
2134
+ * start: 1000,
2135
+ * increment: 1,
2136
+ * cache: 10,
2137
+ * });
2138
+ *
2139
+ * // Cyclic sequence
2140
+ * export const rotatingSeq = pgSequence('rotating_seq', {
2141
+ * start: 1,
2142
+ * maxValue: 100,
2143
+ * cycle: true,
2144
+ * });
2145
+ *
2146
+ * // Owned sequence
2147
+ * export const userIdSeq = pgSequence('user_id_seq', {
2148
+ * ownedBy: 'users.id',
2149
+ * });
2150
+ * ```
2151
+ */
2152
+ export declare function pgSequence(name: string, options?: SequenceOptions): SequenceConfig;
2153
+ /**
2154
+ * Generate CREATE SEQUENCE SQL from a SequenceConfig
2155
+ */
2156
+ export declare function generateSequenceSQL(seq: SequenceConfig): string;
2157
+ /**
2158
+ * Generate DROP SEQUENCE SQL
2159
+ */
2160
+ export declare function dropSequenceSQL(seq: SequenceConfig): string;
2161
+ /**
2162
+ * Type guard to check if a value is a SequenceConfig
2163
+ */
2164
+ export declare function isSequenceConfig(value: unknown): value is SequenceConfig;
2165
+ /**
2166
+ * SQL Tagged Template Literal
2167
+ *
2168
+ * Use with VS Code extension "Inline SQL by qufiwefefwoyn" for PostgreSQL syntax highlighting.
2169
+ *
2170
+ * @example
2171
+ * ```typescript
2172
+ * import { sql } from 'relq/schema-builder';
2173
+ *
2174
+ * const query = sql`
2175
+ * SELECT * FROM users
2176
+ * WHERE id = ${userId}
2177
+ * `;
2178
+ * ```
2179
+ */
2180
+ export interface SQLTemplate {
2181
+ /** The raw SQL string with placeholders */
2182
+ readonly text: string;
2183
+ /** The values to be interpolated */
2184
+ readonly values: readonly unknown[];
2185
+ /** Get the final SQL string (for debugging) */
2186
+ toString(): string;
2187
+ /** Get parameterized query format ($1, $2, etc.) */
2188
+ toParameterized(): {
2189
+ text: string;
2190
+ values: unknown[];
2191
+ };
2192
+ }
2193
+ /**
2194
+ * Tagged template literal for SQL queries.
2195
+ * Works with "Inline SQL" VS Code extension for syntax highlighting.
2196
+ */
2197
+ export declare function sql(strings: TemplateStringsArray, ...values: unknown[]): SQLTemplate;
2198
+ export declare namespace sql {
2199
+ var raw: (value: string) => {
2200
+ __raw: string;
2201
+ };
2202
+ var id: (identifier: string) => {
2203
+ __raw: string;
2204
+ };
2205
+ var literal: (value: string | number | boolean | null) => {
2206
+ __raw: string;
2207
+ };
2208
+ }
2209
+ export type FunctionReturnType = "trigger" | "void" | "integer" | "bigint" | "smallint" | "real" | "double precision" | "numeric" | "text" | "varchar" | "char" | "boolean" | "json" | "jsonb" | "uuid" | "timestamp" | "timestamptz" | "date" | "time" | "timetz" | "interval" | "bytea" | "record" | "setof record" | (string & {});
2210
+ export type FunctionLanguage = "plpgsql" | "sql" | "plv8" | "plpython3u" | "plperl" | (string & {});
2211
+ export type FunctionType = "function" | "procedure";
2212
+ type FunctionVolatility$1 = "volatile" | "stable" | "immutable";
2213
+ type FunctionSecurity$1 = "invoker" | "definer";
2214
+ export interface FunctionParameter {
2215
+ name: string;
2216
+ type: string;
2217
+ mode?: "in" | "out" | "inout" | "variadic";
2218
+ default?: string;
2219
+ }
2220
+ interface FunctionOptions$1 {
2221
+ /** Function name */
2222
+ name: string;
2223
+ /** Return type with autocomplete */
2224
+ returns: FunctionReturnType;
2225
+ /** Language with autocomplete */
2226
+ language: FunctionLanguage;
2227
+ /** Function or procedure */
2228
+ as?: FunctionType;
2229
+ /** Function parameters */
2230
+ parameters?: FunctionParameter[];
2231
+ /** Function body (use sql template) */
2232
+ body: SQLTemplate | string;
2233
+ /** Volatility setting */
2234
+ volatility?: FunctionVolatility$1;
2235
+ /** Security setting */
2236
+ security?: FunctionSecurity$1;
2237
+ /** Schema to create in */
2238
+ schema?: string;
2239
+ /** Replace if exists */
2240
+ orReplace?: boolean;
2241
+ /** Cost estimate */
2242
+ cost?: number;
2243
+ /** Rows estimate (for set-returning functions) */
2244
+ rows?: number;
2245
+ /** Parallel safety */
2246
+ parallel?: "unsafe" | "restricted" | "safe";
2247
+ }
2248
+ export interface FunctionDefinition {
2249
+ /** Function name */
2250
+ readonly name: string;
2251
+ /** Full function configuration */
2252
+ readonly options: Readonly<FunctionOptions$1>;
2253
+ /** Generate CREATE FUNCTION SQL */
2254
+ toSQL(): string;
2255
+ /** Generate DROP FUNCTION SQL */
2256
+ toDropSQL(): string;
2257
+ }
2258
+ /**
2259
+ * Create a PostgreSQL function definition.
2260
+ *
2261
+ * @param options Function configuration
2262
+ * @returns Function definition with SQL generation
2263
+ */
2264
+ export declare function createFunction(options: FunctionOptions$1): FunctionDefinition;
2265
+
2266
+ export {
2267
+ FunctionOptions$1 as FunctionOptions,
2268
+ FunctionSecurity$1 as FunctionSecurity,
2269
+ FunctionVolatility$1 as FunctionVolatility,
2270
+ };
2271
+
2272
+ export {};