sqlite total_changes()

I’m currently working on an envelope feature where I need to know if the underlying sqlite database has been changed and store the updated bytes locally if it has.

I initially checked for that by simply diffing the before and after bytes of the database but, not surprisingly, that is not very inefficient for very big files.

Turns out sqlite has a nice feature that reliably tells me if the database has been updated: total_changes().

These functions return the total number of rows inserted, modified or deleted by all INSERT, UPDATE or DELETE statements completed since the database connection was opened, including those executed as part of trigger programs.

A lot better than a byte-to-byte diff! I just need

pub(crate) async fn total_changes(&self) -> Result<i64> {
    sqlx::query_scalar("SELECT total_changes()")
        .fetch_one(&self.db)
        .await
        .context("failed to read total_changes")
}