Skip to content

Commit 087cb3e

Browse files
committed
Leverage upstream database seeding helper
This logic is being incorporated directly into StructuredQueries.
1 parent 16c6f5e commit 087cb3e

3 files changed

Lines changed: 7 additions & 26 deletions

File tree

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ let package = Package(
3333
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.9.0"),
3434
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.5.0"),
3535
.package(url: "https://github.com/pointfreeco/swift-sharing", from: "2.3.0"),
36-
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.1.1"),
36+
// .package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.1.1"),
37+
.package(url: "https://github.com/pointfreeco/swift-structured-queries", branch: "seeds"),
3738
],
3839
targets: [
3940
.target(

SharingGRDB.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

Sources/StructuredQueriesGRDBCore/Seed.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,8 @@ extension Database {
5353
@InsertValuesBuilder<any StructuredQueriesCore.Table>
5454
_ build: () -> [any StructuredQueriesCore.Table]
5555
) throws {
56-
var seeds = build()
57-
while !seeds.isEmpty {
58-
guard let first = seeds.first else { break }
59-
let firstType = type(of: first)
60-
61-
if let firstType = firstType as? any TableDraft.Type {
62-
func insertBatch<T: TableDraft>(_: T.Type) throws {
63-
let batch = Array(seeds.lazy.prefix { $0 is T }.compactMap { $0 as? T })
64-
defer { seeds.removeFirst(batch.count) }
65-
try T.PrimaryTable.insert(batch).execute(self)
66-
}
67-
68-
try insertBatch(firstType)
69-
} else {
70-
func insertBatch<T: StructuredQueriesCore.Table>(_: T.Type) throws {
71-
let batch = Array(seeds.lazy.prefix { $0 is T }.compactMap { $0 as? T })
72-
defer { seeds.removeFirst(batch.count) }
73-
try T.insert(batch).execute(self)
74-
}
75-
76-
try insertBatch(firstType)
77-
}
56+
for insert in Seeds(build) {
57+
try insert.execute(self)
7858
}
7959
}
8060
}

0 commit comments

Comments
 (0)