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,421 @@
1
+ import format from "../../addons/pg-format.js";
2
+ export class SqlFunction {
3
+ expression;
4
+ constructor(expression) {
5
+ this.expression = expression;
6
+ }
7
+ as(alias) {
8
+ return `${this.expression} AS ${format.ident(alias)}`;
9
+ }
10
+ toString() {
11
+ return this.expression;
12
+ }
13
+ }
14
+ export class StringFunctions {
15
+ static concat(...values) {
16
+ const args = values.map(v => typeof v === 'string' && v.includes('.') || /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v)
17
+ ? format.ident(v)
18
+ : format('%L', v)).join(', ');
19
+ return new SqlFunction(`concat(${args})`);
20
+ }
21
+ static concat_ws(separator, ...values) {
22
+ const sep = format('%L', separator);
23
+ const args = values.map(v => typeof v === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v)
24
+ ? format.ident(v)
25
+ : format('%L', v)).join(', ');
26
+ return new SqlFunction(`concat_ws(${sep}, ${args})`);
27
+ }
28
+ static lower(value) {
29
+ return new SqlFunction(format('lower(%I)', value));
30
+ }
31
+ static upper(value) {
32
+ return new SqlFunction(format('upper(%I)', value));
33
+ }
34
+ static initcap(value) {
35
+ return new SqlFunction(format('initcap(%I)', value));
36
+ }
37
+ static substring(str, start, length) {
38
+ const args = length
39
+ ? format('%I, %s, %s', str, start, length)
40
+ : format('%I, %s', str, start);
41
+ return new SqlFunction(`substring(${args})`);
42
+ }
43
+ static substr(str, start, length) {
44
+ return this.substring(str, start, length);
45
+ }
46
+ static strLength(value) {
47
+ return new SqlFunction(format('length(%I)', value));
48
+ }
49
+ static char_length(value) {
50
+ return new SqlFunction(format('char_length(%I)', value));
51
+ }
52
+ static octet_length(value) {
53
+ return new SqlFunction(format('octet_length(%I)', value));
54
+ }
55
+ static bit_length(value) {
56
+ return new SqlFunction(format('bit_length(%I)', value));
57
+ }
58
+ static trim(str, chars, side = 'both') {
59
+ if (chars) {
60
+ const sideStr = side === 'both' ? 'BOTH' : side === 'leading' ? 'LEADING' : 'TRAILING';
61
+ return new SqlFunction(format(`trim(${sideStr} %L FROM %I)`, chars, str));
62
+ }
63
+ return new SqlFunction(format('trim(%I)', str));
64
+ }
65
+ static ltrim(str, chars) {
66
+ if (chars) {
67
+ return new SqlFunction(format('ltrim(%I, %L)', str, chars));
68
+ }
69
+ return new SqlFunction(format('ltrim(%I)', str));
70
+ }
71
+ static rtrim(str, chars) {
72
+ if (chars) {
73
+ return new SqlFunction(format('rtrim(%I, %L)', str, chars));
74
+ }
75
+ return new SqlFunction(format('rtrim(%I)', str));
76
+ }
77
+ static btrim(str, chars) {
78
+ return this.trim(str, chars, 'both');
79
+ }
80
+ static position(substring, str) {
81
+ return new SqlFunction(format('position(%L IN %I)', substring, str));
82
+ }
83
+ static strpos(str, substring) {
84
+ return new SqlFunction(format('strpos(%I, %L)', str, substring));
85
+ }
86
+ static replace(str, from, to) {
87
+ return new SqlFunction(format('replace(%I, %L, %L)', str, from, to));
88
+ }
89
+ static translate(str, from, to) {
90
+ return new SqlFunction(format('translate(%I, %L, %L)', str, from, to));
91
+ }
92
+ static repeat(str, n) {
93
+ return new SqlFunction(format('repeat(%I, %s)', str, n));
94
+ }
95
+ static lpad(str, length, fill = ' ') {
96
+ return new SqlFunction(format('lpad(%I, %s, %L)', str, length, fill));
97
+ }
98
+ static rpad(str, length, fill = ' ') {
99
+ return new SqlFunction(format('rpad(%I, %s, %L)', str, length, fill));
100
+ }
101
+ static reverse(str) {
102
+ return new SqlFunction(format('reverse(%I)', str));
103
+ }
104
+ static split_part(str, delimiter, position) {
105
+ return new SqlFunction(format('split_part(%I, %L, %s)', str, delimiter, position));
106
+ }
107
+ static regexp_match(str, pattern, flags) {
108
+ if (flags) {
109
+ return new SqlFunction(format('regexp_match(%I, %L, %L)', str, pattern, flags));
110
+ }
111
+ return new SqlFunction(format('regexp_match(%I, %L)', str, pattern));
112
+ }
113
+ static regexp_matches(str, pattern, flags) {
114
+ if (flags) {
115
+ return new SqlFunction(format('regexp_matches(%I, %L, %L)', str, pattern, flags));
116
+ }
117
+ return new SqlFunction(format('regexp_matches(%I, %L)', str, pattern));
118
+ }
119
+ static regexp_replace(str, pattern, replacement, flags) {
120
+ if (flags) {
121
+ return new SqlFunction(format('regexp_replace(%I, %L, %L, %L)', str, pattern, replacement, flags));
122
+ }
123
+ return new SqlFunction(format('regexp_replace(%I, %L, %L)', str, pattern, replacement));
124
+ }
125
+ static regexp_split_to_array(str, pattern, flags) {
126
+ if (flags) {
127
+ return new SqlFunction(format('regexp_split_to_array(%I, %L, %L)', str, pattern, flags));
128
+ }
129
+ return new SqlFunction(format('regexp_split_to_array(%I, %L)', str, pattern));
130
+ }
131
+ static regexp_split_to_table(str, pattern, flags) {
132
+ if (flags) {
133
+ return new SqlFunction(format('regexp_split_to_table(%I, %L, %L)', str, pattern, flags));
134
+ }
135
+ return new SqlFunction(format('regexp_split_to_table(%I, %L)', str, pattern));
136
+ }
137
+ static encode(data, fmt) {
138
+ return new SqlFunction(format('encode(%I, %L)', data, fmt));
139
+ }
140
+ static decode(data, fmt) {
141
+ return new SqlFunction(format('decode(%I, %L)', data, fmt));
142
+ }
143
+ static md5(str) {
144
+ return new SqlFunction(format('md5(%I)', str));
145
+ }
146
+ static ascii(str) {
147
+ return new SqlFunction(format('ascii(%I)', str));
148
+ }
149
+ static chr(code) {
150
+ return new SqlFunction(`chr(${code})`);
151
+ }
152
+ static to_hex(num) {
153
+ const arg = typeof num === 'string' ? format.ident(num) : num;
154
+ return new SqlFunction(`to_hex(${arg})`);
155
+ }
156
+ static lpad_zero(str, width) {
157
+ return new SqlFunction(format('lpad(%I, %s, \'0\')', str, width));
158
+ }
159
+ static format(formatStr, ...values) {
160
+ const args = [format('%L', formatStr), ...values.map(v => typeof v === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v)
161
+ ? format.ident(v)
162
+ : format('%L', v))].join(', ');
163
+ return new SqlFunction(`format(${args})`);
164
+ }
165
+ static quote_ident(str) {
166
+ return new SqlFunction(format('quote_ident(%I)', str));
167
+ }
168
+ static quote_literal(str) {
169
+ return new SqlFunction(format('quote_literal(%I)', str));
170
+ }
171
+ static quote_nullable(str) {
172
+ return new SqlFunction(format('quote_nullable(%I)', str));
173
+ }
174
+ }
175
+ export class DateTimeFunctions {
176
+ static now() {
177
+ return new SqlFunction('now()');
178
+ }
179
+ static current_date() {
180
+ return new SqlFunction('CURRENT_DATE');
181
+ }
182
+ static current_time() {
183
+ return new SqlFunction('CURRENT_TIME');
184
+ }
185
+ static current_timestamp() {
186
+ return new SqlFunction('CURRENT_TIMESTAMP');
187
+ }
188
+ static transaction_timestamp() {
189
+ return new SqlFunction('transaction_timestamp()');
190
+ }
191
+ static statement_timestamp() {
192
+ return new SqlFunction('statement_timestamp()');
193
+ }
194
+ static clock_timestamp() {
195
+ return new SqlFunction('clock_timestamp()');
196
+ }
197
+ static localtimestamp() {
198
+ return new SqlFunction('localtimestamp');
199
+ }
200
+ static date_trunc(field, source) {
201
+ return new SqlFunction(format('date_trunc(%L, %I)', field, source));
202
+ }
203
+ static extract(field, source) {
204
+ return new SqlFunction(format('extract(%s FROM %I)', field.toUpperCase(), source));
205
+ }
206
+ static date_part(field, source) {
207
+ return new SqlFunction(format('date_part(%L, %I)', field, source));
208
+ }
209
+ static age(timestamp1, timestamp2) {
210
+ if (timestamp2) {
211
+ return new SqlFunction(format('age(%I, %I)', timestamp1, timestamp2));
212
+ }
213
+ return new SqlFunction(format('age(%I)', timestamp1));
214
+ }
215
+ static make_date(year, month, day) {
216
+ const y = typeof year === 'string' ? format.ident(year) : year;
217
+ const m = typeof month === 'string' ? format.ident(month) : month;
218
+ const d = typeof day === 'string' ? format.ident(day) : day;
219
+ return new SqlFunction(`make_date(${y}, ${m}, ${d})`);
220
+ }
221
+ static make_time(hour, min, sec) {
222
+ const h = typeof hour === 'string' ? format.ident(hour) : hour;
223
+ const m = typeof min === 'string' ? format.ident(min) : min;
224
+ const s = typeof sec === 'string' ? format.ident(sec) : sec;
225
+ return new SqlFunction(`make_time(${h}, ${m}, ${s})`);
226
+ }
227
+ static make_timestamp(year, month, day, hour, min, sec) {
228
+ const args = [year, month, day, hour, min, sec].map(v => typeof v === 'string' ? format.ident(v) : v).join(', ');
229
+ return new SqlFunction(`make_timestamp(${args})`);
230
+ }
231
+ static make_interval(years, months, weeks, days, hours, mins, secs) {
232
+ const parts = [];
233
+ if (years !== undefined)
234
+ parts.push(`years => ${years}`);
235
+ if (months !== undefined)
236
+ parts.push(`months => ${months}`);
237
+ if (weeks !== undefined)
238
+ parts.push(`weeks => ${weeks}`);
239
+ if (days !== undefined)
240
+ parts.push(`days => ${days}`);
241
+ if (hours !== undefined)
242
+ parts.push(`hours => ${hours}`);
243
+ if (mins !== undefined)
244
+ parts.push(`mins => ${mins}`);
245
+ if (secs !== undefined)
246
+ parts.push(`secs => ${secs}`);
247
+ return new SqlFunction(`make_interval(${parts.join(', ')})`);
248
+ }
249
+ static to_timestamp(unixTimestamp) {
250
+ const arg = typeof unixTimestamp === 'string' ? format.ident(unixTimestamp) : unixTimestamp;
251
+ return new SqlFunction(`to_timestamp(${arg})`);
252
+ }
253
+ static to_timestamp_format(text, formatPattern) {
254
+ return new SqlFunction(format('to_timestamp(%I, %L)', text, formatPattern));
255
+ }
256
+ static to_date(text, formatPattern) {
257
+ return new SqlFunction(format('to_date(%I, %L)', text, formatPattern));
258
+ }
259
+ static to_char(timestamp, formatPattern) {
260
+ return new SqlFunction(format('to_char(%I, %L)', timestamp, formatPattern));
261
+ }
262
+ static timezone(timestamp, timezone) {
263
+ return new SqlFunction(format('timezone(%L, %I)', timezone, timestamp));
264
+ }
265
+ static justify_days(interval) {
266
+ return new SqlFunction(format('justify_days(%I)', interval));
267
+ }
268
+ static justify_hours(interval) {
269
+ return new SqlFunction(format('justify_hours(%I)', interval));
270
+ }
271
+ static justify_interval(interval) {
272
+ return new SqlFunction(format('justify_interval(%I)', interval));
273
+ }
274
+ static isfinite(date) {
275
+ return new SqlFunction(format('isfinite(%I)', date));
276
+ }
277
+ }
278
+ export class MathFunctions {
279
+ static abs(x) {
280
+ const arg = typeof x === 'string' ? format.ident(x) : x;
281
+ return new SqlFunction(`abs(${arg})`);
282
+ }
283
+ static sign(x) {
284
+ const arg = typeof x === 'string' ? format.ident(x) : x;
285
+ return new SqlFunction(`sign(${arg})`);
286
+ }
287
+ static ceil(x) {
288
+ const arg = typeof x === 'string' ? format.ident(x) : x;
289
+ return new SqlFunction(`ceil(${arg})`);
290
+ }
291
+ static ceiling(x) {
292
+ return this.ceil(x);
293
+ }
294
+ static floor(x) {
295
+ const arg = typeof x === 'string' ? format.ident(x) : x;
296
+ return new SqlFunction(`floor(${arg})`);
297
+ }
298
+ static round(x, decimals = 0) {
299
+ const arg = typeof x === 'string' ? format.ident(x) : x;
300
+ return new SqlFunction(`round(${arg}, ${decimals})`);
301
+ }
302
+ static trunc(x, decimals = 0) {
303
+ const arg = typeof x === 'string' ? format.ident(x) : x;
304
+ return new SqlFunction(`trunc(${arg}, ${decimals})`);
305
+ }
306
+ static mod(dividend, divisor) {
307
+ const arg = typeof dividend === 'string' ? format.ident(dividend) : dividend;
308
+ return new SqlFunction(`mod(${arg}, ${divisor})`);
309
+ }
310
+ static div(dividend, divisor) {
311
+ const arg = typeof dividend === 'string' ? format.ident(dividend) : dividend;
312
+ return new SqlFunction(`div(${arg}, ${divisor})`);
313
+ }
314
+ static power(x, y) {
315
+ const arg = typeof x === 'string' ? format.ident(x) : x;
316
+ return new SqlFunction(`power(${arg}, ${y})`);
317
+ }
318
+ static sqrt(x) {
319
+ const arg = typeof x === 'string' ? format.ident(x) : x;
320
+ return new SqlFunction(`sqrt(${arg})`);
321
+ }
322
+ static cbrt(x) {
323
+ const arg = typeof x === 'string' ? format.ident(x) : x;
324
+ return new SqlFunction(`cbrt(${arg})`);
325
+ }
326
+ static exp(x) {
327
+ const arg = typeof x === 'string' ? format.ident(x) : x;
328
+ return new SqlFunction(`exp(${arg})`);
329
+ }
330
+ static ln(x) {
331
+ const arg = typeof x === 'string' ? format.ident(x) : x;
332
+ return new SqlFunction(`ln(${arg})`);
333
+ }
334
+ static log10(x) {
335
+ const arg = typeof x === 'string' ? format.ident(x) : x;
336
+ return new SqlFunction(`log10(${arg})`);
337
+ }
338
+ static log(base, x) {
339
+ const arg = typeof x === 'string' ? format.ident(x) : x;
340
+ return new SqlFunction(`log(${base}, ${arg})`);
341
+ }
342
+ static pi() {
343
+ return new SqlFunction('pi()');
344
+ }
345
+ static degrees(radians) {
346
+ const arg = typeof radians === 'string' ? format.ident(radians) : radians;
347
+ return new SqlFunction(`degrees(${arg})`);
348
+ }
349
+ static radians(degrees) {
350
+ const arg = typeof degrees === 'string' ? format.ident(degrees) : degrees;
351
+ return new SqlFunction(`radians(${arg})`);
352
+ }
353
+ static sin(x) {
354
+ const arg = typeof x === 'string' ? format.ident(x) : x;
355
+ return new SqlFunction(`sin(${arg})`);
356
+ }
357
+ static cos(x) {
358
+ const arg = typeof x === 'string' ? format.ident(x) : x;
359
+ return new SqlFunction(`cos(${arg})`);
360
+ }
361
+ static tan(x) {
362
+ const arg = typeof x === 'string' ? format.ident(x) : x;
363
+ return new SqlFunction(`tan(${arg})`);
364
+ }
365
+ static asin(x) {
366
+ const arg = typeof x === 'string' ? format.ident(x) : x;
367
+ return new SqlFunction(`asin(${arg})`);
368
+ }
369
+ static acos(x) {
370
+ const arg = typeof x === 'string' ? format.ident(x) : x;
371
+ return new SqlFunction(`acos(${arg})`);
372
+ }
373
+ static atan(x) {
374
+ const arg = typeof x === 'string' ? format.ident(x) : x;
375
+ return new SqlFunction(`atan(${arg})`);
376
+ }
377
+ static atan2(y, x) {
378
+ const yArg = typeof y === 'string' ? format.ident(y) : y;
379
+ const xArg = typeof x === 'string' ? format.ident(x) : x;
380
+ return new SqlFunction(`atan2(${yArg}, ${xArg})`);
381
+ }
382
+ static random() {
383
+ return new SqlFunction('random()');
384
+ }
385
+ static setseed(seed) {
386
+ return new SqlFunction(`setseed(${seed})`);
387
+ }
388
+ static gcd(a, b) {
389
+ const aArg = typeof a === 'string' ? format.ident(a) : a;
390
+ const bArg = typeof b === 'string' ? format.ident(b) : b;
391
+ return new SqlFunction(`gcd(${aArg}, ${bArg})`);
392
+ }
393
+ static lcm(a, b) {
394
+ const aArg = typeof a === 'string' ? format.ident(a) : a;
395
+ const bArg = typeof b === 'string' ? format.ident(b) : b;
396
+ return new SqlFunction(`lcm(${aArg}, ${bArg})`);
397
+ }
398
+ static factorial(n) {
399
+ const arg = typeof n === 'string' ? format.ident(n) : n;
400
+ return new SqlFunction(`factorial(${arg})`);
401
+ }
402
+ static greatest(...values) {
403
+ const args = values.map(v => typeof v === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v)
404
+ ? format.ident(v)
405
+ : format('%L', v)).join(', ');
406
+ return new SqlFunction(`greatest(${args})`);
407
+ }
408
+ static least(...values) {
409
+ const args = values.map(v => typeof v === 'string' && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v)
410
+ ? format.ident(v)
411
+ : format('%L', v)).join(', ');
412
+ return new SqlFunction(`least(${args})`);
413
+ }
414
+ static width_bucket(operand, min, max, count) {
415
+ const arg = typeof operand === 'string' ? format.ident(operand) : operand;
416
+ return new SqlFunction(`width_bucket(${arg}, ${min}, ${max}, ${count})`);
417
+ }
418
+ }
419
+ export { StringFunctions as String };
420
+ export { DateTimeFunctions as DateTime };
421
+ export { MathFunctions as Math };
@@ -0,0 +1,34 @@
1
+ export { default as relq } from "./core/query-builder.js";
2
+ export { relq as default } from "./core/query-builder.js";
3
+ export { QueryBuilder, TypedSelectBuilder, TypedInsertBuilder, TypedUpdateBuilder, TypedDeleteBuilder, TypedCountBuilder, relqFor } from "./core/query-builder.js";
4
+ export { Relq } from "./core/relq-client.js";
5
+ export { default as RelqClient } from "./core/relq-client.js";
6
+ export { RelqError, RelqConnectionError, RelqQueryError, RelqTransactionError, RelqConfigError, RelqTimeoutError, RelqPoolError, RelqEnvironmentError, RelqBuilderError, isRelqError, isRelqConnectionError, isRelqQueryError, isRelqBuilderError, wrapError, parsePostgresError, setupErrorHandler } from "./errors/relq-errors.js";
7
+ export { detectEnvironment, isServerless, isTraditional, isEdge, getEnvironmentDescription } from "./utils/environment-detection.js";
8
+ export { getSmartPoolDefaults, validatePoolConfig, mergeWithDefaults, formatPoolConfig } from "./utils/pool-defaults.js";
9
+ export * from "./types.js";
10
+ export { CreateIndexBuilder, DropIndexBuilder, ReindexBuilder } from "./indexing/index.js";
11
+ export { CreateTableBuilder, AlterTableBuilder, DropTableBuilder, ConstraintBuilder, PartitionBuilder, CreatePartitionBuilder, AttachPartitionBuilder, DetachPartitionBuilder, TruncateBuilder } from "./table/index.js";
12
+ export { CreateTriggerBuilder, DropTriggerBuilder } from "./trigger/index.js";
13
+ export { CreateFunctionBuilder, DropFunctionBuilder } from "./function/index.js";
14
+ export { CreateViewBuilder, DropViewBuilder, RefreshMaterializedViewBuilder } from "./view/index.js";
15
+ export { CreateSchemaBuilder, DropSchemaBuilder, GrantBuilder, RevokeBuilder, CreateRoleBuilder, AlterRoleBuilder, DropRoleBuilder, SetRoleBuilder, ReassignOwnedBuilder, DropOwnedBuilder, DefaultPrivilegesBuilder } from "./schema/index.js";
16
+ export { TransactionBuilder, SavepointBuilder } from "./transaction/index.js";
17
+ export { CTEBuilder } from "./cte/index.js";
18
+ export { WindowBuilder } from "./window/index.js";
19
+ export { SelectBuilder } from "./select/index.js";
20
+ export { InsertBuilder } from "./insert/index.js";
21
+ export { UpdateBuilder } from "./update/index.js";
22
+ export { DeleteBuilder } from "./delete/index.js";
23
+ export { CountBuilder } from "./count/index.js";
24
+ export { RawQueryBuilder } from "./raw/index.js";
25
+ export { CreateSequenceBuilder, AlterSequenceBuilder, DropSequenceBuilder } from "./sequence/index.js";
26
+ export { ExplainBuilder } from "./explain/index.js";
27
+ export { ListenBuilder, UnlistenBuilder, NotifyBuilder } from "./pubsub/index.js";
28
+ export { VacuumBuilder, AnalyzeBuilder } from "./maintenance/index.js";
29
+ export { CopyToBuilder, CopyFromBuilder } from "./copy/index.js";
30
+ export { QueryCache, CacheKeyBuilder, createQueryCacheMiddleware, withCache, createTableCache } from "./cache/index.js";
31
+ export { convertCase, format } from "./utils/index.js";
32
+ export { PgValue, PG, RawValue } from "./constants/pg-values.js";
33
+ export { F, SqlFunction, StringFunctions, DateTimeFunctions, MathFunctions, ArrayFunctions, JsonbFunctions, AggregateFunctions, ConditionalFunctions } from "./functions/index.js";
34
+ export { Case, CaseBuilder } from "./functions/case-builder.js";
@@ -0,0 +1,180 @@
1
+ import format from "../../addons/pg-format.js";
2
+ export class CreateIndexBuilder {
3
+ tableName;
4
+ indexName;
5
+ indexType;
6
+ columns = [];
7
+ expressionIndex;
8
+ whereClause;
9
+ includeColumns = [];
10
+ withOptions = {};
11
+ concurrentFlag = false;
12
+ ifNotExistsFlag = false;
13
+ uniqueFlag = false;
14
+ tablespaceValue;
15
+ operatorClass;
16
+ constructor(tableName, indexName) {
17
+ this.tableName = tableName;
18
+ this.indexName = indexName;
19
+ }
20
+ btree(columns) {
21
+ this.indexType = 'BTREE';
22
+ this.columns = this.normalizeColumns(columns);
23
+ return this;
24
+ }
25
+ hash(column) {
26
+ this.indexType = 'HASH';
27
+ this.columns = [{ column }];
28
+ return this;
29
+ }
30
+ gin(columns, opClass) {
31
+ this.indexType = 'GIN';
32
+ this.columns = columns.map(col => ({ column: col }));
33
+ if (opClass) {
34
+ this.operatorClass = opClass;
35
+ }
36
+ return this;
37
+ }
38
+ gist(columns, opClass) {
39
+ this.indexType = 'GIST';
40
+ this.columns = columns.map(col => ({ column: col }));
41
+ if (opClass) {
42
+ this.operatorClass = opClass;
43
+ }
44
+ return this;
45
+ }
46
+ brin(columns, pagesPerRange) {
47
+ this.indexType = 'BRIN';
48
+ this.columns = columns.map(col => ({ column: col }));
49
+ if (pagesPerRange) {
50
+ this.withOptions.pages_per_range = pagesPerRange;
51
+ }
52
+ return this;
53
+ }
54
+ spgist(columns) {
55
+ this.indexType = 'SPGIST';
56
+ this.columns = columns.map(col => ({ column: col }));
57
+ return this;
58
+ }
59
+ bloom(columns, options) {
60
+ this.indexType = 'BLOOM';
61
+ this.columns = columns.map(col => ({ column: col }));
62
+ if (options) {
63
+ this.withOptions = { ...this.withOptions, ...options };
64
+ }
65
+ return this;
66
+ }
67
+ unique() {
68
+ this.uniqueFlag = true;
69
+ return this;
70
+ }
71
+ where(condition) {
72
+ this.whereClause = condition;
73
+ return this;
74
+ }
75
+ partial(condition) {
76
+ return this.where(condition);
77
+ }
78
+ include(...columns) {
79
+ this.includeColumns.push(...columns);
80
+ return this;
81
+ }
82
+ with(options) {
83
+ this.withOptions = { ...this.withOptions, ...options };
84
+ return this;
85
+ }
86
+ concurrently() {
87
+ this.concurrentFlag = true;
88
+ return this;
89
+ }
90
+ ifNotExists() {
91
+ this.ifNotExistsFlag = true;
92
+ return this;
93
+ }
94
+ tablespace(name) {
95
+ this.tablespaceValue = name;
96
+ return this;
97
+ }
98
+ expression(expr) {
99
+ this.expressionIndex = expr;
100
+ return this;
101
+ }
102
+ fillfactor(percent) {
103
+ this.withOptions.fillfactor = percent;
104
+ return this;
105
+ }
106
+ normalizeColumns(columns) {
107
+ return columns.map(col => {
108
+ if (typeof col === 'string') {
109
+ return { column: col };
110
+ }
111
+ return col;
112
+ });
113
+ }
114
+ formatColumn(col) {
115
+ let result = format.ident(col.column);
116
+ if (col.collation) {
117
+ result += ` COLLATE ${format.ident(col.collation)}`;
118
+ }
119
+ if (col.opclass) {
120
+ result += ` ${col.opclass}`;
121
+ }
122
+ else if (this.operatorClass && this.columns.length === 1) {
123
+ result += ` ${this.operatorClass}`;
124
+ }
125
+ if (col.order) {
126
+ result += ` ${col.order}`;
127
+ }
128
+ if (col.nulls) {
129
+ result += ` NULLS ${col.nulls}`;
130
+ }
131
+ return result;
132
+ }
133
+ toString() {
134
+ let sql = 'CREATE';
135
+ if (this.uniqueFlag) {
136
+ sql += ' UNIQUE';
137
+ }
138
+ sql += ' INDEX';
139
+ if (this.concurrentFlag) {
140
+ sql += ' CONCURRENTLY';
141
+ }
142
+ if (this.ifNotExistsFlag) {
143
+ sql += ' IF NOT EXISTS';
144
+ }
145
+ sql += ` ${format.ident(this.indexName)} ON ${format.ident(this.tableName)}`;
146
+ if (this.indexType && this.indexType !== 'BTREE') {
147
+ sql += ` USING ${this.indexType}`;
148
+ }
149
+ if (this.expressionIndex) {
150
+ sql += ` (${this.expressionIndex})`;
151
+ }
152
+ else if (this.columns.length > 0) {
153
+ const columnDefs = this.columns.map(col => this.formatColumn(col));
154
+ if ((this.indexType === 'GIN' || this.indexType === 'GIST') &&
155
+ this.operatorClass &&
156
+ this.columns.length > 1) {
157
+ sql += ` (${columnDefs.join(', ')}) ${this.operatorClass}`;
158
+ }
159
+ else {
160
+ sql += ` (${columnDefs.join(', ')})`;
161
+ }
162
+ }
163
+ if (this.includeColumns.length > 0) {
164
+ sql += ` INCLUDE (${this.includeColumns.map(c => format.ident(c)).join(', ')})`;
165
+ }
166
+ if (Object.keys(this.withOptions).length > 0) {
167
+ const options = Object.entries(this.withOptions)
168
+ .map(([key, value]) => `${key} = ${typeof value === 'boolean' ? (value ? 'on' : 'off') : value}`)
169
+ .join(', ');
170
+ sql += ` WITH (${options})`;
171
+ }
172
+ if (this.tablespaceValue) {
173
+ sql += ` TABLESPACE ${format.ident(this.tablespaceValue)}`;
174
+ }
175
+ if (this.whereClause) {
176
+ sql += ` WHERE ${this.whereClause}`;
177
+ }
178
+ return sql;
179
+ }
180
+ }