rusqlite / rusqlite

Ergonomic bindings to SQLite for Rust
MIT License
3.13k stars 358 forks source link

Add safe exposure of `sqlite3_wal_hook` #1570

Open vincent-herlemont opened 2 weeks ago

vincent-herlemont commented 2 weeks ago

I'd like to propose adding support for the sqlite3_wal_hook in rusqlite, inspired by the existing commit_hook and rollback_hook etc. This would allow users to monitor Write-Ahead Logging (WAL) events via a safe Rust interface.

Proposed Changes:

  1. Feature Flag:
    • Introduce a feature flag (e.g., "wal_hook" or added with the "hooks" feature ) to keep this functionality optional.
  2. Safe Callback Interface:
    • Similar to commit_hook, provide a safe Rust closure interface for the WAL hook, ensuring it adheres to Rust's borrowing and ownership rules.
    • Avoid direct exposure of raw pointers, offering a safe abstraction instead.
gwenn commented 2 weeks ago

You should be able to reuse the existing hooks feature because sqlite3_wal_hook was introduced before 3.14 (https://github.com/rusqlite/rusqlite/blob/95680270eca6f405fb51f5fbe6a214aac5fdce58/libsqlite3-sys/sqlite3/sqlite3ext.h#L233).