DatabaseSnapshot
public class DatabaseSnapshot : DatabaseReader
A DatabaseSnapshot sees an unchanging database content, as it existed at the moment it was created.
See DatabasePool.makeSnapshot()
For more information, read about snapshot isolation
at https://sqlite.org/isolation.html
-
The database configuration
Declaration
Swift
public var configuration: Configuration { get }
-
Synchronously executes a read-only block that takes a database connection, and returns its result.
let players = try snapshot.read { db in try Player.fetchAll(...) }
Throws
The error thrown by the block.Declaration
Swift
public func read<T>(_ block: (Database) throws -> T) rethrows -> T
Parameters
block
A block that accesses the database.
-
Asynchronously executes a read-only block in a protected dispatch queue.
let players = try snapshot.asyncRead { result in do { let db = try result.get() let count = try Player.fetchCount(db) } catch { // Handle error } }
Declaration
Swift
public func asyncRead(_ block: @escaping (Result<Database, Error>) -> Void)
Parameters
block
A block that accesses the database.
-
Declaration
Swift
public func add(function: DatabaseFunction)
-
Declaration
Swift
public func remove(function: DatabaseFunction)
-
Declaration
Swift
public func add(collation: DatabaseCollation)
-
Declaration
Swift
public func remove(collation: DatabaseCollation)
-
Declaration
Swift
public func add<Reducer: ValueReducer>( observation: ValueObservation<Reducer>, onError: @escaping (Error) -> Void, onChange: @escaping (Reducer.Value) -> Void) -> TransactionObserver
-
Declaration
Swift
public func remove(transactionObserver: TransactionObserver)