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,150 @@
1
+ export function defineConfig(config) {
2
+ return {
3
+ ...config,
4
+ pool: {
5
+ min: 2,
6
+ max: 10,
7
+ idleTimeoutMs: 30000,
8
+ connectionTimeoutMs: 5000,
9
+ ...config.pool,
10
+ },
11
+ logging: {
12
+ queries: false,
13
+ parameters: false,
14
+ timing: false,
15
+ errors: true,
16
+ level: 'error',
17
+ ...config.logging,
18
+ },
19
+ cache: {
20
+ enabled: false,
21
+ strategy: 'lru',
22
+ maxSize: 1000,
23
+ ttl: 60000,
24
+ ...config.cache,
25
+ },
26
+ conventions: {
27
+ timestamps: {
28
+ createdAt: 'created_at',
29
+ updatedAt: 'updated_at',
30
+ deletedAt: false,
31
+ },
32
+ softDelete: false,
33
+ primaryKey: 'id',
34
+ ...config.conventions,
35
+ },
36
+ };
37
+ }
38
+ export function loadConfig(path) {
39
+ const configPath = path || findConfigFile();
40
+ if (!configPath) {
41
+ return Promise.resolve(defineConfig({}));
42
+ }
43
+ return import(configPath).then(module => {
44
+ if (module.default) {
45
+ return module.default;
46
+ }
47
+ return defineConfig({});
48
+ }).catch(() => {
49
+ return defineConfig({});
50
+ });
51
+ }
52
+ function findConfigFile() {
53
+ return null;
54
+ }
55
+ export function parseConnectionUrl(url) {
56
+ try {
57
+ const parsed = new URL(url);
58
+ return {
59
+ url,
60
+ host: parsed.hostname,
61
+ port: parsed.port ? parseInt(parsed.port, 10) : 5432,
62
+ database: parsed.pathname.slice(1),
63
+ user: parsed.username,
64
+ password: parsed.password,
65
+ ssl: parsed.searchParams.get('sslmode') || undefined,
66
+ };
67
+ }
68
+ catch {
69
+ return { url };
70
+ }
71
+ }
72
+ export function mergeConfigs(...configs) {
73
+ let result = {};
74
+ for (const config of configs) {
75
+ result = {
76
+ ...result,
77
+ ...config,
78
+ connection: config.connection !== undefined
79
+ ? { ...result.connection, ...config.connection }
80
+ : result.connection,
81
+ schema: config.schema !== undefined
82
+ ? (typeof config.schema === 'string'
83
+ ? config.schema
84
+ : (typeof result.schema === 'object'
85
+ ? { ...result.schema, ...config.schema }
86
+ : config.schema))
87
+ : result.schema,
88
+ migrations: config.migrations !== undefined
89
+ ? { ...result.migrations, ...config.migrations }
90
+ : result.migrations,
91
+ typeGeneration: config.typeGeneration !== undefined
92
+ ? { ...result.typeGeneration, ...config.typeGeneration }
93
+ : result.typeGeneration,
94
+ logging: config.logging !== undefined
95
+ ? { ...result.logging, ...config.logging }
96
+ : result.logging,
97
+ cache: config.cache !== undefined
98
+ ? { ...result.cache, ...config.cache }
99
+ : result.cache,
100
+ pool: config.pool !== undefined
101
+ ? { ...result.pool, ...config.pool }
102
+ : result.pool,
103
+ conventions: config.conventions !== undefined
104
+ ? {
105
+ ...result.conventions,
106
+ ...config.conventions,
107
+ timestamps: config.conventions?.timestamps !== undefined
108
+ ? { ...result.conventions?.timestamps, ...config.conventions.timestamps }
109
+ : result.conventions?.timestamps,
110
+ }
111
+ : result.conventions,
112
+ plugins: config.plugins !== undefined
113
+ ? [...(result.plugins || []), ...config.plugins]
114
+ : result.plugins,
115
+ };
116
+ }
117
+ return defineConfig(result);
118
+ }
119
+ export function validateConfig(config) {
120
+ const errors = [];
121
+ if (config.connection) {
122
+ if (!config.connection.url && !config.connection.host) {
123
+ errors.push('Connection requires either url or host');
124
+ }
125
+ }
126
+ if (config.migrations) {
127
+ if (!config.migrations.directory) {
128
+ errors.push('Migrations require a directory');
129
+ }
130
+ }
131
+ if (config.typeGeneration) {
132
+ if (!config.typeGeneration.output) {
133
+ errors.push('Type generation requires an output path');
134
+ }
135
+ }
136
+ if (config.pool) {
137
+ if (config.pool.min !== undefined && config.pool.max !== undefined) {
138
+ if (config.pool.min > config.pool.max) {
139
+ errors.push('Pool min cannot be greater than max');
140
+ }
141
+ }
142
+ if (config.pool.min !== undefined && config.pool.min < 0) {
143
+ errors.push('Pool min must be non-negative');
144
+ }
145
+ if (config.pool.max !== undefined && config.pool.max < 1) {
146
+ errors.push('Pool max must be at least 1');
147
+ }
148
+ }
149
+ return { valid: errors.length === 0, errors };
150
+ }
@@ -0,0 +1 @@
1
+ export { defineConfig, loadConfig, parseConnectionUrl, mergeConfigs, validateConfig, } from "./config.js";
@@ -0,0 +1,63 @@
1
+ export class RawValue {
2
+ value;
3
+ constructor(value) {
4
+ this.value = value;
5
+ }
6
+ toString() {
7
+ return this.value;
8
+ }
9
+ }
10
+ export class PgValue {
11
+ static NOW = new RawValue('NOW()');
12
+ static CURRENT_TIMESTAMP = new RawValue('CURRENT_TIMESTAMP');
13
+ static CURRENT_DATE = new RawValue('CURRENT_DATE');
14
+ static CURRENT_TIME = new RawValue('CURRENT_TIME');
15
+ static LOCALTIMESTAMP = new RawValue('LOCALTIMESTAMP');
16
+ static LOCALTIME = new RawValue('LOCALTIME');
17
+ static TRANSACTION_TIMESTAMP = new RawValue('transaction_timestamp()');
18
+ static STATEMENT_TIMESTAMP = new RawValue('statement_timestamp()');
19
+ static CLOCK_TIMESTAMP = new RawValue('clock_timestamp()');
20
+ static gen_random_uuid() {
21
+ return new RawValue('gen_random_uuid()');
22
+ }
23
+ static uuid_generate_v1() {
24
+ return new RawValue('uuid_generate_v1()');
25
+ }
26
+ static uuid_generate_v4() {
27
+ return new RawValue('uuid_generate_v4()');
28
+ }
29
+ static nextval(sequenceName) {
30
+ return new RawValue(`nextval('${sequenceName}')`);
31
+ }
32
+ static currval(sequenceName) {
33
+ return new RawValue(`currval('${sequenceName}')`);
34
+ }
35
+ static lastval() {
36
+ return new RawValue('lastval()');
37
+ }
38
+ static setval(sequenceName, value) {
39
+ return new RawValue(`setval('${sequenceName}', ${value})`);
40
+ }
41
+ static DEFAULT = new RawValue('DEFAULT');
42
+ static NULL = new RawValue('NULL');
43
+ static TRUE = new RawValue('TRUE');
44
+ static FALSE = new RawValue('FALSE');
45
+ static EMPTY_ARRAY = new RawValue('ARRAY[]::text[]');
46
+ static EMPTY_JSONB_OBJECT = new RawValue("'{}'::jsonb");
47
+ static EMPTY_JSONB_ARRAY = new RawValue("'[]'::jsonb");
48
+ static raw(sql) {
49
+ return new RawValue(sql);
50
+ }
51
+ static array(values, type = 'text') {
52
+ const formatted = values.map(v => `'${String(v).replace(/'/g, "''")}'`).join(',');
53
+ return new RawValue(`ARRAY[${formatted}]::${type}[]`);
54
+ }
55
+ static jsonb(obj) {
56
+ return new RawValue(`'${JSON.stringify(obj)}'::jsonb`);
57
+ }
58
+ static cast(value, type) {
59
+ const escaped = String(value).replace(/'/g, "''");
60
+ return new RawValue(`'${escaped}'::${type}`);
61
+ }
62
+ }
63
+ export const PG = PgValue;
@@ -0,0 +1,308 @@
1
+ import format from "../../addons/pg-format.js";
2
+ import { RelqBuilderError } from "../errors/relq-errors.js";
3
+ export class CopyToBuilder {
4
+ tableName;
5
+ queryString;
6
+ columns = [];
7
+ destination = 'STDOUT';
8
+ options = {};
9
+ constructor(source) {
10
+ if (source) {
11
+ this.tableName = source;
12
+ }
13
+ }
14
+ table(tableName) {
15
+ this.tableName = tableName;
16
+ return this;
17
+ }
18
+ query(sql) {
19
+ this.queryString = sql;
20
+ this.tableName = undefined;
21
+ return this;
22
+ }
23
+ only(...columnNames) {
24
+ this.columns = columnNames;
25
+ return this;
26
+ }
27
+ toStdout() {
28
+ this.destination = 'STDOUT';
29
+ return this;
30
+ }
31
+ toFile(filename) {
32
+ this.destination = format('%L', filename);
33
+ return this;
34
+ }
35
+ toProgram(command) {
36
+ this.destination = format('PROGRAM %L', command);
37
+ return this;
38
+ }
39
+ csv() {
40
+ this.options.format = 'CSV';
41
+ return this;
42
+ }
43
+ binary() {
44
+ this.options.format = 'BINARY';
45
+ return this;
46
+ }
47
+ text() {
48
+ this.options.format = 'TEXT';
49
+ return this;
50
+ }
51
+ withFormat(fmt) {
52
+ this.options.format = fmt;
53
+ return this;
54
+ }
55
+ withHeader(value = true) {
56
+ this.options.header = value;
57
+ return this;
58
+ }
59
+ withDelimiter(delimiter) {
60
+ this.options.delimiter = delimiter;
61
+ return this;
62
+ }
63
+ withNull(nullString) {
64
+ this.options.null = nullString;
65
+ return this;
66
+ }
67
+ withQuote(quoteChar) {
68
+ this.options.quote = quoteChar;
69
+ return this;
70
+ }
71
+ withEscape(escapeChar) {
72
+ this.options.escape = escapeChar;
73
+ return this;
74
+ }
75
+ withEncoding(encoding) {
76
+ this.options.encoding = encoding;
77
+ return this;
78
+ }
79
+ forceQuote(columns) {
80
+ this.options.forceQuote = columns;
81
+ return this;
82
+ }
83
+ toString() {
84
+ const parts = ['COPY'];
85
+ if (this.queryString) {
86
+ parts.push(`(${this.queryString})`);
87
+ }
88
+ else if (this.tableName) {
89
+ parts.push(format('%I', this.tableName));
90
+ if (this.columns.length > 0) {
91
+ const cols = this.columns.map(c => format('%I', c)).join(', ');
92
+ parts.push(`(${cols})`);
93
+ }
94
+ }
95
+ else {
96
+ throw new RelqBuilderError('COPY TO requires either a table name or query', { builder: 'CopyToBuilder', missing: 'source', hint: 'Use .table() or .query()' });
97
+ }
98
+ parts.push('TO');
99
+ parts.push(this.destination);
100
+ const optionsParts = this.buildOptions();
101
+ if (optionsParts.length > 0) {
102
+ parts.push(`WITH (${optionsParts.join(', ')})`);
103
+ }
104
+ return parts.join(' ');
105
+ }
106
+ buildOptions() {
107
+ const opts = [];
108
+ if (this.options.format) {
109
+ opts.push(`FORMAT ${this.options.format}`);
110
+ }
111
+ if (this.options.header !== undefined) {
112
+ if (this.options.header === 'MATCH') {
113
+ opts.push('HEADER MATCH');
114
+ }
115
+ else {
116
+ opts.push(`HEADER ${this.options.header ? 'TRUE' : 'FALSE'}`);
117
+ }
118
+ }
119
+ if (this.options.delimiter) {
120
+ opts.push(format('DELIMITER %L', this.options.delimiter));
121
+ }
122
+ if (this.options.null !== undefined) {
123
+ opts.push(format('NULL %L', this.options.null));
124
+ }
125
+ if (this.options.quote) {
126
+ opts.push(format('QUOTE %L', this.options.quote));
127
+ }
128
+ if (this.options.escape) {
129
+ opts.push(format('ESCAPE %L', this.options.escape));
130
+ }
131
+ if (this.options.encoding) {
132
+ opts.push(format('ENCODING %L', this.options.encoding));
133
+ }
134
+ if (this.options.forceQuote) {
135
+ if (this.options.forceQuote === '*') {
136
+ opts.push('FORCE_QUOTE *');
137
+ }
138
+ else {
139
+ const cols = this.options.forceQuote.map(c => format('%I', c)).join(', ');
140
+ opts.push(`FORCE_QUOTE (${cols})`);
141
+ }
142
+ }
143
+ return opts;
144
+ }
145
+ }
146
+ export class CopyFromBuilder {
147
+ tableName;
148
+ columns = [];
149
+ source = 'STDIN';
150
+ options = {};
151
+ whereClause;
152
+ constructor(tableName) {
153
+ this.tableName = tableName;
154
+ }
155
+ only(...columnNames) {
156
+ this.columns = columnNames;
157
+ return this;
158
+ }
159
+ fromStdin() {
160
+ this.source = 'STDIN';
161
+ return this;
162
+ }
163
+ fromFile(filename) {
164
+ this.source = format('%L', filename);
165
+ return this;
166
+ }
167
+ fromProgram(command) {
168
+ this.source = format('PROGRAM %L', command);
169
+ return this;
170
+ }
171
+ csv() {
172
+ this.options.format = 'CSV';
173
+ return this;
174
+ }
175
+ binary() {
176
+ this.options.format = 'BINARY';
177
+ return this;
178
+ }
179
+ text() {
180
+ this.options.format = 'TEXT';
181
+ return this;
182
+ }
183
+ withFormat(fmt) {
184
+ this.options.format = fmt;
185
+ return this;
186
+ }
187
+ withHeader(value = true) {
188
+ this.options.header = value;
189
+ return this;
190
+ }
191
+ withDelimiter(delimiter) {
192
+ this.options.delimiter = delimiter;
193
+ return this;
194
+ }
195
+ withNull(nullString) {
196
+ this.options.null = nullString;
197
+ return this;
198
+ }
199
+ withDefault(defaultString) {
200
+ this.options.default = defaultString;
201
+ return this;
202
+ }
203
+ withQuote(quoteChar) {
204
+ this.options.quote = quoteChar;
205
+ return this;
206
+ }
207
+ withEscape(escapeChar) {
208
+ this.options.escape = escapeChar;
209
+ return this;
210
+ }
211
+ withEncoding(encoding) {
212
+ this.options.encoding = encoding;
213
+ return this;
214
+ }
215
+ freeze(value = true) {
216
+ this.options.freeze = value;
217
+ return this;
218
+ }
219
+ forceNotNull(columns) {
220
+ this.options.forceNotNull = columns;
221
+ return this;
222
+ }
223
+ forceNull(columns) {
224
+ this.options.forceNull = columns;
225
+ return this;
226
+ }
227
+ onError(action) {
228
+ this.options.onError = action;
229
+ return this;
230
+ }
231
+ logVerbosity(level) {
232
+ this.options.logVerbosity = level;
233
+ return this;
234
+ }
235
+ where(condition) {
236
+ this.whereClause = condition;
237
+ return this;
238
+ }
239
+ toString() {
240
+ const parts = ['COPY'];
241
+ parts.push(format('%I', this.tableName));
242
+ if (this.columns.length > 0) {
243
+ const cols = this.columns.map(c => format('%I', c)).join(', ');
244
+ parts.push(`(${cols})`);
245
+ }
246
+ parts.push('FROM');
247
+ parts.push(this.source);
248
+ const optionsParts = this.buildOptions();
249
+ if (optionsParts.length > 0) {
250
+ parts.push(`WITH (${optionsParts.join(', ')})`);
251
+ }
252
+ if (this.whereClause) {
253
+ parts.push('WHERE');
254
+ parts.push(this.whereClause);
255
+ }
256
+ return parts.join(' ');
257
+ }
258
+ buildOptions() {
259
+ const opts = [];
260
+ if (this.options.format) {
261
+ opts.push(`FORMAT ${this.options.format}`);
262
+ }
263
+ if (this.options.freeze !== undefined) {
264
+ opts.push(`FREEZE ${this.options.freeze ? 'TRUE' : 'FALSE'}`);
265
+ }
266
+ if (this.options.header !== undefined) {
267
+ if (this.options.header === 'MATCH') {
268
+ opts.push('HEADER MATCH');
269
+ }
270
+ else {
271
+ opts.push(`HEADER ${this.options.header ? 'TRUE' : 'FALSE'}`);
272
+ }
273
+ }
274
+ if (this.options.delimiter) {
275
+ opts.push(format('DELIMITER %L', this.options.delimiter));
276
+ }
277
+ if (this.options.null !== undefined) {
278
+ opts.push(format('NULL %L', this.options.null));
279
+ }
280
+ if (this.options.default !== undefined) {
281
+ opts.push(format('DEFAULT %L', this.options.default));
282
+ }
283
+ if (this.options.quote) {
284
+ opts.push(format('QUOTE %L', this.options.quote));
285
+ }
286
+ if (this.options.escape) {
287
+ opts.push(format('ESCAPE %L', this.options.escape));
288
+ }
289
+ if (this.options.encoding) {
290
+ opts.push(format('ENCODING %L', this.options.encoding));
291
+ }
292
+ if (this.options.forceNotNull && this.options.forceNotNull.length > 0) {
293
+ const cols = this.options.forceNotNull.map(c => format('%I', c)).join(', ');
294
+ opts.push(`FORCE_NOT_NULL (${cols})`);
295
+ }
296
+ if (this.options.forceNull && this.options.forceNull.length > 0) {
297
+ const cols = this.options.forceNull.map(c => format('%I', c)).join(', ');
298
+ opts.push(`FORCE_NULL (${cols})`);
299
+ }
300
+ if (this.options.onError) {
301
+ opts.push(`ON_ERROR ${this.options.onError.toUpperCase()}`);
302
+ }
303
+ if (this.options.logVerbosity) {
304
+ opts.push(`LOG_VERBOSITY ${this.options.logVerbosity.toUpperCase()}`);
305
+ }
306
+ return opts;
307
+ }
308
+ }
@@ -0,0 +1 @@
1
+ export { CopyToBuilder, CopyFromBuilder } from "./copy-builder.js";