kmp-adapter-embedded 0.18.3

Embedded SQLite storage adapters for every KMP persistence port
Documentation
use std::sync::MutexGuard;

use kmp_domain::PortError;
use rusqlite::Connection;

use super::sqlite::Ops;
use super::{Key, ReadTx, Str3Row, StrRow, Table, U64Row};

pub(super) struct SqliteSnapshotRead<'a>(pub(super) MutexGuard<'a, Option<Connection>>);

impl SqliteSnapshotRead<'_> {
    fn ops(&self) -> Ops<'_> {
        Ops {
            connection: self.0.as_ref().expect("snapshot connection"),
        }
    }
}

impl ReadTx for SqliteSnapshotRead<'_> {
    fn scan_linked_json(
        &self,
        request: &super::LinkedJsonScan<'_>,
    ) -> Result<Vec<super::LinkedJsonRow>, PortError> {
        super::sqlite_linked_json::scan(self.0.as_ref().expect("snapshot connection"), request)
    }

    fn get(&self, table: Table, key: Key<'_>) -> Result<Option<Vec<u8>>, PortError> {
        self.ops().get(table, key)
    }
    fn value_len(&self, table: Table, key: Key<'_>) -> Result<Option<u64>, PortError> {
        self.ops().value_len(table, key)
    }
    fn scan_str(&self, table: Table) -> Result<Vec<StrRow>, PortError> {
        self.ops().scan_str(table)
    }
    fn project_str_json(
        &self,
        table: Table,
        key: &str,
        fields: &[&str],
    ) -> Result<Option<Vec<u8>>, PortError> {
        self.ops().project_str_json(table, key, fields)
    }
    fn scan_str3_by_first(&self, table: Table, first: &str) -> Result<Vec<Str3Row>, PortError> {
        self.ops().scan_str3_by_first(table, first)
    }
    fn scan_str3_page(
        &self,
        table: Table,
        first: &str,
        after: Option<(&str, &str)>,
        limit: u32,
        relation_type: Option<&str>,
    ) -> Result<Vec<Str3Row>, PortError> {
        self.ops()
            .scan_str3_page(table, first, after, limit, relation_type)
    }
    fn scan_u64(&self, table: Table) -> Result<Vec<U64Row>, PortError> {
        self.ops().scan_u64(table)
    }
    fn last_u64(&self, table: Table) -> Result<Option<U64Row>, PortError> {
        self.ops().last_u64(table)
    }
    fn count(&self, table: Table) -> Result<u64, PortError> {
        self.ops().count(table)
    }
}