diff options
| author | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-02-25 22:28:26 +0000 |
|---|---|---|
| committer | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-02-25 22:28:26 +0000 |
| commit | 8a4f311c1d1fa4d978c93e58d95bf59a8a38b587 (patch) | |
| tree | 2d0b2c526d4bc25ba048664e77519cf278702a37 /src/main/rust/store/sqlite.rs | |
| parent | d96b45f468a1587fd0ba1e8ecd0552478d7e6f90 (diff) | |
| download | equity-tracker-8a4f311c1d1fa4d978c93e58d95bf59a8a38b587.tar.gz equity-tracker-8a4f311c1d1fa4d978c93e58d95bf59a8a38b587.tar.bz2 equity-tracker-8a4f311c1d1fa4d978c93e58d95bf59a8a38b587.zip | |
Add context and initialization
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()); + } +} |
