relq 1.0.1 → 1.0.3

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 (194) hide show
  1. package/dist/cjs/addon/buffer/index.cjs +1881 -0
  2. package/dist/cjs/addon/pg/index.cjs +4812 -0
  3. package/dist/cjs/addon/pg-cursor/index.cjs +1451 -0
  4. package/dist/cjs/addon/pg-format/index.cjs +2270 -0
  5. package/dist/cjs/cli/commands/add.cjs +430 -25
  6. package/dist/cjs/cli/commands/branch.cjs +131 -0
  7. package/dist/cjs/cli/commands/checkout.cjs +121 -0
  8. package/dist/cjs/cli/commands/cherry-pick.cjs +282 -0
  9. package/dist/cjs/cli/commands/commit.cjs +21 -29
  10. package/dist/cjs/cli/commands/diff.cjs +144 -69
  11. package/dist/cjs/cli/commands/export.cjs +70 -11
  12. package/dist/cjs/cli/commands/fetch.cjs +42 -18
  13. package/dist/cjs/cli/commands/generate.cjs +28 -54
  14. package/dist/cjs/cli/commands/history.cjs +19 -40
  15. package/dist/cjs/cli/commands/import.cjs +305 -41
  16. package/dist/cjs/cli/commands/init.cjs +69 -59
  17. package/dist/cjs/cli/commands/introspect.cjs +4 -8
  18. package/dist/cjs/cli/commands/log.cjs +84 -15
  19. package/dist/cjs/cli/commands/merge.cjs +207 -0
  20. package/dist/cjs/cli/commands/migrate.cjs +13 -26
  21. package/dist/cjs/cli/commands/pull.cjs +321 -95
  22. package/dist/cjs/cli/commands/push.cjs +228 -52
  23. package/dist/cjs/cli/commands/remote.cjs +17 -0
  24. package/dist/cjs/cli/commands/reset.cjs +148 -0
  25. package/dist/cjs/cli/commands/resolve.cjs +191 -0
  26. package/dist/cjs/cli/commands/rollback.cjs +17 -39
  27. package/dist/cjs/cli/commands/stash.cjs +152 -0
  28. package/dist/cjs/cli/commands/status.cjs +52 -9
  29. package/dist/cjs/cli/commands/sync.cjs +30 -50
  30. package/dist/cjs/cli/commands/tag.cjs +146 -0
  31. package/dist/cjs/cli/index.cjs +117 -10
  32. package/dist/cjs/cli/utils/change-tracker.cjs +107 -3
  33. package/dist/cjs/cli/utils/cli-utils.cjs +217 -0
  34. package/dist/cjs/cli/utils/commit-manager.cjs +3 -3
  35. package/dist/cjs/cli/utils/config-loader.cjs +34 -8
  36. package/dist/cjs/cli/utils/env-loader.cjs +3 -2
  37. package/dist/cjs/cli/utils/fast-introspect.cjs +110 -4
  38. package/dist/cjs/cli/utils/git-utils.cjs +42 -161
  39. package/dist/cjs/cli/utils/pool-manager.cjs +156 -0
  40. package/dist/cjs/cli/utils/project-root.cjs +107 -0
  41. package/dist/cjs/cli/utils/relqignore.cjs +297 -38
  42. package/dist/cjs/cli/utils/repo-manager.cjs +92 -3
  43. package/dist/cjs/cli/utils/schema-comparator.cjs +301 -11
  44. package/dist/cjs/cli/utils/schema-diff.cjs +202 -1
  45. package/dist/cjs/cli/utils/schema-hash.cjs +2 -1
  46. package/dist/cjs/cli/utils/schema-introspect.cjs +9 -5
  47. package/dist/cjs/cli/utils/snapshot-manager.cjs +1 -0
  48. package/dist/cjs/cli/utils/spinner.cjs +14 -106
  49. package/dist/cjs/cli/utils/sql-generator.cjs +2 -2
  50. package/dist/cjs/cli/utils/sql-parser.cjs +94 -7
  51. package/dist/cjs/cli/utils/type-generator.cjs +28 -16
  52. package/dist/cjs/condition/array-condition-builder.cjs +1 -1
  53. package/dist/cjs/condition/condition-collector.cjs +1 -1
  54. package/dist/cjs/condition/fulltext-condition-builder.cjs +1 -1
  55. package/dist/cjs/condition/geometric-condition-builder.cjs +1 -1
  56. package/dist/cjs/condition/jsonb-condition-builder.cjs +1 -1
  57. package/dist/cjs/condition/network-condition-builder.cjs +1 -1
  58. package/dist/cjs/condition/range-condition-builder.cjs +1 -1
  59. package/dist/cjs/copy/copy-builder.cjs +1 -1
  60. package/dist/cjs/core/query-builder.cjs +1 -1
  61. package/dist/cjs/core/relq-client.cjs +2 -2
  62. package/dist/cjs/count/count-builder.cjs +1 -1
  63. package/dist/cjs/cte/cte-builder.cjs +1 -1
  64. package/dist/cjs/delete/delete-builder.cjs +1 -1
  65. package/dist/cjs/function/create-function-builder.cjs +1 -1
  66. package/dist/cjs/functions/advanced-functions.cjs +1 -1
  67. package/dist/cjs/functions/case-builder.cjs +1 -1
  68. package/dist/cjs/functions/geometric-functions.cjs +1 -1
  69. package/dist/cjs/functions/network-functions.cjs +1 -1
  70. package/dist/cjs/functions/sql-functions.cjs +1 -1
  71. package/dist/cjs/indexing/create-index-builder.cjs +1 -1
  72. package/dist/cjs/indexing/drop-index-builder.cjs +1 -1
  73. package/dist/cjs/insert/conflict-builder.cjs +1 -1
  74. package/dist/cjs/insert/insert-builder.cjs +1 -1
  75. package/dist/cjs/maintenance/vacuum-builder.cjs +1 -1
  76. package/dist/cjs/pubsub/listen-notify-builder.cjs +1 -1
  77. package/dist/cjs/pubsub/listener-connection.cjs +2 -2
  78. package/dist/cjs/raw/raw-query-builder.cjs +1 -1
  79. package/dist/cjs/schema/schema-builder.cjs +1 -1
  80. package/dist/cjs/schema-definition/table-definition.cjs +1 -1
  81. package/dist/cjs/select/aggregate-builder.cjs +1 -1
  82. package/dist/cjs/select/select-builder.cjs +1 -1
  83. package/dist/cjs/sequence/sequence-builder.cjs +1 -1
  84. package/dist/cjs/table/alter-table-builder.cjs +1 -1
  85. package/dist/cjs/table/constraint-builder.cjs +1 -1
  86. package/dist/cjs/table/create-table-builder.cjs +1 -1
  87. package/dist/cjs/table/partition-builder.cjs +1 -1
  88. package/dist/cjs/table/truncate-builder.cjs +1 -1
  89. package/dist/cjs/transaction/transaction-builder.cjs +1 -1
  90. package/dist/cjs/trigger/create-trigger-builder.cjs +1 -1
  91. package/dist/cjs/update/array-update-builder.cjs +1 -1
  92. package/dist/cjs/update/update-builder.cjs +1 -1
  93. package/dist/cjs/utils/index.cjs +1 -1
  94. package/dist/cjs/view/create-view-builder.cjs +1 -1
  95. package/dist/cjs/window/window-builder.cjs +1 -1
  96. package/dist/config.d.ts +16 -25
  97. package/dist/esm/cli/commands/add.js +399 -27
  98. package/dist/esm/cli/commands/branch.js +95 -0
  99. package/dist/esm/cli/commands/checkout.js +85 -0
  100. package/dist/esm/cli/commands/cherry-pick.js +246 -0
  101. package/dist/esm/cli/commands/commit.js +22 -30
  102. package/dist/esm/cli/commands/diff.js +144 -69
  103. package/dist/esm/cli/commands/export.js +71 -12
  104. package/dist/esm/cli/commands/fetch.js +42 -18
  105. package/dist/esm/cli/commands/generate.js +28 -54
  106. package/dist/esm/cli/commands/history.js +11 -32
  107. package/dist/esm/cli/commands/import.js +306 -42
  108. package/dist/esm/cli/commands/init.js +65 -55
  109. package/dist/esm/cli/commands/introspect.js +4 -8
  110. package/dist/esm/cli/commands/log.js +78 -10
  111. package/dist/esm/cli/commands/merge.js +171 -0
  112. package/dist/esm/cli/commands/migrate.js +13 -26
  113. package/dist/esm/cli/commands/pull.js +313 -87
  114. package/dist/esm/cli/commands/push.js +223 -47
  115. package/dist/esm/cli/commands/remote.js +14 -0
  116. package/dist/esm/cli/commands/reset.js +112 -0
  117. package/dist/esm/cli/commands/resolve.js +155 -0
  118. package/dist/esm/cli/commands/rollback.js +17 -39
  119. package/dist/esm/cli/commands/stash.js +116 -0
  120. package/dist/esm/cli/commands/status.js +20 -10
  121. package/dist/esm/cli/commands/sync.js +30 -50
  122. package/dist/esm/cli/commands/tag.js +110 -0
  123. package/dist/esm/cli/index.js +118 -11
  124. package/dist/esm/cli/utils/change-tracker.js +107 -3
  125. package/dist/esm/cli/utils/cli-utils.js +169 -0
  126. package/dist/esm/cli/utils/commit-manager.js +3 -3
  127. package/dist/esm/cli/utils/config-loader.js +34 -8
  128. package/dist/esm/cli/utils/env-loader.js +3 -2
  129. package/dist/esm/cli/utils/fast-introspect.js +110 -4
  130. package/dist/esm/cli/utils/git-utils.js +2 -124
  131. package/dist/esm/cli/utils/pool-manager.js +114 -0
  132. package/dist/esm/cli/utils/project-root.js +69 -0
  133. package/dist/esm/cli/utils/relqignore.js +278 -37
  134. package/dist/esm/cli/utils/repo-manager.js +83 -3
  135. package/dist/esm/cli/utils/schema-comparator.js +301 -11
  136. package/dist/esm/cli/utils/schema-diff.js +202 -1
  137. package/dist/esm/cli/utils/schema-hash.js +2 -1
  138. package/dist/esm/cli/utils/schema-introspect.js +9 -5
  139. package/dist/esm/cli/utils/snapshot-manager.js +1 -0
  140. package/dist/esm/cli/utils/spinner.js +1 -101
  141. package/dist/esm/cli/utils/sql-generator.js +2 -2
  142. package/dist/esm/cli/utils/sql-parser.js +94 -7
  143. package/dist/esm/cli/utils/type-generator.js +28 -16
  144. package/dist/esm/condition/array-condition-builder.js +1 -1
  145. package/dist/esm/condition/condition-collector.js +1 -1
  146. package/dist/esm/condition/fulltext-condition-builder.js +1 -1
  147. package/dist/esm/condition/geometric-condition-builder.js +1 -1
  148. package/dist/esm/condition/jsonb-condition-builder.js +1 -1
  149. package/dist/esm/condition/network-condition-builder.js +1 -1
  150. package/dist/esm/condition/range-condition-builder.js +1 -1
  151. package/dist/esm/copy/copy-builder.js +1 -1
  152. package/dist/esm/core/query-builder.js +1 -1
  153. package/dist/esm/core/relq-client.js +2 -2
  154. package/dist/esm/count/count-builder.js +1 -1
  155. package/dist/esm/cte/cte-builder.js +1 -1
  156. package/dist/esm/delete/delete-builder.js +1 -1
  157. package/dist/esm/function/create-function-builder.js +1 -1
  158. package/dist/esm/functions/advanced-functions.js +1 -1
  159. package/dist/esm/functions/case-builder.js +1 -1
  160. package/dist/esm/functions/geometric-functions.js +1 -1
  161. package/dist/esm/functions/network-functions.js +1 -1
  162. package/dist/esm/functions/sql-functions.js +1 -1
  163. package/dist/esm/indexing/create-index-builder.js +1 -1
  164. package/dist/esm/indexing/drop-index-builder.js +1 -1
  165. package/dist/esm/insert/conflict-builder.js +1 -1
  166. package/dist/esm/insert/insert-builder.js +1 -1
  167. package/dist/esm/maintenance/vacuum-builder.js +1 -1
  168. package/dist/esm/pubsub/listen-notify-builder.js +1 -1
  169. package/dist/esm/pubsub/listener-connection.js +2 -2
  170. package/dist/esm/raw/raw-query-builder.js +1 -1
  171. package/dist/esm/schema/schema-builder.js +1 -1
  172. package/dist/esm/schema-definition/table-definition.js +1 -1
  173. package/dist/esm/select/aggregate-builder.js +1 -1
  174. package/dist/esm/select/select-builder.js +1 -1
  175. package/dist/esm/sequence/sequence-builder.js +1 -1
  176. package/dist/esm/table/alter-table-builder.js +1 -1
  177. package/dist/esm/table/constraint-builder.js +1 -1
  178. package/dist/esm/table/create-table-builder.js +1 -1
  179. package/dist/esm/table/partition-builder.js +1 -1
  180. package/dist/esm/table/truncate-builder.js +1 -1
  181. package/dist/esm/transaction/transaction-builder.js +1 -1
  182. package/dist/esm/trigger/create-trigger-builder.js +1 -1
  183. package/dist/esm/update/array-update-builder.js +1 -1
  184. package/dist/esm/update/update-builder.js +1 -1
  185. package/dist/esm/utils/index.js +1 -1
  186. package/dist/esm/view/create-view-builder.js +1 -1
  187. package/dist/esm/window/window-builder.js +1 -1
  188. package/dist/index.d.ts +25 -8
  189. package/dist/schema-builder.d.ts +16 -6
  190. package/package.json +1 -1
  191. /package/dist/{addons/buffer.js → esm/addon/buffer/index.js} +0 -0
  192. /package/dist/{addons/pg.js → esm/addon/pg/index.js} +0 -0
  193. /package/dist/{addons/pg-cursor.js → esm/addon/pg-cursor/index.js} +0 -0
  194. /package/dist/{addons/pg-format.js → esm/addon/pg-format/index.js} +0 -0
