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,200 @@
1
+ export class ArrayUuidConditionBuilder {
2
+ parent;
3
+ constructor(parent) {
4
+ this.parent = parent;
5
+ }
6
+ allValid(column) {
7
+ this.parent.conditions.push({
8
+ method: 'array_uuid_all_valid',
9
+ column,
10
+ values: {}
11
+ });
12
+ return this.parent;
13
+ }
14
+ hasVersion(column, version) {
15
+ this.parent.conditions.push({
16
+ method: 'array_uuid_has_version',
17
+ column,
18
+ values: { version }
19
+ });
20
+ return this.parent;
21
+ }
22
+ equals(column, uuid) {
23
+ this.parent.conditions.push({
24
+ method: 'array_uuid_equals',
25
+ column,
26
+ values: { uuid }
27
+ });
28
+ return this.parent;
29
+ }
30
+ }
31
+ export class ArrayDateConditionBuilder {
32
+ parent;
33
+ constructor(parent) {
34
+ this.parent = parent;
35
+ }
36
+ before(column, date) {
37
+ this.parent.conditions.push({
38
+ method: 'array_date_before',
39
+ column,
40
+ values: { date: date instanceof Date ? date.toISOString() : date }
41
+ });
42
+ return this.parent;
43
+ }
44
+ after(column, date) {
45
+ this.parent.conditions.push({
46
+ method: 'array_date_after',
47
+ column,
48
+ values: { date: date instanceof Date ? date.toISOString() : date }
49
+ });
50
+ return this.parent;
51
+ }
52
+ between(column, start, end) {
53
+ this.parent.conditions.push({
54
+ method: 'array_date_between',
55
+ column,
56
+ values: {
57
+ start: start instanceof Date ? start.toISOString() : start,
58
+ end: end instanceof Date ? end.toISOString() : end
59
+ }
60
+ });
61
+ return this.parent;
62
+ }
63
+ withinDays(column, days) {
64
+ this.parent.conditions.push({
65
+ method: 'array_date_within_days',
66
+ column,
67
+ values: { days }
68
+ });
69
+ return this.parent;
70
+ }
71
+ equals(column, date) {
72
+ this.parent.conditions.push({
73
+ method: 'array_date_equals',
74
+ column,
75
+ values: { date: date instanceof Date ? date.toISOString() : date }
76
+ });
77
+ return this.parent;
78
+ }
79
+ hasToday(column) {
80
+ this.parent.conditions.push({
81
+ method: 'array_date_has_today',
82
+ column,
83
+ values: {}
84
+ });
85
+ return this.parent;
86
+ }
87
+ hasPast(column) {
88
+ this.parent.conditions.push({
89
+ method: 'array_date_has_past',
90
+ column,
91
+ values: {}
92
+ });
93
+ return this.parent;
94
+ }
95
+ hasFuture(column) {
96
+ this.parent.conditions.push({
97
+ method: 'array_date_has_future',
98
+ column,
99
+ values: {}
100
+ });
101
+ return this.parent;
102
+ }
103
+ hasThisWeek(column) {
104
+ this.parent.conditions.push({
105
+ method: 'array_date_has_this_week',
106
+ column,
107
+ values: {}
108
+ });
109
+ return this.parent;
110
+ }
111
+ hasThisMonth(column) {
112
+ this.parent.conditions.push({
113
+ method: 'array_date_has_this_month',
114
+ column,
115
+ values: {}
116
+ });
117
+ return this.parent;
118
+ }
119
+ hasThisYear(column) {
120
+ this.parent.conditions.push({
121
+ method: 'array_date_has_this_year',
122
+ column,
123
+ values: {}
124
+ });
125
+ return this.parent;
126
+ }
127
+ }
128
+ export class ArrayJsonbConditionBuilder {
129
+ parent;
130
+ constructor(parent) {
131
+ this.parent = parent;
132
+ }
133
+ hasKey(column, key) {
134
+ this.parent.conditions.push({
135
+ method: 'array_jsonb_has_key',
136
+ column,
137
+ values: { key }
138
+ });
139
+ return this.parent;
140
+ }
141
+ hasPath(column, path) {
142
+ this.parent.conditions.push({
143
+ method: 'array_jsonb_has_path',
144
+ column,
145
+ values: { path }
146
+ });
147
+ return this.parent;
148
+ }
149
+ contains(column, value) {
150
+ this.parent.conditions.push({
151
+ method: 'array_jsonb_contains',
152
+ column,
153
+ values: { value }
154
+ });
155
+ return this.parent;
156
+ }
157
+ containedBy(column, value) {
158
+ this.parent.conditions.push({
159
+ method: 'array_jsonb_contained_by',
160
+ column,
161
+ values: { value }
162
+ });
163
+ return this.parent;
164
+ }
165
+ equals(column, value) {
166
+ this.parent.conditions.push({
167
+ method: 'array_jsonb_equals',
168
+ column,
169
+ values: { value }
170
+ });
171
+ return this.parent;
172
+ }
173
+ pathEquals(column, path, value) {
174
+ this.parent.conditions.push({
175
+ method: 'array_jsonb_path_equals',
176
+ column,
177
+ values: { path, value }
178
+ });
179
+ return this.parent;
180
+ }
181
+ hasObject(column) {
182
+ this.parent.conditions.push({
183
+ method: 'array_jsonb_has_object',
184
+ column,
185
+ values: {}
186
+ });
187
+ return this.parent;
188
+ }
189
+ hasArray(column) {
190
+ this.parent.conditions.push({
191
+ method: 'array_jsonb_has_array',
192
+ column,
193
+ values: {}
194
+ });
195
+ return this.parent;
196
+ }
197
+ }
198
+ export { ArrayUuidConditionBuilder as Uuid };
199
+ export { ArrayDateConditionBuilder as Date };
200
+ export { ArrayJsonbConditionBuilder as Jsonb };
@@ -0,0 +1,142 @@
1
+ export class ArrayStringConditionBuilder {
2
+ parent;
3
+ constructor(parent) {
4
+ this.parent = parent;
5
+ }
6
+ startsWith(column, prefix) {
7
+ this.parent.conditions.push({
8
+ method: 'array_string_starts_with',
9
+ column,
10
+ values: { prefix }
11
+ });
12
+ return this.parent;
13
+ }
14
+ endsWith(column, suffix) {
15
+ this.parent.conditions.push({
16
+ method: 'array_string_ends_with',
17
+ column,
18
+ values: { suffix }
19
+ });
20
+ return this.parent;
21
+ }
22
+ contains(column, substring) {
23
+ this.parent.conditions.push({
24
+ method: 'array_string_contains',
25
+ column,
26
+ values: { substring }
27
+ });
28
+ return this.parent;
29
+ }
30
+ matches(column, pattern) {
31
+ this.parent.conditions.push({
32
+ method: 'array_string_matches',
33
+ column,
34
+ values: { pattern }
35
+ });
36
+ return this.parent;
37
+ }
38
+ imatches(column, pattern) {
39
+ this.parent.conditions.push({
40
+ method: 'array_string_imatches',
41
+ column,
42
+ values: { pattern }
43
+ });
44
+ return this.parent;
45
+ }
46
+ ilike(column, pattern) {
47
+ this.parent.conditions.push({
48
+ method: 'array_string_ilike',
49
+ column,
50
+ values: { pattern }
51
+ });
52
+ return this.parent;
53
+ }
54
+ allStartWith(column, prefix) {
55
+ this.parent.conditions.push({
56
+ method: 'array_string_all_start_with',
57
+ column,
58
+ values: { prefix }
59
+ });
60
+ return this.parent;
61
+ }
62
+ allEndWith(column, suffix) {
63
+ this.parent.conditions.push({
64
+ method: 'array_string_all_end_with',
65
+ column,
66
+ values: { suffix }
67
+ });
68
+ return this.parent;
69
+ }
70
+ allContain(column, substring) {
71
+ this.parent.conditions.push({
72
+ method: 'array_string_all_contain',
73
+ column,
74
+ values: { substring }
75
+ });
76
+ return this.parent;
77
+ }
78
+ lengthBetween(column, min, max) {
79
+ this.parent.conditions.push({
80
+ method: 'array_string_length_between',
81
+ column,
82
+ values: { min, max }
83
+ });
84
+ return this.parent;
85
+ }
86
+ hasEmpty(column) {
87
+ this.parent.conditions.push({
88
+ method: 'array_string_has_empty',
89
+ column,
90
+ values: {}
91
+ });
92
+ return this.parent;
93
+ }
94
+ hasNonEmpty(column) {
95
+ this.parent.conditions.push({
96
+ method: 'array_string_has_non_empty',
97
+ column,
98
+ values: {}
99
+ });
100
+ return this.parent;
101
+ }
102
+ hasUppercase(column) {
103
+ this.parent.conditions.push({
104
+ method: 'array_string_has_uppercase',
105
+ column,
106
+ values: {}
107
+ });
108
+ return this.parent;
109
+ }
110
+ hasLowercase(column) {
111
+ this.parent.conditions.push({
112
+ method: 'array_string_has_lowercase',
113
+ column,
114
+ values: {}
115
+ });
116
+ return this.parent;
117
+ }
118
+ hasNumeric(column) {
119
+ this.parent.conditions.push({
120
+ method: 'array_string_has_numeric',
121
+ column,
122
+ values: {}
123
+ });
124
+ return this.parent;
125
+ }
126
+ equals(column, value) {
127
+ this.parent.conditions.push({
128
+ method: 'array_string_equals',
129
+ column,
130
+ values: { value }
131
+ });
132
+ return this.parent;
133
+ }
134
+ iequals(column, value) {
135
+ this.parent.conditions.push({
136
+ method: 'array_string_iequals',
137
+ column,
138
+ values: { value }
139
+ });
140
+ return this.parent;
141
+ }
142
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,275 @@
1
+ import format from "../../addons/pg-format.js";
2
+ import { JsonbConditionCollector, buildJsonbConditionSQL } from "./jsonb-condition-builder.js";
3
+ import { ArrayConditionCollector, buildArrayConditionSQL } from "./array-condition-builder.js";
4
+ import { FulltextConditionCollector, buildFulltextConditionSQL } from "./fulltext-condition-builder.js";
5
+ import { RangeConditionCollector, buildRangeConditionSQL } from "./range-condition-builder.js";
6
+ import { GeometricConditionCollector, buildGeometricConditionSQL } from "./geometric-condition-builder.js";
7
+ import { NetworkConditionCollector, buildNetworkConditionSQL } from "./network-condition-builder.js";
8
+ export class ConditionCollector {
9
+ conditions = [];
10
+ _jsonb;
11
+ _array;
12
+ _fulltext;
13
+ _range;
14
+ _geometric;
15
+ _network;
16
+ get jsonb() {
17
+ if (!this._jsonb) {
18
+ this._jsonb = new JsonbConditionCollector(this);
19
+ }
20
+ return this._jsonb;
21
+ }
22
+ get array() {
23
+ if (!this._array) {
24
+ this._array = new ArrayConditionCollector(this);
25
+ }
26
+ return this._array;
27
+ }
28
+ get fulltext() {
29
+ if (!this._fulltext) {
30
+ this._fulltext = new FulltextConditionCollector(this);
31
+ }
32
+ return this._fulltext;
33
+ }
34
+ get range() {
35
+ if (!this._range) {
36
+ this._range = new RangeConditionCollector(this);
37
+ }
38
+ return this._range;
39
+ }
40
+ get geometric() {
41
+ if (!this._geometric) {
42
+ this._geometric = new GeometricConditionCollector(this);
43
+ }
44
+ return this._geometric;
45
+ }
46
+ get network() {
47
+ if (!this._network) {
48
+ this._network = new NetworkConditionCollector(this);
49
+ }
50
+ return this._network;
51
+ }
52
+ equal(column, value) {
53
+ this.conditions.push({ method: 'equal', column, values: value });
54
+ return this;
55
+ }
56
+ notEqual(column, value) {
57
+ this.conditions.push({ method: 'notEqual', column, values: value });
58
+ return this;
59
+ }
60
+ lessThan(column, value) {
61
+ this.conditions.push({ method: 'lessThan', column, values: value });
62
+ return this;
63
+ }
64
+ lessThanEqual(column, value) {
65
+ this.conditions.push({ method: 'lessThanEqual', column, values: value });
66
+ return this;
67
+ }
68
+ greaterThan(column, value) {
69
+ this.conditions.push({ method: 'greaterThan', column, values: value });
70
+ return this;
71
+ }
72
+ greaterThanEqual(column, value) {
73
+ this.conditions.push({ method: 'greaterThanEqual', column, values: value });
74
+ return this;
75
+ }
76
+ isNull(column) {
77
+ this.conditions.push({ method: 'isNull', column });
78
+ return this;
79
+ }
80
+ isNotNull(column) {
81
+ this.conditions.push({ method: 'isNotNull', column });
82
+ return this;
83
+ }
84
+ between(column, start, end) {
85
+ this.conditions.push({ method: 'between', column, values: [start, end] });
86
+ return this;
87
+ }
88
+ notBetween(column, start, end) {
89
+ this.conditions.push({ method: 'notBetween', column, values: [start, end] });
90
+ return this;
91
+ }
92
+ startsWith(column, value) {
93
+ this.conditions.push({ method: 'startsWith', column, values: value });
94
+ return this;
95
+ }
96
+ notStartsWith(column, value) {
97
+ this.conditions.push({ method: 'notStartsWith', column, values: value });
98
+ return this;
99
+ }
100
+ endsWith(column, value) {
101
+ this.conditions.push({ method: 'endsWith', column, values: value });
102
+ return this;
103
+ }
104
+ notEndsWith(column, value) {
105
+ this.conditions.push({ method: 'notEndsWith', column, values: value });
106
+ return this;
107
+ }
108
+ contains(column, value) {
109
+ this.conditions.push({ method: 'contains', column, values: value });
110
+ return this;
111
+ }
112
+ notContains(column, value) {
113
+ this.conditions.push({ method: 'notContains', column, values: value });
114
+ return this;
115
+ }
116
+ like(column, pattern) {
117
+ this.conditions.push({ method: 'like', column, values: pattern });
118
+ return this;
119
+ }
120
+ notLike(column, pattern) {
121
+ this.conditions.push({ method: 'notLike', column, values: pattern });
122
+ return this;
123
+ }
124
+ ilike(column, pattern) {
125
+ this.conditions.push({ method: 'ilike', column, values: pattern });
126
+ return this;
127
+ }
128
+ in(column, values) {
129
+ this.conditions.push({ method: 'in', column, values });
130
+ return this;
131
+ }
132
+ notIn(column, values) {
133
+ this.conditions.push({ method: 'notIn', column, values });
134
+ return this;
135
+ }
136
+ exists(subquery) {
137
+ this.conditions.push({ method: 'exists', values: subquery });
138
+ return this;
139
+ }
140
+ notExists(subquery) {
141
+ this.conditions.push({ method: 'notExists', values: subquery });
142
+ return this;
143
+ }
144
+ search(column, value) {
145
+ this.conditions.push({ method: 'search', column, values: value });
146
+ return this;
147
+ }
148
+ notSearch(column, value) {
149
+ this.conditions.push({ method: 'notSearch', column, values: value });
150
+ return this;
151
+ }
152
+ or(callback) {
153
+ const subBuilder = new ConditionCollector();
154
+ callback(subBuilder);
155
+ this.conditions.push({ method: 'or', values: subBuilder.getConditions() });
156
+ return this;
157
+ }
158
+ and(callback) {
159
+ const subBuilder = new ConditionCollector();
160
+ callback(subBuilder);
161
+ this.conditions.push({ method: 'and', values: subBuilder.getConditions() });
162
+ return this;
163
+ }
164
+ raw(condition) {
165
+ this.conditions.push({ method: 'raw', values: condition });
166
+ return this;
167
+ }
168
+ getConditions() {
169
+ return this.conditions;
170
+ }
171
+ }
172
+ export function buildConditionSQL(condition) {
173
+ const { method, column, values } = condition;
174
+ if (method.startsWith('jsonb_')) {
175
+ return buildJsonbConditionSQL(condition);
176
+ }
177
+ if (method.startsWith('array_')) {
178
+ return buildArrayConditionSQL(condition);
179
+ }
180
+ if (method.startsWith('fulltext_')) {
181
+ return buildFulltextConditionSQL(condition);
182
+ }
183
+ if (method.startsWith('range_')) {
184
+ return buildRangeConditionSQL(condition);
185
+ }
186
+ if (method.startsWith('geometric_')) {
187
+ return buildGeometricConditionSQL(condition);
188
+ }
189
+ if (method.startsWith('network_')) {
190
+ return buildNetworkConditionSQL(condition);
191
+ }
192
+ switch (method) {
193
+ case 'equal':
194
+ if (Array.isArray(values) && values.length > 1) {
195
+ return format('%I IN %L', column, values);
196
+ }
197
+ return format('%I = %L', column, Array.isArray(values) ? values[0] : values);
198
+ case 'notEqual':
199
+ if (Array.isArray(values) && values.length > 1) {
200
+ return format('%I NOT IN %L', column, values);
201
+ }
202
+ return format('%I != %L', column, Array.isArray(values) ? values[0] : values);
203
+ case 'lessThan':
204
+ return format('%I < %L', column, Array.isArray(values) ? values[0] : values);
205
+ case 'lessThanEqual':
206
+ return format('%I <= %L', column, Array.isArray(values) ? values[0] : values);
207
+ case 'greaterThan':
208
+ return format('%I > %L', column, Array.isArray(values) ? values[0] : values);
209
+ case 'greaterThanEqual':
210
+ return format('%I >= %L', column, Array.isArray(values) ? values[0] : values);
211
+ case 'isNull':
212
+ return format('%I IS NULL', column);
213
+ case 'isNotNull':
214
+ return format('%I IS NOT NULL', column);
215
+ case 'between': {
216
+ const [start, end] = values;
217
+ return format('%I BETWEEN %L AND %L', column, start, end);
218
+ }
219
+ case 'notBetween': {
220
+ const [notStart, notEnd] = values;
221
+ return format('%I NOT BETWEEN %L AND %L', column, notStart, notEnd);
222
+ }
223
+ case 'startsWith':
224
+ return format('%I LIKE %L', column, `${values}%`);
225
+ case 'notStartsWith':
226
+ return format('%I NOT LIKE %L', column, `${values}%`);
227
+ case 'endsWith':
228
+ return format('%I LIKE %L', column, `%${values}`);
229
+ case 'notEndsWith':
230
+ return format('%I NOT LIKE %L', column, `%${values}`);
231
+ case 'contains':
232
+ return format('%I LIKE %L', column, `%${values}%`);
233
+ case 'notContains':
234
+ return format('%I NOT LIKE %L', column, `%${values}%`);
235
+ case 'like':
236
+ return format('%I LIKE %L', column, values);
237
+ case 'notLike':
238
+ return format('%I NOT LIKE %L', column, values);
239
+ case 'ilike':
240
+ return format('%I ILIKE %L', column, values);
241
+ case 'in': {
242
+ const valueList = Array.isArray(values) ? values : [values];
243
+ const formattedValues = valueList.map(v => format('%L', v)).join(', ');
244
+ return format('%I IN (%s)', column, formattedValues);
245
+ }
246
+ case 'notIn': {
247
+ const valueList = Array.isArray(values) ? values : [values];
248
+ const formattedValues = valueList.map(v => format('%L', v)).join(', ');
249
+ return format('%I NOT IN (%s)', column, formattedValues);
250
+ }
251
+ case 'exists':
252
+ return format('EXISTS (%s)', values);
253
+ case 'notExists':
254
+ return format('NOT EXISTS (%s)', values);
255
+ case 'search':
256
+ return format('to_tsvector(%I) @@ plainto_tsquery(%L)', column, values);
257
+ case 'notSearch':
258
+ return format('NOT (to_tsvector(%I) @@ plainto_tsquery(%L))', column, values);
259
+ case 'or': {
260
+ const orConditions = values;
261
+ return `(${orConditions.map(c => buildConditionSQL(c)).join(' OR ')})`;
262
+ }
263
+ case 'and': {
264
+ const andConditions = values;
265
+ return `(${andConditions.map(c => buildConditionSQL(c)).join(' AND ')})`;
266
+ }
267
+ case 'raw':
268
+ return values;
269
+ default:
270
+ return '';
271
+ }
272
+ }
273
+ export function buildConditionsSQL(conditions) {
274
+ return conditions.map(condition => buildConditionSQL(condition)).join(' AND ');
275
+ }
@@ -0,0 +1,53 @@
1
+ import format from "../../addons/pg-format.js";
2
+ export class FulltextConditionCollector {
3
+ parent;
4
+ constructor(parent) {
5
+ this.parent = parent;
6
+ }
7
+ search(column, query, config = 'english') {
8
+ this.parent.conditions.push({
9
+ method: 'fulltext_search',
10
+ column,
11
+ values: { query, config }
12
+ });
13
+ return this.parent;
14
+ }
15
+ match(column, query, config = 'english') {
16
+ return this.search(column, query, config);
17
+ }
18
+ rank(column, query, minRank = 0, config = 'english') {
19
+ this.parent.conditions.push({
20
+ method: 'fulltext_rank',
21
+ column,
22
+ values: { query, minRank, config }
23
+ });
24
+ return this.parent;
25
+ }
26
+ }
27
+ export function buildFulltextConditionSQL(condition) {
28
+ const { method, column, values } = condition;
29
+ switch (method) {
30
+ case 'fulltext_search': {
31
+ const { query, config } = values;
32
+ const isTsVector = column?.endsWith('_vector') || column?.endsWith('_tsvector');
33
+ if (isTsVector) {
34
+ return format('%I @@ plainto_tsquery(%L, %L)', column, config, query);
35
+ }
36
+ else {
37
+ return format('to_tsvector(%L, %I) @@ plainto_tsquery(%L, %L)', config, column, config, query);
38
+ }
39
+ }
40
+ case 'fulltext_rank': {
41
+ const { query, minRank, config } = values;
42
+ const isTsVector = column?.endsWith('_vector') || column?.endsWith('_tsvector');
43
+ if (isTsVector) {
44
+ return format('ts_rank(%I, plainto_tsquery(%L, %L)) > %L', column, config, query, minRank);
45
+ }
46
+ else {
47
+ return format('ts_rank(to_tsvector(%L, %I), plainto_tsquery(%L, %L)) > %L', config, column, config, query, minRank);
48
+ }
49
+ }
50
+ default:
51
+ return '';
52
+ }
53
+ }