From 7a2bed78562e72250ec2e2fbef689fcbfbb6d00b Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 24 Jun 2025 10:33:27 -0700 Subject: [PATCH] Add test for upsert with representable This test would have caught the regression introduced by #95. --- .../StructuredQueriesTests/InsertTests.swift | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Tests/StructuredQueriesTests/InsertTests.swift b/Tests/StructuredQueriesTests/InsertTests.swift index a0843eef..935305e2 100644 --- a/Tests/StructuredQueriesTests/InsertTests.swift +++ b/Tests/StructuredQueriesTests/InsertTests.swift @@ -476,6 +476,36 @@ extension SnapshotTests { } } + @Test func upsertRepresentation() { + assertQuery( + Item.insert { + $0.notes + } values: { + ["Hello", "World"] + } onConflictDoUpdate: { + $0.notes = ["Goodnight", "Moon"] + } + ) { + """ + INSERT INTO "items" + ("notes") + VALUES + ('[ + "Hello", + "World" + ]') + ON CONFLICT DO UPDATE SET "notes" = '[ + "Goodnight", + "Moon" + ]' + """ + } results: { + """ + no such table: items + """ + } + } + @Test func sql() { assertQuery( #sql( @@ -537,9 +567,11 @@ extension SnapshotTests { ) { """ INSERT INTO "items" - ("title", "quantity") + ("title", "quantity", "notes") VALUES - ('', 0) + ('', 0, '[ + + ]') """ } } @@ -642,4 +674,6 @@ extension SnapshotTests { @Table private struct Item { var title = "" var quantity = 0 + @Column(as: [String].JSONRepresentation.self) + var notes: [String] = [] }