#![cfg_attr(
not(all(
feature = "kv",
feature = "locks",
feature = "jobs",
feature = "sql",
feature = "blobs",
feature = "records",
feature = "metrics",
feature = "search",
feature = "backup",
feature = "replication",
feature = "wire"
)),
allow(dead_code, unused_imports)
)]
mod apply;
mod capture;
mod checkpoint;
mod config;
mod connection;
mod constraint;
#[cfg(test)]
pub(crate) mod division;
mod file;
mod given;
mod group;
mod memory;
mod migrate;
mod mutex;
mod pages;
mod prefix;
mod readers;
mod settle;
mod vacuum;
use std::cell::RefCell;
use std::fmt;
use std::ops::Deref;
use rusqlite::Connection;
pub(crate) use apply::{Applier, checkpoint_away};
pub(crate) use capture::{Commit, Observe, Position, answering, each_commit_past, own_work, wal_end, wal_of};
pub use config::Durability;
pub(crate) use config::{CatchUp, Config, GroupLimits};
#[cfg(feature = "kv")]
pub(crate) use connection::read_file;
pub(crate) use connection::{
copy, execute_cached, given_sql_error, query_cached, quote_ident, read_copy, sql_error, unheard_warnings,
};
pub(crate) use constraint::named as name_constraint;
#[cfg(feature = "replication")]
pub(crate) use file::Switch;
pub(crate) use file::{Begun, File, Mark, a_copy_takes_no_transaction, in_a_transaction, refuse_when_rolled_back};
pub(crate) use given::given;
#[cfg(test)]
pub(crate) use memory::used as memory_used;
pub(crate) use migrate::Migration;
pub(crate) use mutex::{give as give_mutexes, given as mutexes_given};
pub(crate) use pages::{Chunk, Pages, Snapshot};
pub(crate) use prefix::{TextBytes, prefix_end};
pub(crate) use readers::Readers;
pub(crate) use settle::{Left, Settle, Settlers};
pub(crate) struct Tx<'a> {
connection: &'a Connection,
committed: &'a Committed,
settlers: &'a Settlers,
}
impl<'a> Tx<'a> {
pub(crate) fn new(connection: &'a Connection, committed: &'a Committed, settlers: &'a Settlers) -> Self {
Self { connection, committed, settlers }
}
pub(crate) fn settle(&self, left: Left) -> crate::Result<()> {
self.settlers.run(self, left)
}
#[cfg(any(feature = "channels", feature = "records"))]
pub(crate) fn after_commit(&self, hook: Box<dyn FnOnce()>) {
self.committed.push(hook);
}
pub(crate) fn committed(&self) -> &Committed {
self.committed
}
}
#[derive(Default)]
pub(crate) struct Committed(RefCell<Vec<Box<dyn FnOnce()>>>);
impl Committed {
#[cfg(any(feature = "channels", feature = "records"))]
pub(crate) fn push(&self, hook: Box<dyn FnOnce()>) {
self.0.borrow_mut().push(hook);
}
#[cfg(feature = "channels")]
pub(crate) fn take(&self) -> Committed {
Committed(RefCell::new(std::mem::take(&mut *self.0.borrow_mut())))
}
pub(crate) fn mark(&self) -> usize {
self.0.borrow().len()
}
pub(crate) fn take_back(&self, mark: usize) {
self.0.borrow_mut().truncate(mark);
}
#[cfg(feature = "channels")]
pub(crate) fn append(&self, earlier: Committed) {
let mut hooks = earlier.0.into_inner();
hooks.append(&mut self.0.borrow_mut());
*self.0.borrow_mut() = hooks;
}
pub(crate) fn run(&self) {
let hooks = std::mem::take(&mut *self.0.borrow_mut());
for hook in hooks {
hook();
}
}
}
impl Deref for Tx<'_> {
type Target = Connection;
fn deref(&self) -> &Connection {
self.connection
}
}
impl fmt::Debug for Tx<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Tx")
}
}