Split an app into local Swift package modules, then add a separate database module built on SQLiteData. Covers the @Table macro and its Draft type compared with SwiftData, plus defaultDatabase, DatabaseMigrator and raw SQL migrations with the #sql macro.
Links SQLiteData Swift Structured Queries GRDB.swift Swift Package Manager SwiftData Code The episode model, declared with the @Table macro: import Foundation import SQLiteData @Table public struct Episode: Hashable, Identifiable { public let id: Int // ...remaining non-optional properties } Bootstrapping the database with a migration: import SQLiteData public func appDatabase() throws -> any DatabaseWriter { let database = try SQLiteData.defaultDatabase() var migrator = DatabaseMigrator() #if DEBUG migrator.eraseDatabaseOnSchemaChange = true #endif migrator.registerMigration("create episodes") { db in try #sql( """ CREATE TABLE "episodes" ( "id" INTEGER PRIMARY KEY -- ...remaining columns ) STRICT """ ) .execute(db) } try migrator.migrate(database) return database }