Skip to content

Commit a6bc6d5

Browse files
committed
Revert #95
This reverts commit e6b2d2e.
1 parent d0ca5d1 commit a6bc6d5

File tree

4 files changed

+26
-72
lines changed

4 files changed

+26
-72
lines changed

Sources/StructuredQueriesCore/Internal/Deprecations.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension Table {
4545
public static func insert(
4646
or conflictResolution: ConflictResolution? = nil,
4747
_ row: Self,
48-
onConflict doUpdate: ((inout Upsert<Self>) -> Void)? = nil
48+
onConflict doUpdate: ((inout Updates<Self>) -> Void)? = nil
4949
) -> InsertOf<Self> {
5050
insert(or: conflictResolution, [row], onConflict: doUpdate)
5151
}
@@ -56,7 +56,7 @@ extension Table {
5656
public static func insert(
5757
or conflictResolution: ConflictResolution? = nil,
5858
_ rows: [Self],
59-
onConflict doUpdate: ((inout Upsert<Self>) -> Void)? = nil
59+
onConflict doUpdate: ((inout Updates<Self>) -> Void)? = nil
6060
) -> InsertOf<Self> {
6161
insert(or: conflictResolution, values: { rows }, onConflict: doUpdate)
6262
}
@@ -66,7 +66,7 @@ extension Table {
6666
or conflictResolution: ConflictResolution? = nil,
6767
_ columns: (TableColumns) -> TableColumns = { $0 },
6868
@InsertValuesBuilder<Self> values: () -> [Self],
69-
onConflict updates: ((inout Upsert<Self>) -> Void)?
69+
onConflict updates: ((inout Updates<Self>) -> Void)?
7070
) -> InsertOf<Self> {
7171
insert(or: conflictResolution, columns, values: values, onConflictDoUpdate: updates)
7272
}
@@ -77,7 +77,7 @@ extension Table {
7777
_ columns: (TableColumns) -> (TableColumn<Self, V1>, repeat TableColumn<Self, each V2>),
7878
@InsertValuesBuilder<(V1.QueryOutput, repeat (each V2).QueryOutput)>
7979
values: () -> [(V1.QueryOutput, repeat (each V2).QueryOutput)],
80-
onConflict updates: ((inout Upsert<Self>) -> Void)?
80+
onConflict updates: ((inout Updates<Self>) -> Void)?
8181
) -> InsertOf<Self> {
8282
insert(or: conflictResolution, columns, values: values, onConflictDoUpdate: updates)
8383
}
@@ -89,7 +89,7 @@ extension Table {
8989
or conflictResolution: ConflictResolution? = nil,
9090
_ columns: (TableColumns) -> (TableColumn<Self, V1>, repeat TableColumn<Self, each V2>),
9191
select selection: () -> Select<(V1, repeat each V2), From, Joins>,
92-
onConflict updates: ((inout Upsert<Self>) -> Void)?
92+
onConflict updates: ((inout Updates<Self>) -> Void)?
9393
) -> InsertOf<Self> {
9494
insert(or: conflictResolution, columns, select: selection, onConflictDoUpdate: updates)
9595
}
@@ -102,7 +102,7 @@ extension PrimaryKeyedTable {
102102
public static func insert(
103103
or conflictResolution: ConflictResolution? = nil,
104104
_ row: Draft,
105-
onConflict updates: ((inout Upsert<Self>) -> Void)? = nil
105+
onConflict updates: ((inout Updates<Self>) -> Void)? = nil
106106
) -> InsertOf<Self> {
107107
insert(or: conflictResolution, values: { row }, onConflictDoUpdate: updates)
108108
}
@@ -113,7 +113,7 @@ extension PrimaryKeyedTable {
113113
public static func insert(
114114
or conflictResolution: ConflictResolution? = nil,
115115
_ rows: [Draft],
116-
onConflict updates: ((inout Upsert<Self>) -> Void)? = nil
116+
onConflict updates: ((inout Updates<Self>) -> Void)? = nil
117117
) -> InsertOf<Self> {
118118
insert(or: conflictResolution, values: { rows }, onConflictDoUpdate: updates)
119119
}

Sources/StructuredQueriesCore/Statements/Insert.swift

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extension Table {
5454
or conflictResolution: ConflictResolution? = nil,
5555
_ columns: (TableColumns) -> TableColumns = { $0 },
5656
@InsertValuesBuilder<Self> values: () -> [Self],
57-
onConflictDoUpdate updates: ((inout Upsert<Self>) -> Void)? = nil,
57+
onConflictDoUpdate updates: ((inout Updates<Self>) -> Void)? = nil,
5858
@QueryFragmentBuilder<Bool>
5959
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
6060
) -> InsertOf<Self> {
@@ -89,7 +89,7 @@ extension Table {
8989
),
9090
@QueryFragmentBuilder<Bool>
9191
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
92-
doUpdate updates: (inout Upsert<Self>) -> Void = { _ in },
92+
doUpdate updates: (inout Updates<Self>) -> Void = { _ in },
9393
@QueryFragmentBuilder<Bool>
9494
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
9595
) -> InsertOf<Self> {
@@ -111,7 +111,7 @@ extension Table {
111111
onConflict conflictTargets: (TableColumns) -> (repeat TableColumn<Self, each ConflictTarget>)?,
112112
@QueryFragmentBuilder<Bool>
113113
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
114-
doUpdate updates: ((inout Upsert<Self>) -> Void)?,
114+
doUpdate updates: ((inout Updates<Self>) -> Void)?,
115115
@QueryFragmentBuilder<Bool>
116116
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
117117
) -> InsertOf<Self> {
@@ -197,7 +197,7 @@ extension Table {
197197
_ columns: (TableColumns) -> (TableColumn<Self, V1>, repeat TableColumn<Self, each V2>),
198198
@InsertValuesBuilder<(V1.QueryOutput, repeat (each V2).QueryOutput)>
199199
values: () -> [(V1.QueryOutput, repeat (each V2).QueryOutput)],
200-
onConflictDoUpdate updates: ((inout Upsert<Self>) -> Void)? = nil,
200+
onConflictDoUpdate updates: ((inout Updates<Self>) -> Void)? = nil,
201201
@QueryFragmentBuilder<Bool>
202202
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
203203
) -> InsertOf<Self> {
@@ -234,7 +234,7 @@ extension Table {
234234
),
235235
@QueryFragmentBuilder<Bool>
236236
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
237-
doUpdate updates: (inout Upsert<Self>) -> Void = { _ in },
237+
doUpdate updates: (inout Updates<Self>) -> Void = { _ in },
238238
@QueryFragmentBuilder<Bool>
239239
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
240240
) -> InsertOf<Self> {
@@ -259,7 +259,7 @@ extension Table {
259259
onConflict conflictTargets: (TableColumns) -> (repeat TableColumn<Self, each ConflictTarget>)?,
260260
@QueryFragmentBuilder<Bool>
261261
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
262-
doUpdate updates: ((inout Upsert<Self>) -> Void)?,
262+
doUpdate updates: ((inout Updates<Self>) -> Void)?,
263263
@QueryFragmentBuilder<Bool>
264264
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
265265
) -> InsertOf<Self> {
@@ -306,7 +306,7 @@ extension Table {
306306
or conflictResolution: ConflictResolution? = nil,
307307
_ columns: (TableColumns) -> (TableColumn<Self, V1>, repeat TableColumn<Self, each V2>),
308308
select selection: () -> some PartialSelectStatement<(V1, repeat each V2)>,
309-
onConflictDoUpdate updates: ((inout Upsert<Self>) -> Void)? = nil,
309+
onConflictDoUpdate updates: ((inout Updates<Self>) -> Void)? = nil,
310310
@QueryFragmentBuilder<Bool>
311311
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
312312
) -> InsertOf<Self> {
@@ -350,7 +350,7 @@ extension Table {
350350
),
351351
@QueryFragmentBuilder<Bool>
352352
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
353-
doUpdate updates: (inout Upsert<Self>) -> Void = { _ in },
353+
doUpdate updates: (inout Updates<Self>) -> Void = { _ in },
354354
@QueryFragmentBuilder<Bool>
355355
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
356356
) -> InsertOf<Self> {
@@ -377,7 +377,7 @@ extension Table {
377377
onConflict conflictTargets: (TableColumns) -> (repeat TableColumn<Self, each ConflictTarget>)?,
378378
@QueryFragmentBuilder<Bool>
379379
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
380-
doUpdate updates: ((inout Upsert<Self>) -> Void)?,
380+
doUpdate updates: ((inout Updates<Self>) -> Void)?,
381381
@QueryFragmentBuilder<Bool>
382382
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
383383
) -> InsertOf<Self> {
@@ -428,7 +428,7 @@ extension Table {
428428
onConflict conflictTargets: (TableColumns) -> (repeat TableColumn<Self, each ConflictTarget>)?,
429429
@QueryFragmentBuilder<Bool>
430430
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
431-
doUpdate updates: ((inout Upsert<Self>) -> Void)?,
431+
doUpdate updates: ((inout Updates<Self>) -> Void)?,
432432
@QueryFragmentBuilder<Bool>
433433
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
434434
) -> InsertOf<Self> {
@@ -444,7 +444,7 @@ extension Table {
444444
conflictTargetColumnNames: conflictTargetColumnNames,
445445
conflictTargetFilter: targetFilter(Self.columns),
446446
values: values,
447-
updates: updates.map { Upsert($0) },
447+
updates: updates.map { Updates($0) },
448448
updateFilter: updateFilter(Self.columns),
449449
returning: []
450450
)
@@ -468,7 +468,7 @@ extension PrimaryKeyedTable {
468468
or conflictResolution: ConflictResolution? = nil,
469469
_ columns: (Draft.TableColumns) -> Draft.TableColumns = { $0 },
470470
@InsertValuesBuilder<Draft> values: () -> [Draft],
471-
onConflictDoUpdate updates: ((inout Upsert<Self>) -> Void)? = nil,
471+
onConflictDoUpdate updates: ((inout Updates<Self>) -> Void)? = nil,
472472
@QueryFragmentBuilder<Bool>
473473
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
474474
) -> InsertOf<Self> {
@@ -504,7 +504,7 @@ extension PrimaryKeyedTable {
504504
),
505505
@QueryFragmentBuilder<Bool>
506506
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
507-
doUpdate updates: (inout Upsert<Self>) -> Void = { _ in },
507+
doUpdate updates: (inout Updates<Self>) -> Void = { _ in },
508508
@QueryFragmentBuilder<Bool>
509509
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
510510
) -> InsertOf<Self> {
@@ -545,7 +545,7 @@ extension PrimaryKeyedTable {
545545
onConflict: { $0.primaryKey },
546546
doUpdate: { updates in
547547
for column in Draft.TableColumns.allColumns where column.name != columns.primaryKey.name {
548-
updates.updates.set(column, #""excluded".\#(quote: column.name)"#)
548+
updates.set(column, #""excluded".\#(quote: column.name)"#)
549549
}
550550
}
551551
)
@@ -557,7 +557,7 @@ extension PrimaryKeyedTable {
557557
onConflict conflictTargets: (TableColumns) -> (repeat TableColumn<Self, each ConflictTarget>)?,
558558
@QueryFragmentBuilder<Bool>
559559
where targetFilter: (TableColumns) -> [QueryFragment] = { _ in [] },
560-
doUpdate updates: ((inout Upsert<Self>) -> Void)?,
560+
doUpdate updates: ((inout Updates<Self>) -> Void)?,
561561
@QueryFragmentBuilder<Bool>
562562
where updateFilter: (TableColumns) -> [QueryFragment] = { _ in [] }
563563
) -> InsertOf<Self> {
@@ -590,49 +590,6 @@ private enum InsertValues {
590590
case select(QueryFragment)
591591
}
592592

593-
@dynamicMemberLookup
594-
public struct Upsert<Base: Table>: QueryExpression {
595-
public typealias QueryValue = Never
596-
597-
public struct Excluded: AliasName {
598-
public static var aliasName: String {
599-
"excluded"
600-
}
601-
}
602-
603-
init(_ body: (inout Self) -> Void) {
604-
body(&self)
605-
}
606-
607-
fileprivate var updates = Updates<Base>()
608-
609-
public var excluded: TableAlias<Base, Excluded>.TableColumns {
610-
Base.as(Excluded.self).columns
611-
}
612-
613-
public subscript<Member>(dynamicMember keyPath: KeyPath<Updates<Base>, Member>) -> Member {
614-
updates[keyPath: keyPath]
615-
}
616-
617-
public subscript<Member>(
618-
dynamicMember keyPath: WritableKeyPath<Updates<Base>, Member>
619-
) -> Member {
620-
get { updates[keyPath: keyPath] }
621-
set { updates[keyPath: keyPath] = newValue }
622-
}
623-
624-
public subscript<Value>(
625-
dynamicMember keyPath: KeyPath<Base.TableColumns, TableColumn<Base, Value>>
626-
) -> any QueryExpression<Value> {
627-
get { updates[dynamicMember: keyPath] }
628-
set { updates[dynamicMember: keyPath] = newValue }
629-
}
630-
631-
public var queryFragment: QueryFragment {
632-
updates.queryFragment
633-
}
634-
}
635-
636593
/// An `INSERT` statement.
637594
///
638595
/// This type of statement is returned from the
@@ -646,7 +603,7 @@ public struct Insert<Into: Table, Returning> {
646603
var conflictTargetColumnNames: [String]
647604
var conflictTargetFilter: [QueryFragment]
648605
fileprivate var values: InsertValues
649-
var updates: Upsert<Into>?
606+
var updates: Updates<Into>?
650607
var updateFilter: [QueryFragment]
651608
var returning: [QueryFragment]
652609

@@ -656,7 +613,7 @@ public struct Insert<Into: Table, Returning> {
656613
conflictTargetColumnNames: [String],
657614
conflictTargetFilter: [QueryFragment],
658615
values: InsertValues,
659-
updates: Upsert<Into>?,
616+
updates: Updates<Into>?,
660617
updateFilter: [QueryFragment],
661618
returning: [QueryFragment]
662619
) {

Sources/StructuredQueriesCore/Updates.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
public struct Updates<Base: Table> {
99
private var updates: [(String, QueryFragment)] = []
1010

11-
init() {
12-
}
13-
1411
init(_ body: (inout Self) -> Void) {
1512
body(&self)
1613
}

Tests/StructuredQueriesTests/InsertTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ extension SnapshotTests {
553553
} where: {
554554
!$0.isCompleted
555555
} doUpdate: {
556-
$0.isCompleted = $0.excluded.isCompleted
556+
$0.isCompleted = true
557557
} where: {
558558
$0.isFlagged
559559
}
@@ -565,7 +565,7 @@ extension SnapshotTests {
565565
(NULL, NULL, NULL, 0, 0, '', NULL, 1, '', '2040-02-14 23:31:30.000')
566566
ON CONFLICT ("id")
567567
WHERE NOT ("reminders"."isCompleted")
568-
DO UPDATE SET "isCompleted" = "excluded"."isCompleted"
568+
DO UPDATE SET "isCompleted" = 1
569569
WHERE "reminders"."isFlagged"
570570
"""
571571
}

0 commit comments

Comments
 (0)