Skip to content

Commit 7800ea8

Browse files
committed
wip
1 parent 3905f40 commit 7800ea8

File tree

9 files changed

+57
-16
lines changed

9 files changed

+57
-16
lines changed

Sources/StructuredQueriesCore/Internal/Deprecations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ extension PrimaryKeyedTable {
113113
}
114114

115115
// TODO: Support composite keys.
116-
extension PrimaryKeyedTable where TableColumns.PrimaryKeyColumn == TableColumn<Self, PrimaryKey> {
116+
extension PrimaryKeyedTable where TableColumns.PrimaryColumn == TableColumn<Self, PrimaryKey> {
117117
@available(
118118
*, deprecated, message: "Use a trailing closure, instead: 'Table.upsert { draft }'"
119119
)

Sources/StructuredQueriesCore/Optional.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ extension Optional: Table, PartialSelectStatement, Statement where Wrapped: Tabl
140140
)
141141
}
142142

143+
public subscript<Member>(
144+
dynamicMember keyPath: KeyPath<Wrapped.TableColumns, GeneratedColumn<Wrapped, Member>>
145+
) -> GeneratedColumn<Optional, Member?> {
146+
let column = Wrapped.columns[keyPath: keyPath]
147+
return GeneratedColumn<Optional, Member?>(
148+
column.name,
149+
keyPath: \.[member: \Member.self, column: column.keyPath]
150+
)
151+
}
152+
143153
public subscript<Member: QueryExpression>(
144154
dynamicMember keyPath: KeyPath<Wrapped.TableColumns, Member>
145155
) -> some QueryExpression<Member.QueryValue?> {
@@ -161,7 +171,7 @@ extension Optional: Table, PartialSelectStatement, Statement where Wrapped: Tabl
161171
extension Optional: PrimaryKeyedTable
162172
where
163173
Wrapped: PrimaryKeyedTable,
164-
Wrapped.TableColumns.PrimaryKeyColumn == TableColumn<Wrapped, Wrapped.PrimaryKey>
174+
Wrapped.TableColumns.PrimaryColumn == TableColumn<Wrapped, Wrapped.PrimaryKey>
165175
{
166176
public typealias Draft = Wrapped.Draft?
167177
}
@@ -170,7 +180,7 @@ where
170180
extension Optional: TableDraft
171181
where
172182
Wrapped: TableDraft,
173-
Wrapped.PrimaryTable.TableColumns.PrimaryKeyColumn == TableColumn<
183+
Wrapped.PrimaryTable.TableColumns.PrimaryColumn == TableColumn<
174184
Wrapped.PrimaryTable, Wrapped.PrimaryTable.PrimaryKey
175185
>
176186
{
@@ -184,7 +194,7 @@ where
184194
extension Optional.TableColumns: PrimaryKeyedTableDefinition
185195
where
186196
Wrapped.TableColumns: PrimaryKeyedTableDefinition,
187-
Wrapped.TableColumns.PrimaryKeyColumn == TableColumn<Wrapped, Wrapped.PrimaryKey>
197+
Wrapped.TableColumns.PrimaryColumn == TableColumn<Wrapped, Wrapped.PrimaryKey>
188198
{
189199
public typealias PrimaryKey = Wrapped.TableColumns.PrimaryKey?
190200

Sources/StructuredQueriesCore/PrimaryKeyed.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ where QueryValue: PrimaryKeyedTable {
5252
associatedtype PrimaryKey: QueryRepresentable & QueryExpression
5353
where PrimaryKey.QueryValue == PrimaryKey
5454

55-
associatedtype PrimaryKeyColumn: _TableColumnExpression<QueryValue, PrimaryKey>
55+
associatedtype PrimaryColumn: _TableColumnExpression<QueryValue, PrimaryKey>
5656

5757
/// The column representing this table's primary key.
58-
var primaryKey: PrimaryKeyColumn { get }
58+
var primaryKey: PrimaryColumn { get }
5959
}
6060

6161
extension TableDefinition where QueryValue: TableDraft {
@@ -66,7 +66,7 @@ extension TableDefinition where QueryValue: TableDraft {
6666
}
6767
}
6868

69-
extension PrimaryKeyedTableDefinition where PrimaryKeyColumn: TableColumnExpression {
69+
extension PrimaryKeyedTableDefinition where PrimaryColumn: TableColumnExpression {
7070
/// A query expression representing the number of rows in this table.
7171
///
7272
/// - Parameters:

Sources/StructuredQueriesCore/Statements/Insert.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ extension Table {
617617
}
618618

619619
// TODO: Support composite keys.
620-
extension PrimaryKeyedTable where TableColumns.PrimaryKeyColumn == TableColumn<Self, PrimaryKey> {
620+
extension PrimaryKeyedTable where TableColumns.PrimaryColumn == TableColumn<Self, PrimaryKey> {
621621
/// An upsert statement for given drafts.
622622
///
623623
/// Generates an insert statement with an upsert clause. Useful for building forms that can both

Sources/StructuredQueriesCore/TableAlias.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public struct TableAlias<
179179
extension TableAlias: PrimaryKeyedTable
180180
where
181181
Base: PrimaryKeyedTable,
182-
Base.TableColumns.PrimaryKeyColumn == TableColumn<Base, Base.PrimaryKey>
182+
Base.TableColumns.PrimaryColumn == TableColumn<Base, Base.PrimaryKey>
183183
{
184184
public typealias Draft = TableAlias<Base.Draft, Name>
185185
}
@@ -188,7 +188,7 @@ where
188188
extension TableAlias: TableDraft
189189
where
190190
Base: TableDraft,
191-
Base.PrimaryTable.TableColumns.PrimaryKeyColumn == TableColumn<
191+
Base.PrimaryTable.TableColumns.PrimaryColumn == TableColumn<
192192
Base.PrimaryTable, Base.PrimaryTable.PrimaryKey
193193
>
194194
{
@@ -202,7 +202,7 @@ where
202202
extension TableAlias.TableColumns: PrimaryKeyedTableDefinition
203203
where
204204
Base.TableColumns: PrimaryKeyedTableDefinition,
205-
Base.TableColumns.PrimaryKeyColumn == TableColumn<Base, Base.PrimaryKey>
205+
Base.TableColumns.PrimaryColumn == TableColumn<Base, Base.PrimaryKey>
206206
{
207207
public typealias PrimaryKey = Base.TableColumns.PrimaryKey
208208

Sources/StructuredQueriesSQLiteCore/Insert.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ extension Table {
451451
}
452452

453453
// TODO: Support composite keys.
454-
extension PrimaryKeyedTable where TableColumns.PrimaryKeyColumn == TableColumn<Self, PrimaryKey> {
454+
extension PrimaryKeyedTable where TableColumns.PrimaryColumn == TableColumn<Self, PrimaryKey> {
455455
/// An upsert statement for given drafts.
456456
///
457457
/// - Parameters:

Sources/StructuredQueriesSQLiteCore/Internal/Deprecations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ extension PrimaryKeyedTable {
8585
}
8686

8787
// TODO: Support composite keys.
88-
extension PrimaryKeyedTable where TableColumns.PrimaryKeyColumn == TableColumn<Self, PrimaryKey> {
88+
extension PrimaryKeyedTable where TableColumns.PrimaryColumn == TableColumn<Self, PrimaryKey> {
8989
@available(
9090
*, deprecated, message: "Use a trailing closure, instead: 'Table.upsert { draft }'"
9191
)

Sources/StructuredQueriesSQLiteCore/JSONFunctions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ extension PrimaryKeyedTableDefinition where QueryValue: Codable {
126126
extension PrimaryKeyedTableDefinition
127127
where
128128
QueryValue: _OptionalProtocol & Codable,
129-
PrimaryKeyColumn == TableColumn<QueryValue, PrimaryKey>
129+
PrimaryColumn == TableColumn<QueryValue, PrimaryKey>
130130
{
131131
/// A JSON array representation of the aggregation of a table's columns.
132132
///

Tests/StructuredQueriesTests/NestedTests.swift

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ extension SnapshotTests {
5151
└──────────────────────────┘
5252
"""
5353
}
54+
assertQuery(
55+
Item.insert {
56+
$0.status.isOutOfStock
57+
} values: {
58+
true
59+
}
60+
) {
61+
"""
62+
INSERT INTO "items"
63+
("isOutOfStock")
64+
VALUES
65+
(1)
66+
"""
67+
}
68+
// TODO: Make work?
69+
// assertQuery(
70+
// Item.insert {
71+
// $0.status
72+
// } values: {
73+
// Status(isOutOfStock: true, isOnBackOrder: false)
74+
// }
75+
// )
5476
assertQuery(
5577
Item.all
5678
) {
@@ -69,6 +91,15 @@ extension SnapshotTests {
6991
│ isOnBackOrder: false │
7092
│ ) │
7193
│ ) │
94+
├──────────────────────────┤
95+
│ Item( │
96+
│ title: "", │
97+
│ quantity: 0, │
98+
│ status: Status( │
99+
│ isOutOfStock: true, │
100+
│ isOnBackOrder: false │
101+
│ ) │
102+
│ ) │
72103
└──────────────────────────┘
73104
"""
74105
}
@@ -110,7 +141,7 @@ extension SnapshotTests {
110141
SET "isOutOfStock" = 1, "isOnBackOrder" = 1
111142
"""
112143
}
113-
// FIXME: This should decode 'nil' but because all its fields have defaults it coalesces.
144+
// FIXME: These should decode 'nil' but because all its fields have defaults it coalesces.
114145
assertQuery(
115146
DefaultItem?(nil)
116147
) {
@@ -360,7 +391,7 @@ private struct Timestamps {
360391
var createdAt: Date
361392
var updatedAt: Date
362393
var deletedAt: Date?
363-
@Column(generated: .stored)
394+
@Column(generated: .virtual)
364395
let isDeleted: Bool
365396
}
366397

0 commit comments

Comments
 (0)