latticesql 1.6.5 → 1.6.7
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 +20 -8
- package/dist/index.cjs +20 -8
- package/dist/index.js +20 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -556,22 +556,34 @@ 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
|
+
}
|
|
569
|
+
s = mapCodeRegions(
|
|
570
|
+
s,
|
|
571
|
+
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1, _w2) => {
|
|
572
|
+
return `CREATE${w1}OR REPLACE VIEW`;
|
|
573
|
+
})
|
|
574
|
+
);
|
|
571
575
|
s = replaceFunction(s, "hex", (arg) => `encode(${arg}, 'hex')`);
|
|
572
576
|
s = replaceFunction(s, "randomblob", (arg) => `gen_random_bytes(${arg})`);
|
|
573
577
|
return s;
|
|
574
578
|
}
|
|
579
|
+
function hasOnConflictInCode(sql) {
|
|
580
|
+
let found = false;
|
|
581
|
+
mapCodeRegions(sql, (code) => {
|
|
582
|
+
if (/ON\s+CONFLICT/i.test(code)) found = true;
|
|
583
|
+
return code;
|
|
584
|
+
});
|
|
585
|
+
return found;
|
|
586
|
+
}
|
|
575
587
|
function mapCodeRegions(sql, xform) {
|
|
576
588
|
let out = "";
|
|
577
589
|
let codeStart = 0;
|
package/dist/index.cjs
CHANGED
|
@@ -306,22 +306,34 @@ 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
|
+
}
|
|
319
|
+
s = mapCodeRegions(
|
|
320
|
+
s,
|
|
321
|
+
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1, _w2) => {
|
|
322
|
+
return `CREATE${w1}OR REPLACE VIEW`;
|
|
323
|
+
})
|
|
324
|
+
);
|
|
321
325
|
s = replaceFunction(s, "hex", (arg) => `encode(${arg}, 'hex')`);
|
|
322
326
|
s = replaceFunction(s, "randomblob", (arg) => `gen_random_bytes(${arg})`);
|
|
323
327
|
return s;
|
|
324
328
|
}
|
|
329
|
+
function hasOnConflictInCode(sql) {
|
|
330
|
+
let found = false;
|
|
331
|
+
mapCodeRegions(sql, (code) => {
|
|
332
|
+
if (/ON\s+CONFLICT/i.test(code)) found = true;
|
|
333
|
+
return code;
|
|
334
|
+
});
|
|
335
|
+
return found;
|
|
336
|
+
}
|
|
325
337
|
function mapCodeRegions(sql, xform) {
|
|
326
338
|
let out = "";
|
|
327
339
|
let codeStart = 0;
|
package/dist/index.js
CHANGED
|
@@ -241,22 +241,34 @@ 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
|
+
}
|
|
254
|
+
s = mapCodeRegions(
|
|
255
|
+
s,
|
|
256
|
+
(code) => code.replace(/CREATE(\s+)VIEW(\s+)IF\s+NOT\s+EXISTS/gi, (_m, w1, _w2) => {
|
|
257
|
+
return `CREATE${w1}OR REPLACE VIEW`;
|
|
258
|
+
})
|
|
259
|
+
);
|
|
256
260
|
s = replaceFunction(s, "hex", (arg) => `encode(${arg}, 'hex')`);
|
|
257
261
|
s = replaceFunction(s, "randomblob", (arg) => `gen_random_bytes(${arg})`);
|
|
258
262
|
return s;
|
|
259
263
|
}
|
|
264
|
+
function hasOnConflictInCode(sql) {
|
|
265
|
+
let found = false;
|
|
266
|
+
mapCodeRegions(sql, (code) => {
|
|
267
|
+
if (/ON\s+CONFLICT/i.test(code)) found = true;
|
|
268
|
+
return code;
|
|
269
|
+
});
|
|
270
|
+
return found;
|
|
271
|
+
}
|
|
260
272
|
function mapCodeRegions(sql, xform) {
|
|
261
273
|
let out = "";
|
|
262
274
|
let codeStart = 0;
|
package/package.json
CHANGED