Generate a SQLite persistence layer using GRDB.swift with actor-based concurrency: database actor, schema migrations, record types, and query helpers. Invoke with entity names, fields, and relationship definitions.
Generate a production-grade SQLite persistence layer using GRDB.swift with actor isolation, WAL mode, and structured migrations.
$ARGUMENTS should include:
Example: files(id:ULID path:String contentHash:String? size:Int64 createdAt:Date) entities(id:ULID name:String kind:EntityKind) relationships(subjectId:ULID predicate:String objectId:ULID confidence:Double)
Package.swift to verify GRDB.swift is listed as a dependency.Sources/{PROJECT_NAME}/Database/ exists beyond .gitkeep.Sources/{PROJECT_NAME}/Core/Types.swift for existing domain types
that map to database records.Create Sources/{PROJECT_NAME}/Database/DatabaseManager.swift:
actor DatabaseManager with a DatabaseWriter (GRDB).init(path: URL) creating/opening the database with WAL mode.static let shared singleton pattern or dependency injection.Create Sources/{PROJECT_NAME}/Database/Migrations.swift:
struct DatabaseMigrator with static migrate(_ db: DatabaseWriter).DatabaseMigrator with named migrations ("v1.0-initial").For each entity, create Sources/{PROJECT_NAME}/Database/Records/{Entity}Record.swift:
struct {Entity}Record: Codable, FetchableRecord, PersistableRecord conformance.static let databaseTableName = "{entities}" (pluralized, snake_case).enum Columns: String, ColumnExpression.init(row: Row) and encoding/decoding.Create Sources/{PROJECT_NAME}/Database/Queries/{Entity}Queries.swift:
DatabaseManager with typed query methods:
func insert(_ record: {Entity}Record) async throwsfunc fetch(id: String) async throws -> {Entity}Record?func fetchAll(filter: {Entity}Filter?) async throws -> [{Entity}Record]func update(_ record: {Entity}Record) async throwsfunc delete(id: String) async throwsValueObservation where appropriate.If the project requires an immutable decision/event log:
Create Sources/{PROJECT_NAME}/Database/AuditLog.swift:
struct AuditEntry: Codable with timestamp, action, details, confidence.func append(_ entry: AuditEntry) throws — file-append, never modify.AppConfiguration.Update Sources/{PROJECT_NAME}/Config/Configuration.swift:
databasePath: URL field (default: dataDirectory/graph.db).walMode: Bool field (default: true).foreignKeys: Bool field (default: true).Database/ already has files beyond .gitkeep, read them and only add missing components.Core/Types.swift types, use those types
rather than creating duplicates — add FetchableRecord conformance via extensions.Package.swift, warn that /scaffold-package should add it./scaffold-package (for Package.swift and module structure)/test-harness (for database test fixtures), /daemon-service (for persistence)