uql-orm 0.8.2 → 0.8.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.
@@ -1,9 +1,18 @@
1
1
  /**
2
- * Split a SQL blob on semicolons for execution as separate statements.
2
+ * Splits a SQL blob on semicolons into separate statements.
3
3
  *
4
- * **Heuristic only:** unsafe if a statement contains `;` inside a string literal. Migration builder
5
- * operations emit DDL without embedded semicolons in literals; `createTable` bypasses this and uses
6
- * `string[]` from the schema generator instead (#87).
4
+ * Uses a declarative Master-Regex scanner to rapidly
5
+ * identify and skip "non-splittable" blocks (strings, comments, dollar-quotes) in a single pass.
6
+ * This approach is $O(n)$, leverages native regex speed, and is trivially easy to audit.
7
+ *
8
+ * Handles:
9
+ * - Single quotes: '...' (standard SQL, respects '' and \')
10
+ * - Double quotes: "..." (identifiers or MySQL strings)
11
+ * - Backticks: `...` (MySQL identifiers)
12
+ * - Postgres Dollar quotes: $tag$...$tag$ or $$...$$
13
+ * - Comments: -- and /* ... *\/
7
14
  */
8
- export declare function splitSqlStatementsOnSemicolons(sql: string): string[];
15
+ export declare function splitSqlStatements(sql: string): string[];
16
+ /** Legacy alias kept for backward compatibility. */
17
+ export declare const splitSqlStatementsOnSemicolons: typeof splitSqlStatements;
9
18
  //# sourceMappingURL=splitSqlStatements.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"splitSqlStatements.d.ts","sourceRoot":"","sources":["../../../src/migrate/builder/splitSqlStatements.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAKpE"}
1
+ {"version":3,"file":"splitSqlStatements.d.ts","sourceRoot":"","sources":["../../../src/migrate/builder/splitSqlStatements.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CA+BxD;AAED,oDAAoD;AACpD,eAAO,MAAM,8BAA8B,2BAAqB,CAAC"}
@@ -1,14 +1,44 @@
1
1
  /**
2
- * Split a SQL blob on semicolons for execution as separate statements.
2
+ * Splits a SQL blob on semicolons into separate statements.
3
3
  *
4
- * **Heuristic only:** unsafe if a statement contains `;` inside a string literal. Migration builder
5
- * operations emit DDL without embedded semicolons in literals; `createTable` bypasses this and uses
6
- * `string[]` from the schema generator instead (#87).
4
+ * Uses a declarative Master-Regex scanner to rapidly
5
+ * identify and skip "non-splittable" blocks (strings, comments, dollar-quotes) in a single pass.
6
+ * This approach is $O(n)$, leverages native regex speed, and is trivially easy to audit.
7
+ *
8
+ * Handles:
9
+ * - Single quotes: '...' (standard SQL, respects '' and \')
10
+ * - Double quotes: "..." (identifiers or MySQL strings)
11
+ * - Backticks: `...` (MySQL identifiers)
12
+ * - Postgres Dollar quotes: $tag$...$tag$ or $$...$$
13
+ * - Comments: -- and /* ... *\/
7
14
  */
8
- export function splitSqlStatementsOnSemicolons(sql) {
9
- return sql
10
- .split(';')
11
- .map((s) => s.trim())
12
- .filter((s) => s.length > 0);
15
+ export function splitSqlStatements(sql) {
16
+ const statements = [];
17
+ let lastIndex = 0;
18
+ // This regex matches:
19
+ // 1. Single quoted strings: '(?:''|\\['\\]|[^'])*(?:'|(?=$))
20
+ // 2. Double quoted identifiers: "(?:""|\\["\\]|[^"])*(?:"|(?=$))
21
+ // 3. Backticked identifiers: `(?:``|\\[`\\]|[^`])*(?:`|(?=$))
22
+ // 4. Postgres Dollar quoted blocks: \$(?<tag>[a-zA-Z0-9_]*)\$[\s\S]*?(?:\$\k<tag>|(?=$))
23
+ // 5. Single-line comments: --.*
24
+ // 6. Multi-line comments: \/\*[\s\S]*?(?:\*\/|(?=$))
25
+ // 7. Statement terminator: ;
26
+ const masterRegex = /'(?:''|\\['\\]|[^'])*(?:'|(?=$))|"(?:""|\\["\\]|[^"])*(?:"|(?=$))|`(?:``|\\[`\\]|[^`])*(?:`|(?=$))|\$(?<tag>[a-zA-Z0-9_]*)\$[\s\S]*?(?:\$\k<tag>|(?=$))|--.*|\/\*[\s\S]*?(?:\*\/|(?=$))|;/g;
27
+ for (const match of sql.matchAll(masterRegex)) {
28
+ if (match[0] === ';') {
29
+ const stmt = sql.substring(lastIndex, match.index ?? 0).trim();
30
+ if (stmt) {
31
+ statements.push(stmt);
32
+ }
33
+ lastIndex = (match.index ?? 0) + match[0].length;
34
+ }
35
+ }
36
+ const lastStmt = sql.substring(lastIndex).trim();
37
+ if (lastStmt) {
38
+ statements.push(lastStmt);
39
+ }
40
+ return statements;
13
41
  }
42
+ /** Legacy alias kept for backward compatibility. */
43
+ export const splitSqlStatementsOnSemicolons = splitSqlStatements;
14
44
  //# sourceMappingURL=splitSqlStatements.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"splitSqlStatements.js","sourceRoot":"","sources":["../../../src/migrate/builder/splitSqlStatements.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B,CAAC,GAAW;IACxD,OAAO,GAAG;SACP,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACjC,CAAC"}
1
+ {"version":3,"file":"splitSqlStatements.js","sourceRoot":"","sources":["../../../src/migrate/builder/splitSqlStatements.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,sBAAsB;IACtB,6DAA6D;IAC7D,iEAAiE;IACjE,8DAA8D;IAC9D,yFAAyF;IACzF,gCAAgC;IAChC,qDAAqD;IACrD,6BAA6B;IAC7B,MAAM,WAAW,GACf,4LAA4L,CAAC;IAE/L,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9C,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACrB,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC/D,IAAI,IAAI,EAAE,CAAC;gBACT,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;YACD,SAAS,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACnD,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;IACjD,IAAI,QAAQ,EAAE,CAAC;QACb,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,oDAAoD;AACpD,MAAM,CAAC,MAAM,8BAA8B,GAAG,kBAAkB,CAAC"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "homepage": "https://uql-orm.dev",
4
4
  "description": "Fast, type-safe TypeScript ORM — one API for every database",
5
5
  "license": "MIT",
6
- "version": "0.8.2",
6
+ "version": "0.8.3",
7
7
  "type": "module",
8
8
  "sideEffects": false,
9
9
  "main": "./dist/index.js",
@@ -156,5 +156,5 @@
156
156
  "publishConfig": {
157
157
  "access": "public"
158
158
  },
159
- "gitHead": "b7ba21c5ea6bc2e0a2a2a7beb124df712a773187"
159
+ "gitHead": "697c9271ac86f021b57816d22de39e1e76f7cee3"
160
160
  }