From sqlitedata-swift
Use when looking up exact API signatures, init parameters, type details, or advanced patterns (FTS5, custom functions, seeding) — covers all public types, property wrappers, SyncEngine methods, and re-exported types. NOT for usage patterns (use core) or troubleshooting (use diag)
How this skill is triggered — by the user, by Claude, or both
Slash command
/sqlitedata-swift:sqd-refThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Complete API reference for all public types and methods in SQLiteData.
Complete API reference for all public types and methods in SQLiteData.
From GRDB: Configuration, Database, DatabaseError, DatabaseMigrator, DatabasePool, DatabaseQueue, DatabaseReader, DatabaseWriter, ValueObservationScheduler
From StructuredQueriesSQLite: @Table, @Column, @Selection, @ForeignKey, #sql, #bind
From Dependencies: @Dependency, prepareDependencies, DependencyValues
For usage patterns of these types, see /skill sqd-core.
Fetches a collection of rows from SQLite with reactive observation.
@dynamicMemberLookup
@propertyWrapper
public struct FetchAll<Element: Sendable>: Sendable, DynamicProperty
Initializers:
// Fetch all rows from table (default order)
init(wrappedValue: [Element] = [], database: (any DatabaseReader)? = nil)
where Element: Table, Element.QueryOutput == Element
// From a SelectStatement (query builder)
init<S: SelectStatement>(wrappedValue: [Element] = [], _ statement: S,
database: (any DatabaseReader)? = nil)
// From any Statement<V>
init<V: QueryRepresentable>(wrappedValue: [Element] = [],
_ statement: some Statement<V>, database: (any DatabaseReader)? = nil)
// With animation (iOS 17+)
init(..., animation: Animation)
// With custom scheduler
init(..., scheduler: some ValueObservationScheduler & Hashable)
Properties:
var wrappedValue: [Element] // The fetched data
var projectedValue: Self // Access to wrapper state ($items)
var loadError: (any Error)? // Last error
var isLoading: Bool // Loading state
var publisher: some Publisher<[Element], Never> // Combine publisher
var sharedReader: SharedReader<[Element]> // Underlying reader
Methods:
func load() async throws // Reload current query
func load<S>(_ statement: S, database:) async throws -> FetchSubscription // Load new query
Fetches a single value (aggregate, first row, etc.) with reactive observation.
@dynamicMemberLookup
@propertyWrapper
public struct FetchOne<Value: Sendable>: Sendable, DynamicProperty
Same initializer patterns as FetchAll but for single values. Always requires a default wrappedValue.
Fetches custom data via FetchKeyRequest for multi-query transactions.
@dynamicMemberLookup
@propertyWrapper
public struct Fetch<Value: Sendable>: Sendable, DynamicProperty
Initializers:
// From FetchKeyRequest
init(wrappedValue: Value, _ request: some FetchKeyRequest<Value>,
database: (any DatabaseReader)? = nil)
// With animation (iOS 17+)
init(wrappedValue: Value, _ request: some FetchKeyRequest<Value>,
database: (any DatabaseReader)? = nil, animation: Animation)
// With custom scheduler
init(wrappedValue: Value, _ request: some FetchKeyRequest<Value>,
database: (any DatabaseReader)? = nil, scheduler: some ValueObservationScheduler & Hashable)
Methods:
func load(_ request: some FetchKeyRequest<Value>, database:) async throws -> FetchSubscription
public protocol FetchKeyRequest<Value>: Hashable, Sendable {
associatedtype Value
func fetch(_ db: Database) throws -> Value
}
public struct FetchSubscription: Sendable {
public var task: Void { get async throws }
public func cancel()
}
public func defaultDatabase(
path: String? = nil,
configuration: Configuration = Configuration()
) throws -> any DatabaseWriter
Context-aware:
DatabasePool in Application SupportDatabasePool at temporary pathextension DependencyValues {
public var defaultDatabase: any DatabaseWriter { get set }
// CloudKit only:
public var defaultSyncEngine: SyncEngine { get set }
}
Wraps Apple's CKSyncEngine. For the underlying CloudKit sharing model and CKRecord.ID mapping, see /skill sqd-sharing.
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
public final class SyncEngine: Observable, Sendable
public convenience init<each T1: PrimaryKeyedTable, each T2: PrimaryKeyedTable>(
for database: any DatabaseWriter,
tables: repeat (each T1).Type, // Shareable tables
privateTables: repeat (each T2).Type, // Private-only tables
containerIdentifier: String? = nil, // CloudKit container
defaultZone: CKRecordZone = .defaultZone,
startImmediately: Bool? = nil, // Default: true
delegate: (any SyncEngineDelegate)? = nil,
logger: Logger = .disabled
) throws
public var isRunning: Bool { get }
public var isSendingChanges: Bool { get }
public var isFetchingChanges: Bool { get }
public var isSynchronizing: Bool { get } // isSending || isFetching
public func start() async throws
public func stop()
public func fetchChanges(_ options: CKSyncEngine.FetchChangesOptions) async throws
public func sendChanges(_ options: CKSyncEngine.SendChangesOptions) async throws
public func syncChanges(
fetchOptions: CKSyncEngine.FetchChangesOptions,
sendOptions: CKSyncEngine.SendChangesOptions
) async throws
public func syncChanges() async throws // Convenience (default options)
public func deleteLocalData() async throws
For CloudKit's sharing model (CKShare, participants, permissions, UICloudSharingController): /skill sqd-sharing
public func share<T: PrimaryKeyedTable>(
record: T,
configure: @Sendable (CKShare) -> Void
) async throws -> SharedRecord
public func unshare<T: PrimaryKeyedTable>(record: T) async throws
public func acceptShare(metadata: CKShare.Metadata) async throws
public func attachMetadatabase(containerIdentifier: String? = nil) throws
// Called on Database instance in prepareDatabase
public static func migratePrimaryKeys<each T: PrimaryKeyedTable>(
_ db: Database,
tables: repeat (each T).Type,
dropUniqueConstraints: Bool = false,
uuid: (any ScalarDatabaseFunction<(), UUID>)? = nil
) throws
public static let writePermissionError: String
// "co.pointfree.SQLiteData.CloudKit.write-permission-error"
public static let invalidRecordNameError: String
// "co.pointfree.SQLiteData.CloudKit.invalid-record-name-error"
// SQL expression (for triggers):
public static var isSynchronizing: Bool // Swift property
public static var $isSynchronizing // SQL expression for use in #sql / triggers
public protocol SyncEngineDelegate: AnyObject, Sendable {
func syncEngine(
_ syncEngine: SyncEngine,
accountChanged changeType: CKSyncEngine.Event.AccountChange.ChangeType
) async
}
Full struct definition and joining patterns: see /skill sqd-cloudkit §6.
Key lookup types:
SyncMetadata.ID // Composite key: recordPrimaryKey + recordType
SyncMetadata.ParentID // Parent record reference
All PrimaryKeyedTable types have:
extension PrimaryKeyedTableDefinition {
var syncMetadataID: SyncMetadata.ID { get }
}
Contains the CKShare returned from SyncEngine.share(). The id is a CKRecord.ID (see /skill sqd-sharing).
public struct SharedRecord: Hashable, Identifiable, Sendable {
public let share: CKShare
public var id: CKRecord.ID { share.recordID }
}
For custom identifier types (non-UUID):
public protocol IdentifierStringConvertible {
var identifierString: String { get }
init?(identifierString: String)
}
UUID conforms by default.
public func assertQuery<V: QueryRepresentable, S: Statement<V>>(
includeSQL: Bool = false,
_ query: S,
database: (any DatabaseWriter)? = nil,
sql: (() -> String)? = nil,
results: (() -> String)? = nil,
// + source location params
)
Usage:
@Test
func queryResults() throws {
try assertQuery(
Item.order(by: \.title),
results: {
"""
┌─────────────────────┐
│ "Buy groceries" │
│ "Call accountant" │
└─────────────────────┘
"""
}
)
}
| Package | Version | Purpose |
|---|---|---|
| GRDB.swift | 7.6.0+ | SQLite wrapper |
| swift-structured-queries | 0.31.0+ | Type-safe SQL builder |
| swift-sharing | 2.3.0+ | SharedReader observation |
| swift-dependencies | 1.9.0+ | Dependency injection |
| swift-perception | 2.0.0+ | Observation backport |
| swift-collections | — | OrderedCollections |
| swift-concurrency-extras | — | Async utilities |
| swift-tagged | 0.10.0 | Tagged types (optional) |
@DatabaseFunction
nonisolated func createDefaultList() {
Task {
@Dependency(\.defaultDatabase) var database
try await database.write { db in
try List.insert { List.Draft(title: "Personal") }.execute(db)
}
}
}
// Register in prepareDatabase:
configuration.prepareDatabase { db in
db.add(function: $createDefaultList)
}
#if DEBUG
extension DatabaseWriter {
func seedSampleData() throws {
try write { db in
try db.seed {
Item(id: uuid(), title: "Groceries", listID: listIDs[0])
Item(id: uuid(), title: "Haircut", listID: listIDs[0])
}
}
}
}
#endif
extension Updates<Reminder> {
mutating func toggleStatus() {
self.status = Case(self.status)
.when(#bind(.incomplete), then: #bind(.completing))
.else(#bind(.incomplete))
}
}
@Table
struct ReminderText: FTS5 {
let rowid: Int
let title: String
let notes: String
let tags: String
}
Schema: CREATE VIRTUAL TABLE "reminderTexts" USING fts5("title", "notes", "tags", tokenize = 'trigram')
Keep FTS in sync via triggers on the source table.
npx claudepluginhub sitapix/sqlitedata-swift-skills --plugin sqlitedata-swiftSearches MemPalace before answering questions about past work, people, projects, or prior decisions. Returns verbatim stored content instead of guessing from model memory.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Implements vector databases with Pinecone, Weaviate, Qdrant, Milvus, pgvector for semantic search, RAG, recommendations, and similarity systems. Optimizes embeddings, indexing, and hybrid search.