@@ -24,19 +24,31 @@ extension SnapshotTests {
2424 )
2525 )
2626 assertQuery (
27- Item . insert {
28- Item ( title: " Phone " , quantity: 1 , status: Status ( ) )
29- }
27+ Item
28+ . insert {
29+ Item ( title: " Phone " , quantity: 1 , status: Status ( ) )
30+ }
31+ . returning ( \. self)
3032 ) {
3133 """
3234 INSERT INTO " items "
3335 ( " title " , " quantity " , " isOutOfStock " , " isOnBackOrder " )
3436 VALUES
3537 ('Phone', 1, 0, 0)
38+ RETURNING " title " , " quantity " , " isOutOfStock " , " isOnBackOrder "
3639 """
3740 } results: {
3841 """
39-
42+ ┌──────────────────────────┐
43+ │ Item( │
44+ │ title: " Phone " , │
45+ │ quantity: 1, │
46+ │ status: Status( │
47+ │ isOutOfStock: false, │
48+ │ isOnBackOrder: false │
49+ │ ) │
50+ │ ) │
51+ └──────────────────────────┘
4052 """
4153 }
4254 assertQuery (
@@ -61,19 +73,56 @@ extension SnapshotTests {
6173 """
6274 }
6375 assertQuery (
64- Item . where { $0. status. eq ( Status ( ) ) }
76+ Item . where { $0. status. eq ( Status ( ) ) } . select ( \ . status )
6577 ) {
6678 """
67- SELECT " items " . " title " , " items " . " quantity " , " items " . " isOutOfStock " , " items " . " isOnBackOrder "
79+ SELECT " items " . " isOutOfStock " , " items " . " isOnBackOrder "
6880 FROM " items "
6981 WHERE ( " items " . " isOutOfStock " , " items " . " isOnBackOrder " ) = (0, 0)
7082 """
83+ } results: {
84+ """
85+ ┌────────────────────────┐
86+ │ Status( │
87+ │ isOutOfStock: false, │
88+ │ isOnBackOrder: false │
89+ │ ) │
90+ └────────────────────────┘
91+ """
92+ }
93+ // FIXME: This should decode 'nil' but because all its fields have defaults it coalesces.
94+ assertQuery (
95+ DefaultItem ? ( nil )
96+ ) {
97+ """
98+ SELECT NULL AS " title " , NULL AS " quantity " , NULL AS " isOutOfStock " , NULL AS " isOnBackOrder "
99+ """
71100 } results: {
72101 """
73102 ┌──────────────────────────┐
74- │ Item( │
75- │ title: " Phone " , │
76- │ quantity: 1, │
103+ │ DefaultItem( │
104+ │ title: " " , │
105+ │ quantity: 0, │
106+ │ status: Status( │
107+ │ isOutOfStock: false, │
108+ │ isOnBackOrder: false │
109+ │ ) │
110+ │ ) │
111+ └──────────────────────────┘
112+ """
113+ }
114+ assertQuery (
115+ DefaultItem ? . none
116+ ) {
117+ """
118+ SELECT NULL AS " title " , NULL AS " quantity " , NULL AS " isOutOfStock " , NULL AS " isOnBackOrder "
119+ """
120+ } results: {
121+ """
122+ ┌──────────────────────────┐
123+ │ DefaultItem( │
124+ │ title: " " , │
125+ │ quantity: 0, │
77126 │ status: Status( │
78127 │ isOutOfStock: false, │
79128 │ isOnBackOrder: false │
@@ -110,6 +159,22 @@ extension SnapshotTests {
110159 (NULL, NULL, NULL, NULL, '2001-01-01 00:00:00.000')
111160 """
112161 }
162+ assertQuery (
163+ ItemWithTimestamp ( item: nil , timestamp: Date ( timeIntervalSinceReferenceDate: 0 ) )
164+ ) {
165+ """
166+ SELECT NULL AS " title " , NULL AS " quantity " , NULL AS " isOutOfStock " , NULL AS " isOnBackOrder " , '2001-01-01 00:00:00.000' AS " timestamp "
167+ """
168+ } results: {
169+ """
170+ ┌─────────────────────────────────────────────┐
171+ │ ItemWithTimestamp( │
172+ │ item: nil, │
173+ │ timestamp: Date(2001-01-01T00:00:00.000Z) │
174+ │ ) │
175+ └─────────────────────────────────────────────┘
176+ """
177+ }
113178 assertQuery (
114179 ItemWithTimestamp . insert {
115180 ItemWithTimestamp (
@@ -181,6 +246,14 @@ extension SnapshotTests {
181246
182247@Table
183248private struct Item {
249+ var title : String
250+ var quantity = 0
251+ @Columns
252+ var status : Status = Status ( )
253+ }
254+
255+ @Table ( " items " )
256+ private struct DefaultItem {
184257 var title = " "
185258 var quantity = 0
186259 @Columns
0 commit comments