Skip to content

Commit 1fc1792

Browse files
doozMenStijn Willems
authored andcommitted
wip local dependencies for structured queries (#3)
1 parent 7e95230 commit 1fc1792

6 files changed

Lines changed: 64 additions & 160 deletions

File tree

.claude/settings.local.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(swift --version:*)",
5+
"Bash(~/.swiftly/bin/swiftly list:*)",
6+
"Bash(~/.swiftly/bin/swiftly use:*)"
7+
]
8+
}
9+
}

Package.resolved

Lines changed: 9 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.1
1+
// swift-tools-version: 6.2.1
22

33
import PackageDescription
44

@@ -25,12 +25,13 @@ let package = Package(
2525
],
2626
dependencies: [
2727
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
28-
.package(url: "https://github.com/groue/GRDB.swift", from: "7.6.0"),
28+
// NB: Fork synced with upstream v7.9.0
29+
.package(url: "https://github.com/doozMen/GRDB.swift", branch: "master"),
2930
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"),
3031
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"),
3132
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.9.0"),
32-
.package(url: "https://github.com/pointfreeco/swift-perception", from: "2.0.0"),
33-
.package(url: "https://github.com/pointfreeco/swift-sharing", from: "2.3.0"),
33+
// NB: Fork with Swift 6.3 fixes (uses doozMen/swift-perception)
34+
.package(url: "https://github.com/doozMen/swift-sharing", branch: "main"),
3435
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.4"),
3536
.package(
3637
url: "https://github.com/pointfreeco/swift-structured-queries",
@@ -51,7 +52,6 @@ let package = Package(
5152
.product(name: "GRDB", package: "GRDB.swift"),
5253
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
5354
.product(name: "OrderedCollections", package: "swift-collections"),
54-
.product(name: "Perception", package: "swift-perception"),
5555
.product(name: "Sharing", package: "swift-sharing"),
5656
.product(name: "StructuredQueriesSQLite", package: "swift-structured-queries"),
5757
.product(
@@ -103,7 +103,8 @@ for index in package.targets.indices {
103103

104104
#if !os(Windows)
105105
// Add the documentation compiler plugin if possible
106+
// NB: Use explicit type to avoid Swift 6.2.3 circular reference bug
106107
package.dependencies.append(
107-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
108+
Package.Dependency.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
108109
)
109110
#endif

Package@swift-6.0.swift

Lines changed: 0 additions & 89 deletions
This file was deleted.

Sources/SQLiteData/CloudKit/CloudKit+StructuredQueries.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291

292292
self.userModificationTime = other.userModificationTime
293293
for column in T.TableColumns.writableColumns {
294-
func open<Root, Value>(_ column: some WritableTableColumnExpression<Root, Value>) {
294+
func open<Value>(_ column: some WritableTableColumnExpression<T, Value>) {
295295
let key = column.name
296296
let keyPath = column.keyPath as! KeyPath<T, Value.QueryOutput>
297297
let didSet: Bool

Sources/SQLiteData/CloudKit/PrimaryKeyMigration.swift

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,18 @@
181181
newColumns.append(columns.primaryKey.name)
182182
}
183183
newColumns.append(contentsOf: tableInfo.map(\.name))
184-
convertedColumns.append(
185-
contentsOf: tableInfo.map { tableInfo -> QueryFragment in
186-
if tableInfo.name == primaryKey.name, tableInfo.isInt {
187-
return $backfillUUID(id: #sql("\(quote: tableInfo.name)"), table: tableName, salt: salt)
188-
.queryFragment
189-
} else if tableInfo.isInt,
190-
let foreignKey = foreignKeys.first(where: { $0.from == tableInfo.name })
191-
{
192-
return $backfillUUID(
193-
id: #sql("\(quote: foreignKey.from)"),
194-
table: foreignKey.table,
195-
salt: salt
196-
)
197-
.queryFragment
198-
} else {
199-
return QueryFragment(quote: tableInfo.name)
200-
}
201-
}
202-
)
184+
// NB: Swift 6.3-dev crashes on complex closures with #sql macro interpolation.
185+
// Extracted to helper function to work around compiler bug.
186+
for info in tableInfo {
187+
let fragment = convertTableInfoToQueryFragment(
188+
info,
189+
primaryKeyName: primaryKey.name,
190+
foreignKeys: foreignKeys,
191+
tableName: tableName,
192+
salt: salt
193+
)
194+
convertedColumns.append(fragment)
195+
}
203196

204197
try #sql(QueryFragment(stringLiteral: newSchema)).execute(db)
205198
try #sql(
@@ -225,6 +218,32 @@
225218
)
226219
.execute(db)
227220
}
221+
222+
// NB: Extracted from closure to work around Swift 6.3-dev compiler crash.
223+
// The compiler crashes on complex closures mixing #sql macro interpolation with nested closures.
224+
private static func convertTableInfoToQueryFragment(
225+
_ tableInfo: PragmaTableInfo<Self>,
226+
primaryKeyName: String,
227+
foreignKeys: [PragmaForeignKeyList<Self>],
228+
tableName: String,
229+
salt: String
230+
) -> QueryFragment {
231+
if tableInfo.name == primaryKeyName, tableInfo.isInt {
232+
return $backfillUUID(id: #sql("\(quote: tableInfo.name)"), table: tableName, salt: salt)
233+
.queryFragment
234+
} else if tableInfo.isInt,
235+
let foreignKey = foreignKeys.first(where: { $0.from == tableInfo.name })
236+
{
237+
return $backfillUUID(
238+
id: #sql("\(quote: foreignKey.from)"),
239+
table: foreignKey.table,
240+
salt: salt
241+
)
242+
.queryFragment
243+
} else {
244+
return QueryFragment(quote: tableInfo.name)
245+
}
246+
}
228247
}
229248

230249
extension StringProtocol {

0 commit comments

Comments
 (0)