datasources-memory 0.1.65

In-memory datasource provider
Documentation
use crate::connection::{MemoryConnection, MemoryState};
use async_trait::async_trait;
use datasources::{Connection, IsolationLevel, Result, Transaction};
use std::sync::Arc;

pub struct MemoryTransaction {
    pub(crate) state: Arc<MemoryState>,
    pub(crate) isolation: IsolationLevel,
}

impl MemoryTransaction {
    pub(crate) fn new(state: Arc<MemoryState>, isolation: IsolationLevel) -> Self {
        Self { state, isolation }
    }
}

#[async_trait]
impl Transaction for MemoryTransaction {
    fn connection(&self) -> Arc<dyn Connection> {
        Arc::new(MemoryConnection {
            state: Arc::clone(&self.state),
        })
    }

    fn isolation(&self) -> IsolationLevel {
        self.isolation
    }

    async fn commit(&self) -> Result<()> {
        self.state.engine.commit();
        Ok(())
    }

    async fn abort(&self) -> Result<()> {
        self.state.engine.abort();
        Ok(())
    }
}