mirror of
https://github.com/BetterCorp/BetterFrame.git
synced 2026-05-26 16:56:33 +00:00
fix(db): rewrite INSERT OR IGNORE to ON CONFLICT DO NOTHING for PG
SQLite INSERT OR IGNORE syntax not valid in PG. PG adapter now auto-rewrites to INSERT INTO ... ON CONFLICT DO NOTHING. Fixes attach layout, label assignments, and join table inserts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
649c64728a
commit
e3254ed46b
1 changed files with 9 additions and 0 deletions
|
|
@ -27,6 +27,15 @@ export class PgAdapter implements DbAdapter {
|
|||
}
|
||||
|
||||
private rewriteSql(sql: string): string {
|
||||
// SQLite → PG dialect fixups.
|
||||
if (/INSERT\s+OR\s+IGNORE/i.test(sql)) {
|
||||
sql = sql.replace(/INSERT\s+OR\s+IGNORE\s+INTO/gi, "INSERT INTO");
|
||||
sql = sql.trimEnd().replace(/;?\s*$/, " ON CONFLICT DO NOTHING");
|
||||
}
|
||||
if (/INSERT\s+OR\s+REPLACE/i.test(sql)) {
|
||||
sql = sql.replace(/INSERT\s+OR\s+REPLACE\s+INTO/gi, "INSERT INTO");
|
||||
}
|
||||
|
||||
// `?` → `$1`, `$2`, ... Skips `?` characters inside string literals.
|
||||
let out = "";
|
||||
let n = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue