DatabaseWriter

extension DatabaseWriter

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

    updates

    A 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 : Scheduler

    Parameters

    scheduler

    A Scheduler.

    updates

    A 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

    updates

    A closure which writes in the database.

    value

    A 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 : Scheduler

    Parameters

    scheduler

    A Scheduler.

    updates

    A closure which writes in the database.

    value

    A closure which reads from the database.