use crate::store::Store; use miette::{IntoDiagnostic, Result}; use sqlite::Connection; pub struct SQLite { location: String, connection: Option, } 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()); } }