DatabaseWriter
A type that writes into an SQLite database.
protocol DatabaseWriter : DatabaseReader
Browse conforming typesDo not declare new conformances to DatabaseWriter
. Only the built-in conforming types are valid.
A database writer creates one single SQLite connection dedicated to database updates. All updates are executed in a serial writer dispatch queue.
Read accesses are defined by DatabaseReader
, the protocol all database writers conform to.
See Concurrency for more information about the behavior of conforming types in a multithreaded application.
Writing into the Database
func write<T>((Database) throws -> T
) throws -> T Executes database operations, and returns their result after they have finished executing.
func write<T>(@escaping (Database) throws -> T
) async throws -> T Executes database operations, and returns their result after they have finished executing.
writePublisher(receiveOn:updates:)
writePublisher(receiveOn:updates:thenRead:)
func writeWithoutTransaction<T>((Database) throws -> T
) rethrows -> T Executes database operations, and returns their result after they have finished executing.
func writeWithoutTransaction<T>(@escaping (Database) throws -> T
) async throws -> T Executes database operations, and returns their result after they have finished executing.
func asyncWrite<T>(@escaping (Database) throws -> T, completion: @escaping (Database, Result<T, Error>) -> Void
) Schedules database operations for execution, and returns immediately.
func asyncWriteWithoutTransaction(@escaping (Database) -> Void
) Schedules database operations for execution, and returns immediately.
Exclusive Access to the Database
func barrierWriteWithoutTransaction<T>((Database) throws -> T
) throws -> T Executes database operations, and returns their result after they have finished executing.
func barrierWriteWithoutTransaction<T>(@escaping (Database) throws -> T
) async throws -> T Executes database operations, and returns their result after they have finished executing.
func asyncBarrierWriteWithoutTransaction(@escaping (Result<Database, Error>) -> Void
) Schedules database operations for execution, and returns immediately.
Reading from the Latest Committed Database State
func spawnConcurrentRead(@escaping (Result<Database, Error>) -> Void
) Schedules read-only database operations for execution.
Unsafe Methods
func unsafeReentrantWrite<T>((Database) throws -> T
) rethrows -> T Executes database operations, and returns their result after they have finished executing.
Observing Database Transactions
func add(transactionObserver: some TransactionObserver, extent: Database.TransactionObservationExtent
) Adds a transaction observer to the writer connection, so that it gets notified of database changes and transactions.
func remove(transactionObserver: some TransactionObserver
) Removes a transaction observer from the writer connection.
Other Database Operations
func erase(
) throws Erase the database: delete all content, drop all tables, etc.
func erase(
) async throws Erase the database: delete all content, drop all tables, etc.
func vacuum(
) throws Rebuilds the database file, repacking it into a minimal amount of disk space.
func vacuum(
) async throws Rebuilds the database file, repacking it into a minimal amount of disk space.
func vacuum(into: String
) throws Creates a new database file at the specified path with a minimum amount of disk space.
func vacuum(into: String
) async throws Creates a new database file at the specified path with a minimum amount of disk space.
Supporting Types
class AnyDatabaseWriter
A type-erased database writer.