From 381376ca3127cae0cad8aadd79f56b07bc4f9069 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Tue, 8 Oct 2024 09:20:07 +0300 Subject: [PATCH] Fix formatting of DO UPDATE in SQLite Fixes #783 --- src/languages/sqlite/sqlite.formatter.ts | 1 + test/sqlite.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/languages/sqlite/sqlite.formatter.ts b/src/languages/sqlite/sqlite.formatter.ts index 5d7c10c05e..98f9bbfa9e 100644 --- a/src/languages/sqlite/sqlite.formatter.ts +++ b/src/languages/sqlite/sqlite.formatter.ts @@ -63,6 +63,7 @@ const reservedJoins = expandPhrases([ const reservedPhrases = expandPhrases([ 'ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]', '{ROWS | RANGE | GROUPS} BETWEEN', + 'DO UPDATE', ]); export const sqlite: DialectOptions = { diff --git a/test/sqlite.test.ts b/test/sqlite.test.ts index 7d12dea399..40b04c3ea4 100644 --- a/test/sqlite.test.ts +++ b/test/sqlite.test.ts @@ -65,4 +65,17 @@ describe('SqliteFormatter', () => { (2, 'Dog'); `); }); + + it('supports ON CONFLICT .. DO UPDATE syntax', () => { + expect(format(`INSERT INTO tbl VALUES (1,'Leopard') ON CONFLICT DO UPDATE SET foo=1;`)) + .toBe(dedent` + INSERT INTO + tbl + VALUES + (1, 'Leopard') + ON CONFLICT DO UPDATE + SET + foo = 1; + `); + }); });