coven/builder_before_commit.rs
1//! The app's before-commit function on the builder (E1).
2
3use super::*;
4
5/// The app's before-commit function, as the builder keeps it.
6pub(super) type BeforeCommit = dyn Fn(&CommitSql<'_>) -> Result<(), DbError> + Send + Sync;
7
8impl CovenBuilder {
9 /// The app's before-commit function (ยง9.4): coven runs it last in each
10 /// transaction that changes the app's rows, so the app stores what its
11 /// own rules compute from them in the same transaction. A local write, a
12 /// bulk write, an applied slot, a snapshot load and a migration as the
13 /// store opens each run it once, after every other change of the
14 /// transaction; coven's own transactions, such as one that pins a file,
15 /// don't. It reads any table app SQL reads and writes device-local
16 /// tables only: a statement that would write a synced table fails with
17 /// `SyncedTableBeforeCommit`. An error, or a statement of it that
18 /// failed, fails the transaction: a write returns the error, an applied
19 /// slot or a load doesn't commit, the pass reports the error and the next
20 /// pass tries again, and a migration fails the open. Without one,
21 /// nothing runs.
22 pub fn before_commit<F>(mut self, function: F) -> Self
23 where
24 F: Fn(&CommitSql<'_>) -> Result<(), DbError> + Send + Sync + 'static,
25 {
26 self.before_commit = Some(Arc::new(function));
27 self
28 }
29}