Skip to content
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

Explicit change notifications #1460

Merged
merged 18 commits into from Nov 26, 2023
Merged

Explicit change notifications #1460

merged 18 commits into from Nov 26, 2023

Conversation

groue
Copy link
Owner

@groue groue commented Nov 25, 2023

This pull request addresses #1457 and adds a new API that helps applications deal with database changes that are not automatically detected by GRDB.

As a reminder, the changes that are not automatically detected are:

  • Changes performed by external database connections.
  • Changes performed by SQLite statements that are not both compiled and executed through GRDB APIs.
  • Changes to the database schema, changes to internal system tables such as sqlite_master.
  • Changes to WITHOUT ROWID tables.
  • The deletion of duplicate rows triggered by ON CONFLICT REPLACE clauses (this last exception might change in a future release of SQLite).

Those changes are still undetected, but applications can explicitly notify them when appropriate, and trigger database observation tools (ValueObservation, DatabaseRegionObservation, and generally speaking all interested TransactionObserver):

try dbQueue.write { db in
    // Notify observers that some changes were performed in the database
    try db.notifyChanges(in: .fullDatabase)

    // Notify observers that some changes were performed in the player table
    try db.notifyChanges(in: Player.all())

    // Equivalent alternative
    try db.notifyChanges(in: Table("player"))
}

@groue groue merged commit 54357e4 into development Nov 26, 2023
22 checks passed
@groue groue deleted the dev/notify-changes branch November 26, 2023 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant