From 8a4f311c1d1fa4d978c93e58d95bf59a8a38b587 Mon Sep 17 00:00:00 2001 From: Kevin Hoerr Date: Wed, 25 Feb 2026 22:28:26 +0000 Subject: Add context and initialization --- src/main/rust/store/sqlite.rs | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/main/rust/store/sqlite.rs (limited to 'src/main/rust/store/sqlite.rs') 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, +} + +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()); + } +} -- cgit v1.3