File tree Expand file tree Collapse file tree 2 files changed +53
-6
lines changed
Sources/StructuredQueriesCore/Statements
Tests/StructuredQueriesTests Expand file tree Collapse file tree 2 files changed +53
-6
lines changed Original file line number Diff line number Diff line change @@ -68,8 +68,8 @@ extension PrimaryKeyedTable {
6868 _ row: Self
6969 ) -> UpdateOf < Self > {
7070 update ( or: conflictResolution) { updates in
71- for column in TableColumns . allColumns where column. name != columns. primaryKey. name {
72- func open< Root, Value> ( _ column: some TableColumnExpression < Root , Value > ) {
71+ for column in TableColumns . writableColumns where column. name != columns. primaryKey. name {
72+ func open< Root, Value> ( _ column: some WritableTableColumnExpression < Root , Value > ) {
7373 updates. set (
7474 column,
7575 Value ( queryOutput: ( row as! Root ) [ keyPath: column. keyPath] ) . queryFragment
Original file line number Diff line number Diff line change @@ -252,9 +252,53 @@ extension SnapshotTests {
252252 └───────────────────────────────────────────────────┘
253253 """
254254 }
255- }
256-
257- @Test func tableAliasGenerated( ) {
255+ assertQuery (
256+ Row
257+ . update ( Row ( id: UUID ( 2 ) , isDeleted: true , isNotDeleted: false ) )
258+ . returning ( \. self)
259+ ) {
260+ """
261+ UPDATE " rows "
262+ SET " isDeleted " = 1
263+ WHERE ( " rows " . " id " = '00000000-0000-0000-0000-000000000002')
264+ RETURNING " id " , " isDeleted " , " isNotDeleted "
265+ """
266+ } results: {
267+ """
268+ ┌───────────────────────────────────────────────────┐
269+ │ Row( │
270+ │ id: UUID(00000000-0000-0000-0000-000000000002), │
271+ │ isDeleted: true, │
272+ │ isNotDeleted: false │
273+ │ ) │
274+ └───────────────────────────────────────────────────┘
275+ """
276+ }
277+ assertQuery (
278+ Row
279+ . upsert { Row . Draft ( id: UUID ( 2 ) , isDeleted: false ) }
280+ . returning ( \. self)
281+ ) {
282+ """
283+ INSERT INTO " rows "
284+ ( " id " , " isDeleted " )
285+ VALUES
286+ ('00000000-0000-0000-0000-000000000002', 0)
287+ ON CONFLICT ( " id " )
288+ DO UPDATE SET " isDeleted " = " excluded " . " isDeleted "
289+ RETURNING " id " , " isDeleted " , " isNotDeleted "
290+ """
291+ } results: {
292+ """
293+ ┌───────────────────────────────────────────────────┐
294+ │ Row( │
295+ │ id: UUID(00000000-0000-0000-0000-000000000002), │
296+ │ isDeleted: false, │
297+ │ isNotDeleted: true │
298+ │ ) │
299+ └───────────────────────────────────────────────────┘
300+ """
301+ }
258302 enum R : AliasName { }
259303 assertQuery (
260304 Row . as ( R . self) . select ( \. isNotDeleted)
@@ -265,7 +309,10 @@ extension SnapshotTests {
265309 """
266310 } results: {
267311 """
268- no such table: rows
312+ ┌──────┐
313+ │ true │
314+ │ true │
315+ └──────┘
269316 """
270317 }
271318 }
You can’t perform that action at this time.
0 commit comments