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