diff options
Diffstat (limited to 'src/main/rust/store/sqlite.rs')
| -rw-r--r-- | src/main/rust/store/sqlite.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/rust/store/sqlite.rs b/src/main/rust/store/sqlite.rs new file mode 100644 index 0000000..734c635 --- /dev/null +++ b/src/main/rust/store/sqlite.rs @@ -0,0 +1,48 @@ +use crate::store::Store; +use miette::{IntoDiagnostic, Result}; +use sqlite::Connection; + +pub struct SQLite { + location: String, + connection: Option<Connection>, +} + +impl Default for SQLite { + fn default() -> Self { + SQLite { + location: ":memory:".into(), + connection: Option::None, + } + } +} + +impl Store for SQLite { + fn init(&mut self) -> Result<()> { + let conn_path = self.location.clone(); + self.connection = sqlite::open(conn_path).into_diagnostic().ok(); + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn sqlite_default() { + let context = SQLite::default(); + + assert_eq!(context.location, ":memory:"); + assert!(context.connection.is_none()); + } + + #[test] + fn sqlite_init() { + let mut context = SQLite::default(); + + let res = context.init(); + + assert!(res.is_ok()); + assert!(context.connection.is_some()); + } +} |
