Skip to main content

vein_database/sql/
mod.rs

1pub mod sqlite;
2
3use anyhow::Result;
4
5enum SQLiteBackend {
6    Sqlite(sqlite::SqliteDb),
7}
8
9pub struct SQLite {
10    backend: SQLiteBackend,
11}
12
13impl SQLite {
14    pub fn new() -> Result<Self> {
15        let sqlite = sqlite::SqliteDb::new()?;
16        Ok(Self {
17            backend: SQLiteBackend::Sqlite(sqlite),
18        })
19    }
20
21    pub fn create(
22        &self,
23        id: &str,
24        role: &str,
25        summary: &str,
26        code_style: bool,
27        agent: &str,
28        timestamp: &str,
29    ) -> Result<String> {
30        match &self.backend {
31            SQLiteBackend::Sqlite(db) => db.create(id, role, summary, code_style, agent, timestamp),
32        }
33    }
34
35    pub fn upsert(
36        &self,
37        id: &str,
38        role: &str,
39        summary: &str,
40        code_style: bool,
41        agent: &str,
42        timestamp: &str,
43    ) -> Result<String> {
44        match &self.backend {
45            SQLiteBackend::Sqlite(db) => db.upsert(id, role, summary, code_style, agent, timestamp),
46        }
47    }
48
49    pub fn update(
50        &self,
51        id: &str,
52        role: &str,
53        summary: &str,
54        code_style: bool,
55        agent: &str,
56        timestamp: &str,
57    ) -> Result<bool> {
58        match &self.backend {
59            SQLiteBackend::Sqlite(db) => db.update(id, role, summary, code_style, agent, timestamp),
60        }
61    }
62
63    pub fn delete(&self, id: &str) -> Result<bool> {
64        match &self.backend {
65            SQLiteBackend::Sqlite(db) => db.delete(id),
66        }
67    }
68
69    pub fn query(&self, query_str: &str) -> Result<String> {
70        match &self.backend {
71            SQLiteBackend::Sqlite(db) => db.query(query_str),
72        }
73    }
74
75    pub fn count_all(&self) -> Result<usize> {
76        match &self.backend {
77            SQLiteBackend::Sqlite(db) => db.count_all(),
78        }
79    }
80}