Skip to content

Add combine support (change listener) #1147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ursusursus opened this issue Jul 25, 2022 · 4 comments
Open

Add combine support (change listener) #1147

ursusursus opened this issue Jul 25, 2022 · 4 comments

Comments

@ursusursus
Copy link

Reactive database is needed in reactive architecture.
I don't see any Combine bindings provided. Is there some sort of data change listener I could adapt myself to Combine?

@groue
Copy link

groue commented Jul 25, 2022

SQLite is certainly capable of database observation. Check out GRDB's ValueObservation for ready-made Combine publishers.

// Connect to the database
let dbQueue = ... 

// Define an observation for the tracked value(s).
let observation = ValueObservation.tracking { db in
    // Fetch anything you want, from as many tables as needed
    return ...
}

// Turn the observation into a Combine publisher
let publisher = observation.publisher(in: dbQueue)

// Be notified of all changes, until the subscription is cancelled.
let cancellable = publisher.sink(
    receiveCompletion: { completion in ... },
    receiveValue: { value in
        print("Fresh database value: \(value)")
    })

@nathanfallet nathanfallet changed the title Combine support? Any data change listener I could wrap? Add combine support (change listener) Jul 25, 2022
@jberkel
Copy link
Collaborator

jberkel commented Jul 26, 2022

@ursusursus Can you explain a bit more what you're after?

@ursusursus
Copy link
Author

@jberkel I basically want observable queries, that is to get the current result of the query as first emit, and then subsequent emits as the underlying data changes. In other words, query over time.

@jberkel
Copy link
Collaborator

jberkel commented Jul 26, 2022

Alright. See #686 for a related discussion, which unfortunately fizzled out (there was a user who mentioned opening a PR, but nothing materialized).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants