vein-database 0.1.0

Database layer for Vein - shared memory system for AI agents and tools
Documentation
pub mod sqlite;

use anyhow::Result;

enum SQLiteBackend {
    Sqlite(sqlite::SqliteDb),
}

pub struct SQLite {
    backend: SQLiteBackend,
}

impl SQLite {
    pub fn new() -> Result<Self> {
        let sqlite = sqlite::SqliteDb::new()?;
        Ok(Self {
            backend: SQLiteBackend::Sqlite(sqlite),
        })
    }

    pub fn create(
        &self,
        id: &str,
        role: &str,
        summary: &str,
        code_style: bool,
        agent: &str,
        timestamp: &str,
    ) -> Result<String> {
        match &self.backend {
            SQLiteBackend::Sqlite(db) => db.create(id, role, summary, code_style, agent, timestamp),
        }
    }

    pub fn upsert(
        &self,
        id: &str,
        role: &str,
        summary: &str,
        code_style: bool,
        agent: &str,
        timestamp: &str,
    ) -> Result<String> {
        match &self.backend {
            SQLiteBackend::Sqlite(db) => db.upsert(id, role, summary, code_style, agent, timestamp),
        }
    }

    pub fn update(
        &self,
        id: &str,
        role: &str,
        summary: &str,
        code_style: bool,
        agent: &str,
        timestamp: &str,
    ) -> Result<bool> {
        match &self.backend {
            SQLiteBackend::Sqlite(db) => db.update(id, role, summary, code_style, agent, timestamp),
        }
    }

    pub fn delete(&self, id: &str) -> Result<bool> {
        match &self.backend {
            SQLiteBackend::Sqlite(db) => db.delete(id),
        }
    }

    pub fn query(&self, query_str: &str) -> Result<String> {
        match &self.backend {
            SQLiteBackend::Sqlite(db) => db.query(query_str),
        }
    }

    pub fn count_all(&self) -> Result<usize> {
        match &self.backend {
            SQLiteBackend::Sqlite(db) => db.count_all(),
        }
    }
}