INNER CODE UNIT · Rust

with_write_scope

aannoo/hcom · src/db/mod.rs:166

    pub fn with_write_scope<T>(&self, f: impl FnOnce() -> Result<T>) -> Result<T> {
        let own_transaction = self.conn.is_autocommit();
        let (begin, commit, rollback) = if own_transaction {
            ("BEGIN IMMEDIATE", "COMMIT", "ROLLBACK")
        } else {
            (
                "SAVEPOINT hcom_write_scope",
                "RELEASE hcom_write_scope",
                "ROLLBACK TO hcom_write_scope; RELEASE hcom_write_scope",
            )
        };
        self.conn.execute_batch(begin)?;
        let result = f().and_then(|value| {
            self.conn.execute_batch(commit)?;
            Ok(value)
        });
        if result.is_err() {
            let _ = self.conn.execute_batch(rollback);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…