engram_storage/
database.rs1use rusqlite::{Connection, OpenFlags};
2
3use crate::error::StorageError;
4use crate::schema;
5
6pub struct Database {
7 connection: Connection,
8}
9
10impl Database {
11 pub fn open(path: &str) -> Result<Self, StorageError> {
13 let connection = Connection::open(path)?;
14 schema::apply_schema(&connection)?;
15 Ok(Self { connection })
16 }
17
18 pub fn open_read_only(path: &str) -> Result<Self, StorageError> {
25 let connection = Connection::open_with_flags(
26 path,
27 OpenFlags::SQLITE_OPEN_READ_ONLY | OpenFlags::SQLITE_OPEN_URI,
28 )?;
29 Ok(Self { connection })
30 }
31
32 pub fn in_memory() -> Result<Self, StorageError> {
34 Self::open(":memory:")
35 }
36
37 pub fn connection(&self) -> &Connection {
38 &self.connection
39 }
40}