Skip to content

Commit 7d434e2

Browse files
committed
wip
1 parent c4c2d03 commit 7d434e2

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

Tests/StructuredQueriesTests/NestedTests.swift

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,24 +302,26 @@ extension SnapshotTests {
302302
"recordID" TEXT NOT NULL ON CONFLICT REPLACE DEFAULT
303303
'00000000-0000-0000-0000-000000000000',
304304
"recordType" TEXT NOT NULL ON CONFLICT REPLACE DEFAULT 'reminders',
305+
"userModificationDate" TEXT NOT NULL,
305306
PRIMARY KEY ("recordID", "recordType")
306307
)
307308
"""
308309
)
309310
)
311+
let now = Date(timeIntervalSinceReferenceDate: 0)
310312
assertQuery(
311313
Metadata
312314
.insert {
313-
Metadata.Draft()
315+
Metadata.Draft(userModificationDate: now)
314316
}
315317
.returning(\.self)
316318
) {
317319
"""
318320
INSERT INTO "metadatas"
319-
("recordID", "recordType")
321+
("recordID", "recordType", "userModificationDate")
320322
VALUES
321-
(NULL, NULL)
322-
RETURNING "recordID", "recordType"
323+
(NULL, NULL, '2001-01-01 00:00:00.000')
324+
RETURNING "recordID", "recordType", "userModificationDate"
323325
"""
324326
} results: {
325327
"""
@@ -328,7 +330,8 @@ extension SnapshotTests {
328330
│ id: MetadataID( │
329331
│ recordID: UUID(00000000-0000-0000-0000-000000000000), │
330332
│ recordType: "reminders"
331-
│ ) │
333+
│ ), │
334+
│ userModificationDate: Date(2001-01-01T00:00:00.000Z) │
332335
│ ) │
333336
└───────────────────────────────────────────────────────────┘
334337
"""
@@ -337,7 +340,7 @@ extension SnapshotTests {
337340
Metadata.find(MetadataID(recordID: UUID(0), recordType: "reminders"))
338341
) {
339342
"""
340-
SELECT "metadatas"."recordID", "metadatas"."recordType"
343+
SELECT "metadatas"."recordID", "metadatas"."recordType", "metadatas"."userModificationDate"
341344
FROM "metadatas"
342345
WHERE ("metadatas"."recordID", "metadatas"."recordType") IN (('00000000-0000-0000-0000-000000000000', 'reminders'))
343346
"""
@@ -348,25 +351,41 @@ extension SnapshotTests {
348351
│ id: MetadataID( │
349352
│ recordID: UUID(00000000-0000-0000-0000-000000000000), │
350353
│ recordType: "reminders"
351-
│ ) │
354+
│ ), │
355+
│ userModificationDate: Date(2001-01-01T00:00:00.000Z) │
352356
│ ) │
353357
└───────────────────────────────────────────────────────────┘
354358
"""
355359
}
356360
assertQuery(
357361
Metadata.upsert {
358362
Metadata(
359-
id: MetadataID(recordID: UUID(0), recordType: "reminders")
363+
id: MetadataID(recordID: UUID(0), recordType: "reminders"),
364+
userModificationDate: now.addingTimeInterval(1)
360365
)
361366
}
367+
.returning(\.self)
362368
) {
363369
"""
364370
INSERT INTO "metadatas"
365-
("recordID", "recordType")
371+
("recordID", "recordType", "userModificationDate")
366372
VALUES
367-
('00000000-0000-0000-0000-000000000000', 'reminders')
373+
('00000000-0000-0000-0000-000000000000', 'reminders', '2001-01-01 00:00:01.000')
368374
ON CONFLICT ("recordID", "recordType")
369-
DO NOTHING
375+
DO UPDATE SET "userModificationDate" = "excluded"."userModificationDate"
376+
RETURNING "recordID", "recordType", "userModificationDate"
377+
"""
378+
} results: {
379+
"""
380+
┌───────────────────────────────────────────────────────────┐
381+
│ Metadata( │
382+
│ id: MetadataID( │
383+
│ recordID: UUID(00000000-0000-0000-0000-000000000000), │
384+
│ recordType: "reminders"
385+
│ ), │
386+
│ userModificationDate: Date(2001-01-01T00:00:01.000Z) │
387+
│ ) │
388+
└───────────────────────────────────────────────────────────┘
370389
"""
371390
}
372391
}
@@ -420,8 +439,9 @@ private struct Row {
420439

421440
@Table
422441
private struct Metadata: Identifiable {
423-
@Columns/*(primaryKey: true)*/
442+
@Columns /*(primaryKey: true)*/
424443
let id: MetadataID
444+
var userModificationDate: Date
425445
}
426446

427447
@Table

0 commit comments

Comments
 (0)