Skip to content

Commit efd928f

Browse files
authored
Add test for upsert with representable (#97)
This test would have caught the regression introduced by #95.
1 parent a6bc6d5 commit efd928f

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

Tests/StructuredQueriesTests/InsertTests.swift

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,36 @@ extension SnapshotTests {
476476
}
477477
}
478478

479+
@Test func upsertRepresentation() {
480+
assertQuery(
481+
Item.insert {
482+
$0.notes
483+
} values: {
484+
["Hello", "World"]
485+
} onConflictDoUpdate: {
486+
$0.notes = ["Goodnight", "Moon"]
487+
}
488+
) {
489+
"""
490+
INSERT INTO "items"
491+
("notes")
492+
VALUES
493+
('[
494+
"Hello",
495+
"World"
496+
]')
497+
ON CONFLICT DO UPDATE SET "notes" = '[
498+
"Goodnight",
499+
"Moon"
500+
]'
501+
"""
502+
} results: {
503+
"""
504+
no such table: items
505+
"""
506+
}
507+
}
508+
479509
@Test func sql() {
480510
assertQuery(
481511
#sql(
@@ -537,9 +567,11 @@ extension SnapshotTests {
537567
) {
538568
"""
539569
INSERT INTO "items"
540-
("title", "quantity")
570+
("title", "quantity", "notes")
541571
VALUES
542-
('', 0)
572+
('', 0, '[
573+
574+
]')
543575
"""
544576
}
545577
}
@@ -642,4 +674,6 @@ extension SnapshotTests {
642674
@Table private struct Item {
643675
var title = ""
644676
var quantity = 0
677+
@Column(as: [String].JSONRepresentation.self)
678+
var notes: [String] = []
645679
}

0 commit comments

Comments
 (0)