latticesql 1.6.5 → 1.6.6
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.
- package/dist/cli.js +14 -8
- package/dist/index.cjs +14 -8
- package/dist/index.js +14 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -556,22 +556,28 @@ function translateDialect(sql) {
|
|
|
556
556
|
"PostgresAdapter: 'INSERT OR REPLACE INTO ...' is not auto-translated. Use INSERT INTO ... ON CONFLICT (col) DO UPDATE SET ... in your migration."
|
|
557
557
|
);
|
|
558
558
|
}
|
|
559
|
+
let hadInsertOrIgnore = false;
|
|
559
560
|
let s = mapCodeRegions(sql, (code) => {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
mutated = mutated.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1, _w2) => {
|
|
563
|
-
needsOnConflict = true;
|
|
561
|
+
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1, _w2) => {
|
|
562
|
+
hadInsertOrIgnore = true;
|
|
564
563
|
return `INSERT${w1}INTO`;
|
|
565
564
|
});
|
|
566
|
-
if (needsOnConflict && !/ON\s+CONFLICT/i.test(mutated)) {
|
|
567
|
-
mutated = mutated.replace(/(\s*;?\s*)$/, " ON CONFLICT DO NOTHING$1");
|
|
568
|
-
}
|
|
569
|
-
return mutated;
|
|
570
565
|
});
|
|
566
|
+
if (hadInsertOrIgnore && !hasOnConflictInCode(s)) {
|
|
567
|
+
s = s.replace(/(\s*;?\s*)$/, " ON CONFLICT DO NOTHING$1");
|
|
568
|
+
}
|
|
571
569
|
s = replaceFunction(s, "hex", (arg) => `encode(${arg}, 'hex')`);
|
|
572
570
|
s = replaceFunction(s, "randomblob", (arg) => `gen_random_bytes(${arg})`);
|
|
573
571
|
return s;
|
|
574
572
|
}
|
|
573
|
+
function hasOnConflictInCode(sql) {
|
|
574
|
+
let found = false;
|
|
575
|
+
mapCodeRegions(sql, (code) => {
|
|
576
|
+
if (/ON\s+CONFLICT/i.test(code)) found = true;
|
|
577
|
+
return code;
|
|
578
|
+
});
|
|
579
|
+
return found;
|
|
580
|
+
}
|
|
575
581
|
function mapCodeRegions(sql, xform) {
|
|
576
582
|
let out = "";
|
|
577
583
|
let codeStart = 0;
|
package/dist/index.cjs
CHANGED
|
@@ -306,22 +306,28 @@ function translateDialect(sql) {
|
|
|
306
306
|
"PostgresAdapter: 'INSERT OR REPLACE INTO ...' is not auto-translated. Use INSERT INTO ... ON CONFLICT (col) DO UPDATE SET ... in your migration."
|
|
307
307
|
);
|
|
308
308
|
}
|
|
309
|
+
let hadInsertOrIgnore = false;
|
|
309
310
|
let s = mapCodeRegions(sql, (code) => {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
mutated = mutated.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1, _w2) => {
|
|
313
|
-
needsOnConflict = true;
|
|
311
|
+
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1, _w2) => {
|
|
312
|
+
hadInsertOrIgnore = true;
|
|
314
313
|
return `INSERT${w1}INTO`;
|
|
315
314
|
});
|
|
316
|
-
if (needsOnConflict && !/ON\s+CONFLICT/i.test(mutated)) {
|
|
317
|
-
mutated = mutated.replace(/(\s*;?\s*)$/, " ON CONFLICT DO NOTHING$1");
|
|
318
|
-
}
|
|
319
|
-
return mutated;
|
|
320
315
|
});
|
|
316
|
+
if (hadInsertOrIgnore && !hasOnConflictInCode(s)) {
|
|
317
|
+
s = s.replace(/(\s*;?\s*)$/, " ON CONFLICT DO NOTHING$1");
|
|
318
|
+
}
|
|
321
319
|
s = replaceFunction(s, "hex", (arg) => `encode(${arg}, 'hex')`);
|
|
322
320
|
s = replaceFunction(s, "randomblob", (arg) => `gen_random_bytes(${arg})`);
|
|
323
321
|
return s;
|
|
324
322
|
}
|
|
323
|
+
function hasOnConflictInCode(sql) {
|
|
324
|
+
let found = false;
|
|
325
|
+
mapCodeRegions(sql, (code) => {
|
|
326
|
+
if (/ON\s+CONFLICT/i.test(code)) found = true;
|
|
327
|
+
return code;
|
|
328
|
+
});
|
|
329
|
+
return found;
|
|
330
|
+
}
|
|
325
331
|
function mapCodeRegions(sql, xform) {
|
|
326
332
|
let out = "";
|
|
327
333
|
let codeStart = 0;
|
package/dist/index.js
CHANGED
|
@@ -241,22 +241,28 @@ function translateDialect(sql) {
|
|
|
241
241
|
"PostgresAdapter: 'INSERT OR REPLACE INTO ...' is not auto-translated. Use INSERT INTO ... ON CONFLICT (col) DO UPDATE SET ... in your migration."
|
|
242
242
|
);
|
|
243
243
|
}
|
|
244
|
+
let hadInsertOrIgnore = false;
|
|
244
245
|
let s = mapCodeRegions(sql, (code) => {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
mutated = mutated.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1, _w2) => {
|
|
248
|
-
needsOnConflict = true;
|
|
246
|
+
return code.replace(/INSERT(\s+)OR\s+IGNORE(\s+)INTO/gi, (_m, w1, _w2) => {
|
|
247
|
+
hadInsertOrIgnore = true;
|
|
249
248
|
return `INSERT${w1}INTO`;
|
|
250
249
|
});
|
|
251
|
-
if (needsOnConflict && !/ON\s+CONFLICT/i.test(mutated)) {
|
|
252
|
-
mutated = mutated.replace(/(\s*;?\s*)$/, " ON CONFLICT DO NOTHING$1");
|
|
253
|
-
}
|
|
254
|
-
return mutated;
|
|
255
250
|
});
|
|
251
|
+
if (hadInsertOrIgnore && !hasOnConflictInCode(s)) {
|
|
252
|
+
s = s.replace(/(\s*;?\s*)$/, " ON CONFLICT DO NOTHING$1");
|
|
253
|
+
}
|
|
256
254
|
s = replaceFunction(s, "hex", (arg) => `encode(${arg}, 'hex')`);
|
|
257
255
|
s = replaceFunction(s, "randomblob", (arg) => `gen_random_bytes(${arg})`);
|
|
258
256
|
return s;
|
|
259
257
|
}
|
|
258
|
+
function hasOnConflictInCode(sql) {
|
|
259
|
+
let found = false;
|
|
260
|
+
mapCodeRegions(sql, (code) => {
|
|
261
|
+
if (/ON\s+CONFLICT/i.test(code)) found = true;
|
|
262
|
+
return code;
|
|
263
|
+
});
|
|
264
|
+
return found;
|
|
265
|
+
}
|
|
260
266
|
function mapCodeRegions(sql, xform) {
|
|
261
267
|
let out = "";
|
|
262
268
|
let codeStart = 0;
|
package/package.json
CHANGED