@@ -1,101 +1 @@
1
- const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
2
- const SPINNER_INTERVAL = 80;
3
- export function createSpinner() {
4
- let intervalId = null;
5
- let frameIndex = 0;
6
- let currentMessage = '';
7
- let isSpinning = false;
8
- const clearLine = () => {
9
- process.stdout.write('\r\x1b[K');
10
- };
11
- const render = () => {
12
- if (!isSpinning)
13
- return;
14
- clearLine();
15
- const frame = SPINNER_FRAMES[frameIndex];
16
- process.stdout.write(`\x1b[36m${frame}\x1b[0m ${currentMessage}`);
17
- frameIndex = (frameIndex + 1) % SPINNER_FRAMES.length;
18
- };
19
- return {
20
- start(message) {
21
- if (isSpinning)
22
- this.stop();
23
- currentMessage = message;
24
- isSpinning = true;
25
- frameIndex = 0;
26
- intervalId = setInterval(render, SPINNER_INTERVAL);
27
- render();
28
- },
29
- update(message) {
30
- currentMessage = message;
31
- },
32
- succeed(message) {
33
- this.stop();
34
- console.log(`\x1b[32m✓\x1b[0m ${message || currentMessage}`);
35
- },
36
- fail(message) {
37
- this.stop();
38
- console.log(`\x1b[31m✗\x1b[0m ${message || currentMessage}`);
39
- },
40
- info(message) {
41
- this.stop();
42
- console.log(`\x1b[34mℹ\x1b[0m ${message || currentMessage}`);
43
- },
44
- warn(message) {
45
- this.stop();
46
- console.log(`\x1b[33m⚠\x1b[0m ${message || currentMessage}`);
47
- },
48
- stop() {
49
- if (intervalId) {
50
- clearInterval(intervalId);
51
- intervalId = null;
52
- }
53
- if (isSpinning) {
54
- clearLine();
55
- isSpinning = false;
56
- }
57
- }
58
- };
59
- }
60
- export const colors = {
61
- reset: '\x1b[0m',
62
- bold: (text) => `\x1b[1m${text}\x1b[0m`,
63
- dim: (text) => `\x1b[2m${text}\x1b[0m`,
64
- red: (text) => `\x1b[31m${text}\x1b[0m`,
65
- green: (text) => `\x1b[32m${text}\x1b[0m`,
66
- yellow: (text) => `\x1b[33m${text}\x1b[0m`,
67
- blue: (text) => `\x1b[34m${text}\x1b[0m`,
68
- magenta: (text) => `\x1b[35m${text}\x1b[0m`,
69
- cyan: (text) => `\x1b[36m${text}\x1b[0m`,
70
- gray: (text) => `\x1b[90m${text}\x1b[0m`,
71
- white: (text) => `\x1b[37m${text}\x1b[0m`,
72
- success: (text) => `\x1b[32m${text}\x1b[0m`,
73
- error: (text) => `\x1b[31m${text}\x1b[0m`,
74
- warning: (text) => `\x1b[33m${text}\x1b[0m`,
75
- info: (text) => `\x1b[34m${text}\x1b[0m`,
76
- muted: (text) => `\x1b[90m${text}\x1b[0m`,
77
- };
78
- export function progressBar(current, total, width = 30) {
79
- const percentage = Math.min(100, Math.round((current / total) * 100));
80
- const filled = Math.round((percentage / 100) * width);
81
- const empty = width - filled;
82
- const bar = '█'.repeat(filled) + '░'.repeat(empty);
83
- return `\x1b[36m${bar}\x1b[0m ${percentage}%`;
84
- }
85
- export function formatBytes(bytes) {
86
- if (bytes === 0)
87
- return '0 B';
88
- const k = 1024;
89
- const sizes = ['B', 'KB', 'MB', 'GB'];
90
- const i = Math.floor(Math.log(bytes) / Math.log(k));
91
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
92
- }
93
- export function formatDuration(ms) {
94
- if (ms < 1000)
95
- return `${ms}ms`;
96
- if (ms < 60000)
97
- return `${(ms / 1000).toFixed(1)}s`;
98
- const minutes = Math.floor(ms / 60000);
99
- const seconds = Math.round((ms % 60000) / 1000);
100
- return `${minutes}m ${seconds}s`;
101
- }
1
+ export { colors, createSpinner, progressBar, formatBytes, formatDuration, fatal, error, warning, hint, requireInit, confirm, success, } from "./cli-utils.js";
@@ -206,7 +206,7 @@ function generateColumnSQL(col) {
206
206
  if (col.identityGeneration) {
207
207
  parts.push(`GENERATED ${col.identityGeneration} AS IDENTITY`);
208
208
  }
209
- if (!col.isNullable && !col.isPrimaryKey) {
209
+ if (!col.isNullable && !col.isPrimaryKey && !col.identityGeneration) {
210
210
  parts.push('NOT NULL');
211
211
  }
212
212
  if (col.defaultValue !== null && col.defaultValue !== undefined && !col.isGenerated) {
@@ -324,7 +324,7 @@ export function generateIndexSQL(index, tableName) {
324
324
  if (index.expression) {
325
325
  parts.push(`(${index.expression})`);
326
326
  }
327
- else if (index.columns && index.columns.length > 0) {
327
+ else if (index.columns && Array.isArray(index.columns) && index.columns.length > 0) {
328
328
  const cols = index.columns.map(c => quoteColumnRef(c)).join(', ');
329
329
  parts.push(`(${cols})`);
330
330
  }
@@ -6,6 +6,9 @@ export function parseSqlFile(sqlContent) {
6
6
  const sequences = [];
7
7
  const collations = [];
8
8
  const foreignTables = [];
9
+ const views = [];
10
+ const materializedViews = [];
11
+ const foreignServers = [];
9
12
  const extensions = [];
10
13
  const partitions = [];
11
14
  const cleanedSql = removeComments(sqlContent);
@@ -18,7 +21,14 @@ export function parseSqlFile(sqlContent) {
18
21
  parseTables(cleanedSql, tables, partitions, enums, domains);
19
22
  parseIndexes(cleanedSql, tables);
20
23
  parseForeignTables(cleanedSql, foreignTables);
21
- return { tables, enums, domains, compositeTypes, sequences, collations, foreignTables, extensions, partitions };
24
+ parseViews(cleanedSql, views);
25
+ parseMaterializedViews(cleanedSql, materializedViews);
26
+ parseForeignServers(cleanedSql, foreignServers);
27
+ return {
28
+ tables, enums, domains, compositeTypes, sequences, collations,
29
+ foreignTables, views, materializedViews, foreignServers,
30
+ extensions, partitions
31
+ };
22
32
  }
23
33
  function removeComments(sql) {
24
34
  let result = sql.replace(/\/\*[\s\S]*?\*\//g, '');
@@ -110,11 +120,11 @@ function parseCompositeTypeBody(body) {
110
120
  const trimmed = line.trim();
111
121
  if (!trimmed)
112
122
  continue;
113
- const attrMatch = trimmed.match(/^(\w+)\s+(.+)$/);
123
+ const attrMatch = trimmed.match(/^(?:"([^"]+)"|(\w+))\s+(.+)$/);
114
124
  if (attrMatch) {
115
125
  attributes.push({
116
- name: attrMatch[1],
117
- type: attrMatch[2].trim().replace(/,\s*$/, ''),
126
+ name: attrMatch[1] || attrMatch[2],
127
+ type: attrMatch[3].trim().replace(/,\s*$/, ''),
118
128
  });
119
129
  }
120
130
  }
@@ -613,9 +623,9 @@ function extractMaxLength(type) {
613
623
  }
614
624
  function parseConstraint(def) {
615
625
  const upper = def.toUpperCase();
616
- const namedMatch = def.match(/CONSTRAINT\s+(\w+)\s+(.+)/i);
617
- const constraintDef = namedMatch ? namedMatch[2] : def;
618
- const constraintName = namedMatch ? namedMatch[1] : '';
626
+ const namedMatch = def.match(/CONSTRAINT\s+(?:"([^"]+)"|(\w+))\s+(.+)/is);
627
+ const constraintDef = namedMatch ? namedMatch[3] : def;
628
+ const constraintName = namedMatch ? (namedMatch[1] || namedMatch[2]) : '';
619
629
  const constraintUpper = constraintDef.toUpperCase();
620
630
  if (constraintUpper.startsWith('PRIMARY KEY')) {
621
631
  const colsMatch = constraintDef.match(/PRIMARY\s+KEY\s*\(\s*([^)]+)\s*\)/i);
@@ -991,4 +1001,81 @@ export function parseComments(sql) {
991
1001
  }
992
1002
  return comments;
993
1003
  }
1004
+ function parseViews(sql, views) {
1005
+ const viewRegex = /CREATE\s+(?:OR\s+REPLACE\s+)?VIEW\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:(?:"?(\w+)"?\.)?"?(\w+)"?)\s*(?:\(([^)]+)\))?\s+AS\s+([\s\S]+?)(?:;|\s+WITH\s+(?:CASCADED|LOCAL)\s+CHECK\s+OPTION\s*;)/gi;
1006
+ let match;
1007
+ while ((match = viewRegex.exec(sql)) !== null) {
1008
+ const schema = match[1] || 'public';
1009
+ const name = match[2];
1010
+ const columnsStr = match[3];
1011
+ const definition = match[4].trim();
1012
+ const columns = columnsStr
1013
+ ? columnsStr.split(',').map(c => c.trim().replace(/"/g, ''))
1014
+ : undefined;
1015
+ views.push({
1016
+ name,
1017
+ schema,
1018
+ definition,
1019
+ columns,
1020
+ });
1021
+ }
1022
+ const simpleViewRegex = /CREATE\s+(?:OR\s+REPLACE\s+)?VIEW\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:(?:"?(\w+)"?\.)?"?(\w+)"?)\s*AS\s+(SELECT[\s\S]+?);/gi;
1023
+ while ((match = simpleViewRegex.exec(sql)) !== null) {
1024
+ const schema = match[1] || 'public';
1025
+ const name = match[2];
1026
+ const definition = match[3].trim();
1027
+ if (views.some(v => v.name === name))
1028
+ continue;
1029
+ views.push({
1030
+ name,
1031
+ schema,
1032
+ definition,
1033
+ });
1034
+ }
1035
+ }
1036
+ function parseMaterializedViews(sql, materializedViews) {
1037
+ const mviewRegex = /CREATE\s+MATERIALIZED\s+VIEW\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:(?:"?(\w+)"?\.)?"?(\w+)"?)\s*(?:\(([^)]+)\))?\s+AS\s+([\s\S]+?)(?:WITH\s+(NO\s+)?DATA\s*)?;/gi;
1038
+ let match;
1039
+ while ((match = mviewRegex.exec(sql)) !== null) {
1040
+ const schema = match[1] || 'public';
1041
+ const name = match[2];
1042
+ const columnsStr = match[3];
1043
+ const definition = match[4].trim();
1044
+ const withNoData = match[5] !== undefined;
1045
+ const columns = columnsStr
1046
+ ? columnsStr.split(',').map(c => c.trim().replace(/"/g, ''))
1047
+ : undefined;
1048
+ materializedViews.push({
1049
+ name,
1050
+ schema,
1051
+ definition,
1052
+ columns,
1053
+ withData: !withNoData,
1054
+ });
1055
+ }
1056
+ }
1057
+ function parseForeignServers(sql, foreignServers) {
1058
+ const serverRegex = /CREATE\s+SERVER\s+(?:IF\s+NOT\s+EXISTS\s+)?"?(\w+)"?\s+FOREIGN\s+DATA\s+WRAPPER\s+"?(\w+)"?\s*(?:OPTIONS\s*\(([^)]+)\))?;/gi;
1059
+ let match;
1060
+ while ((match = serverRegex.exec(sql)) !== null) {
1061
+ const name = match[1];
1062
+ const fdwName = match[2];
1063
+ const optionsStr = match[3];
1064
+ const options = {};
1065
+ if (optionsStr) {
1066
+ const optParts = optionsStr.split(',');
1067
+ for (const part of optParts) {
1068
+ const optMatch = part.trim().match(/(\w+)\s+'([^']+)'/);
1069
+ if (optMatch) {
1070
+ options[optMatch[1]] = optMatch[2];
1071
+ }
1072
+ }
1073
+ }
1074
+ foreignServers.push({
1075
+ name,
1076
+ fdwName,
1077
+ options: Object.keys(options).length > 0 ? options : undefined,
1078
+ });
1079
+ }
1080
+ }
994
1081
  export default parseSqlFile;
@@ -700,8 +700,18 @@ function formatDefaultValue(val, col, domainMap) {
700
700
  }
701
701
  if (cleaned === "'[]'" || cleaned === 'ARRAY[]')
702
702
  return 'emptyArray()';
703
+ const isJsonColumn = col.dataType.toLowerCase().includes('json');
704
+ if (isJsonColumn && cleaned.startsWith("'") && cleaned.endsWith("'")) {
705
+ const jsonStr = cleaned.slice(1, -1).replace(/''/g, "'");
706
+ try {
707
+ const parsed = JSON.parse(jsonStr);
708
+ return JSON.stringify(parsed);
709
+ }
710
+ catch {
711
+ }
712
+ }
703
713
  const pgArrayMatch = cleaned.match(/^'?\{([^}]*)\}'?$/);
704
- if (pgArrayMatch) {
714
+ if (pgArrayMatch && !isJsonColumn) {
705
715
  const contents = pgArrayMatch[1];
706
716
  if (contents === '') {
707
717
  return 'emptyArray()';
@@ -736,16 +746,6 @@ function formatDefaultValue(val, col, domainMap) {
736
746
  }
737
747
  return 'emptyArray()';
738
748
  }
739
- const isJsonColumn = col.dataType.toLowerCase().includes('json');
740
- if (isJsonColumn && cleaned.startsWith("'") && cleaned.endsWith("'")) {
741
- const jsonStr = cleaned.slice(1, -1).replace(/''/g, "'");
742
- try {
743
- const parsed = JSON.parse(jsonStr);
744
- return JSON.stringify(parsed);
745
- }
746
- catch {
747
- }
748
- }
749
749
  if (cleaned.startsWith("'") && cleaned.endsWith("'")) {
750
750
  const str = cleaned.slice(1, -1).replace(/'/g, "\\'");
751
751
  return `'${str}'`;
@@ -1429,6 +1429,17 @@ function parseCheckValue(value, camelCase) {
1429
1429
  if (/^-?\d+(\.\d+)?$/.test(value)) {
1430
1430
  return value;
1431
1431
  }
1432
+ const castMatch = value.match(/^\(?(.+?)\)?::[a-z_][a-z0-9_]*(\[\])?$/i);
1433
+ if (castMatch) {
1434
+ const innerValue = castMatch[1].trim();
1435
+ if (/^-?\d+(\.\d+)?$/.test(innerValue)) {
1436
+ return innerValue;
1437
+ }
1438
+ if (/^'.*'$/.test(innerValue)) {
1439
+ return innerValue;
1440
+ }
1441
+ return parseCheckValue(innerValue, camelCase);
1442
+ }
1432
1443
  if (/^TRUE$/i.test(value))
1433
1444
  return 'true';
1434
1445
  if (/^FALSE$/i.test(value))
@@ -1550,16 +1561,17 @@ function generateDefineTable(table, camelCase = true, childPartitions, enumNames
1550
1561
  if (enumMatch) {
1551
1562
  const colName = enumMatch[1];
1552
1563
  const valuesStr = enumMatch[2];
1553
- const values = valuesStr
1554
- .match(/'([^']+)'/g)
1555
- ?.map(v => v.replace(/'/g, '')) || [];
1564
+ const values = valuesStr.match(/'([^']+)'/g)?.map(v => v.replace(/'/g, '')) || [];
1556
1565
  if (values.length > 0) {
1557
- columnChecks.set(colName.toLowerCase(), values);
1566
+ columnChecks.set(colName, values);
1558
1567
  }
1559
1568
  }
1560
1569
  }
1561
1570
  const columns = table.columns
1562
- .map(col => generateColumnDef(col, seenColumns, camelCase, columnChecks.get(col.name.toLowerCase()), enumNames, domainNames, compositeNames, domainMap))
1571
+ .map(col => {
1572
+ const checkValues = columnChecks.get(col.name);
1573
+ return generateColumnDef(col, seenColumns, camelCase, checkValues, enumNames, domainNames, compositeNames, domainMap);
1574
+ })
1563
1575
  .filter(Boolean);
1564
1576
  const columnNames = Array.from(seenColumns);
1565
1577
  const indexesFn = table.indexes ? generateIndexes(table.indexes, columnNames, camelCase) : null;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { ArrayStringConditionBuilder } from "./array-string-condition-builder.js";
3
3
  import { ArrayNumericConditionBuilder } from "./array-numeric-condition-builder.js";
4
4
  import { ArrayUuidConditionBuilder, ArrayDateConditionBuilder, ArrayJsonbConditionBuilder } from "./array-specialized-condition-builder.js";
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { JsonbConditionCollector, buildJsonbConditionSQL } from "./jsonb-condition-builder.js";
3
3
  import { ArrayConditionCollector, buildArrayConditionSQL } from "./array-condition-builder.js";
4
4
  import { FulltextConditionCollector, buildFulltextConditionSQL } from "./fulltext-condition-builder.js";
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class FulltextConditionCollector {
3
3
  parent;
4
4
  constructor(parent) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class GeometricConditionCollector {
3
3
  parent;
4
4
  constructor(parent) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class JsonbConditionCollector {
3
3
  parent;
4
4
  constructor(parent) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class NetworkConditionCollector {
3
3
  parent;
4
4
  constructor(parent) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class RangeConditionCollector {
3
3
  parent;
4
4
  constructor(parent) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { RelqBuilderError } from "../errors/relq-errors.js";
3
3
  export class CopyToBuilder {
4
4
  tableName;
@@ -22,7 +22,7 @@ import { ExplainBuilder } from "../explain/explain-builder.js";
22
22
  import { ListenBuilder, UnlistenBuilder, NotifyBuilder } from "../pubsub/listen-notify-builder.js";
23
23
  import { VacuumBuilder, AnalyzeBuilder } from "../maintenance/vacuum-builder.js";
24
24
  import { CopyToBuilder, CopyFromBuilder } from "../copy/copy-builder.js";
25
- import format from "../../addons/pg-format.js";
25
+ import format from "../addon/pg-format/index.js";
26
26
  export class TypedSelectBuilder {
27
27
  builder;
28
28
  constructor(builder) {
@@ -14,7 +14,7 @@ import { validatePoolConfig, formatPoolConfig, getSmartPoolDefaults } from "../u
14
14
  import { RelqEnvironmentError, RelqConfigError, RelqQueryError, RelqConnectionError, parsePostgresError } from "../errors/relq-errors.js";
15
15
  import { randomLimit } from "../types/pagination-types.js";
16
16
  import { deserializeValue, serializeValue } from "../utils/type-coercion.js";
17
- import Cursor from "../../addons/pg-cursor.js";
17
+ import Cursor from "../addon/pg-cursor/index.js";
18
18
  const INTERNAL = Symbol('relq-internal');
19
19
  let PgPool = null;
20
20
  let PgClient = null;
@@ -40,7 +40,7 @@ function registerGlobalCleanupHandlers() {
40
40
  async function loadPg() {
41
41
  if (!PgPool || !PgClient) {
42
42
  try {
43
- const pg = await import("../addon/pg.js");
43
+ const pg = await import("../addon/pg/index.js");
44
44
  PgPool = pg.Pool;
45
45
  PgClient = pg.Client;
46
46
  return { Pool: pg.Pool, Client: pg.Client };
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { ConditionCollector, buildConditionsSQL, buildConditionSQL } from "../condition/condition-collector.js";
3
3
  export class CountBuilder {
4
4
  tableName;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { SelectBuilder } from "../select/select-builder.js";
3
3
  import { InsertBuilder } from "../insert/insert-builder.js";
4
4
  import { UpdateBuilder } from "../update/update-builder.js";
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { ConditionCollector, buildConditionsSQL } from "../condition/condition-collector.js";
3
3
  import { SelectBuilder } from "../select/select-builder.js";
4
4
  import { CountBuilder } from "../count/count-builder.js";
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { RelqBuilderError } from "../errors/relq-errors.js";
3
3
  export class CreateFunctionBuilder {
4
4
  functionName;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { SqlFunction } from "./sql-functions.js";
3
3
  export class ArrayFunctions {
4
4
  static array_length(array, dimension = 1) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class CaseBuilder {
3
3
  expression;
4
4
  whenClauses = [];
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { SqlFunction } from "./sql-functions.js";
3
3
  export class GeometricFunctions {
4
4
  static area(column) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { SqlFunction } from "./sql-functions.js";
3
3
  export class NetworkFunctions {
4
4
  static abbrev(column) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class SqlFunction {
3
3
  expression;
4
4
  constructor(expression) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class CreateIndexBuilder {
3
3
  tableName;
4
4
  indexName;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class DropIndexBuilder {
3
3
  indexName;
4
4
  ifExistsFlag = false;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  function isColumnRef(value) {
3
3
  return typeof value === 'object' && value !== null && value.__type === 'column_ref';
4
4
  }
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { convertCase } from "../utils/case-converter.js";
3
3
  import { SelectBuilder } from "../select/select-builder.js";
4
4
  import { CountBuilder } from "../count/count-builder.js";
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class VacuumBuilder {
3
3
  tables = [];
4
4
  columns = new Map();
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class ListenBuilder {
3
3
  channelName;
4
4
  constructor(channelName) {
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
- import { Client } from "../../addons/pg.js";
3
- import format from "../../addons/pg-format.js";
2
+ import { Client } from "../addon/pg/index.js";
3
+ import format from "../addon/pg-format/index.js";
4
4
  export class ListenerConnection extends EventEmitter {
5
5
  client = null;
6
6
  config;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { RelqQueryError } from "../errors/relq-errors.js";
3
3
  export class RawQueryBuilder {
4
4
  query;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { RelqBuilderError } from "../errors/relq-errors.js";
3
3
  export class CreateSchemaBuilder {
4
4
  schemaName;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { partitionStrategyFactory } from "./partitions.js";
3
3
  import { sqlFunctions, expressionBuilder } from "./sql-expressions.js";
4
4
  function formatWhereValue(val) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { ConditionCollector, buildConditionsSQL } from "../condition/condition-collector.js";
3
3
  const NUMERIC_FUNCS = new Set(['COUNT', 'SUM', 'AVG', 'MIN', 'MAX']);
4
4
  export class AggregateQueryBuilder {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { ConditionCollector, buildConditionsSQL } from "../condition/condition-collector.js";
3
3
  export class SelectBuilder {
4
4
  tableName;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class CreateSequenceBuilder {
3
3
  sequenceName;
4
4
  options = {};
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { RelqBuilderError } from "../errors/relq-errors.js";
3
3
  export class AlterTableBuilder {
4
4
  tableName;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class ConstraintBuilder {
3
3
  constraints = [];
4
4
  addPrimaryKey(columns, name) {
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { ConstraintBuilder } from "./constraint-builder.js";
3
3
  import { PartitionBuilder } from "./partition-builder.js";
4
4
  import { CreateIndexBuilder } from "../indexing/create-index-builder.js";
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class PartitionBuilder {
3
3
  strategy;
4
4
  columns = [];
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class TruncateBuilder {
3
3
  tables;
4
4
  cascadeFlag = false;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  export class TransactionBuilder {
3
3
  isolationLevel;
4
4
  mode;
@@ -1,4 +1,4 @@
1
- import format from "../../addons/pg-format.js";
1
+ import format from "../addon/pg-format/index.js";
2
2
  import { RelqBuilderError } from "../errors/relq-errors.js";
3
3
  export class CreateTriggerBuilder {
4
4
  triggerName;