Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.9.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.5.0"),
.package(url: "https://github.com/pointfreeco/swift-sharing", from: "2.3.0"),
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.1.1"),
// .package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.1.1"),
.package(url: "https://github.com/pointfreeco/swift-structured-queries", branch: "seeds"),
],
targets: [
.target(
Expand Down
6 changes: 3 additions & 3 deletions SharingGRDB.xcworkspace/xcshareddata/swiftpm/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 2 additions & 22 deletions Sources/StructuredQueriesGRDBCore/Seed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,8 @@ extension Database {
@InsertValuesBuilder<any StructuredQueriesCore.Table>
_ build: () -> [any StructuredQueriesCore.Table]
) throws {
var seeds = build()
while !seeds.isEmpty {
guard let first = seeds.first else { break }
let firstType = type(of: first)

if let firstType = firstType as? any TableDraft.Type {
func insertBatch<T: TableDraft>(_: T.Type) throws {
let batch = Array(seeds.lazy.prefix { $0 is T }.compactMap { $0 as? T })
defer { seeds.removeFirst(batch.count) }
try T.PrimaryTable.insert(batch).execute(self)
}

try insertBatch(firstType)
} else {
func insertBatch<T: StructuredQueriesCore.Table>(_: T.Type) throws {
let batch = Array(seeds.lazy.prefix { $0 is T }.compactMap { $0 as? T })
defer { seeds.removeFirst(batch.count) }
try T.insert(batch).execute(self)
}

try insertBatch(firstType)
}
for insert in Seeds(build) {
try insert.execute(self)
}
}
}