/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

use crate::{Database, Transaction};
use anyhow::Result;

pub trait DatabaseReturnExt: Database {
    fn transaction_ret<T>(
        &self,
        mut t: impl FnMut(&mut dyn Transaction) -> Result<T>,
    ) -> Result<T> {
        let mut ret = None;
        self.transaction(&mut |x| {
            ret = Some(t(x)?);
            Ok(())
        })?;
        Ok(ret.unwrap())
    }
}
impl<D: Database + ?Sized> DatabaseReturnExt for D {}
