DatabaseWriter
protocol DatabaseWriter : DatabaseReader
Combine extensions on DatabaseWriter.
-
Returns a Publisher that asynchronously writes into the database.
// AnyPublisher<Int, Error> let newPlayerCount = dbQueue.writePublisher { db -> Int in try Player(...).insert(db) return try Player.fetchCount(db) }Its value and completion are emitted on the main dispatch queue.
Declaration
Swift
public func writePublisher<Output>( updates: @escaping (Database) throws -> Output) -> AnyPublisher<Output, Error>Parameters
updatesA closure which writes in the database.
-
Returns a Publisher that asynchronously writes into the database.
// AnyPublisher<Int, Error> let newPlayerCount = dbQueue.writePublisher( receiveOn: DispatchQueue.global(), updates: { db -> Int in try Player(...).insert(db) return try Player.fetchCount(db) })Its value and completion are emitted on
scheduler.Declaration
Swift
public func writePublisher<S, Output>( receiveOn scheduler: S, updates: @escaping (Database) throws -> Output) -> AnyPublisher<Output, Error> where S : SchedulerParameters
schedulerA Scheduler.
updatesA closure which writes in the database.
-
Returns a Publisher that asynchronously writes into the database.
// AnyPublisher<Int, Error> let newPlayerCount = dbQueue.writePublisher( updates: { db in try Player(...).insert(db) } thenRead: { db, _ in try Player.fetchCount(db) })Its value and completion are emitted on the main dispatch queue.
Declaration
Swift
public func writePublisher<T, Output>( updates: @escaping (Database) throws -> T, thenRead value: @escaping (Database, T) throws -> Output) -> AnyPublisher<Output, Error>Parameters
updatesA closure which writes in the database.
valueA closure which reads from the database.
-
Returns a Publisher that asynchronously writes into the database.
// AnyPublisher<Int, Error> let newPlayerCount = dbQueue.writePublisher( receiveOn: DispatchQueue.global(), updates: { db in try Player(...).insert(db) } thenRead: { db, _ in try Player.fetchCount(db) })Its value and completion are emitted on
scheduler.Declaration
Swift
public func writePublisher<S, T, Output>( receiveOn scheduler: S, updates: @escaping (Database) throws -> T, thenRead value: @escaping (Database, T) throws -> Output) -> AnyPublisher<Output, Error> where S : SchedulerParameters
schedulerA Scheduler.
updatesA closure which writes in the database.
valueA closure which reads from the database.
View on GitHub
Install in Dash
DatabaseWriter Extension Reference