diff options
| author | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-02-26 22:11:25 +0000 |
|---|---|---|
| committer | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-02-26 22:11:25 +0000 |
| commit | b59ea630284d792d7b959e2b64e818e22b038f21 (patch) | |
| tree | dcea59e042e76dd4def27ce034c044c27923d407 /src/main/rust | |
| parent | 5d78d005478def6da994af5545a4aae681b93d00 (diff) | |
| download | equity-tracker-b59ea630284d792d7b959e2b64e818e22b038f21.tar.gz equity-tracker-b59ea630284d792d7b959e2b64e818e22b038f21.tar.bz2 equity-tracker-b59ea630284d792d7b959e2b64e818e22b038f21.zip | |
SQLite -> SQLiteStore
Diffstat (limited to 'src/main/rust')
| -rw-r--r-- | src/main/rust/store/mod.rs | 9 | ||||
| -rw-r--r-- | src/main/rust/store/sqlite.rs | 26 |
2 files changed, 17 insertions, 18 deletions
diff --git a/src/main/rust/store/mod.rs b/src/main/rust/store/mod.rs index 2408901..2cce3e9 100644 --- a/src/main/rust/store/mod.rs +++ b/src/main/rust/store/mod.rs @@ -1,12 +1,11 @@ mod sqlite; -use std::num::TryFromIntError; - +use crate::store::sqlite::SQLiteStore; use miette::{Diagnostic, Result}; use thiserror::Error; pub enum Context { - SQLite(sqlite::SQLite), + SQLite(SQLiteStore), } #[derive(Debug, Diagnostic, Error)] @@ -14,12 +13,12 @@ pub enum ContextError { #[error("Data storage error")] DataError(#[from] ::sqlite::Error), #[error("Int conversion error")] - ConversionError(#[from] TryFromIntError), + ConversionError(#[from] std::num::TryFromIntError), } impl Default for Context { fn default() -> Self { - Context::SQLite(sqlite::SQLite::default()) + Context::SQLite(SQLiteStore::default()) } } diff --git a/src/main/rust/store/sqlite.rs b/src/main/rust/store/sqlite.rs index 6033494..12d9a47 100644 --- a/src/main/rust/store/sqlite.rs +++ b/src/main/rust/store/sqlite.rs @@ -2,12 +2,12 @@ use crate::store::{ContextError, Store}; use miette::Result; use sqlite::Connection; -pub struct SQLite { +pub struct SQLiteStore { location: String, connection: Option<Connection>, } -impl SQLite { +impl SQLiteStore { /// Wrap connection in a Result to make it easier to unwrap later fn get_connection(&self) -> Result<&Connection, sqlite::Error> { match &self.connection { @@ -50,16 +50,16 @@ impl SQLite { } } -impl Default for SQLite { +impl Default for SQLiteStore { fn default() -> Self { - SQLite { + SQLiteStore { location: ":memory:".into(), connection: Option::None, } } } -impl Store for SQLite { +impl Store for SQLiteStore { /// Init SQLite for counting. Creates `RATAT` table with single row, with /// counter set to `0` fn init(&mut self) -> Result<(), ContextError> { @@ -101,7 +101,7 @@ mod tests { #[test] fn default() { - let context = SQLite::default(); + let context = SQLiteStore::default(); assert_eq!(context.location, ":memory:"); assert!(context.connection.is_none()); @@ -109,7 +109,7 @@ mod tests { #[test] fn init() { - let mut context = SQLite::default(); + let mut context = SQLiteStore::default(); let res = context.init(); @@ -119,7 +119,7 @@ mod tests { #[test] fn get_counter() { - let mut context = SQLite::default(); + let mut context = SQLiteStore::default(); assert!(context.init().is_ok()); let res = context.get_counter(); @@ -130,7 +130,7 @@ mod tests { #[test] fn get_counter_error() { - let context = SQLite::default(); + let context = SQLiteStore::default(); // don't initialize let res = context.get_counter(); @@ -140,7 +140,7 @@ mod tests { #[test] fn get_counter_outside_range() { - let mut context = SQLite::default(); + let mut context = SQLiteStore::default(); assert!(context.init().is_ok()); let new_value = -1; @@ -156,7 +156,7 @@ mod tests { #[test] fn set_counter() { - let mut context = SQLite::default(); + let mut context = SQLiteStore::default(); assert!(context.init().is_ok()); let expected = 240; @@ -168,7 +168,7 @@ mod tests { #[test] fn set_counter_error() { - let mut context = SQLite::default(); + let mut context = SQLiteStore::default(); // don't initialize let res = context.set_counter(1); @@ -178,7 +178,7 @@ mod tests { #[test] fn set_and_get() { - let mut context = SQLite::default(); + let mut context = SQLiteStore::default(); assert!(context.init().is_ok()); let count_0 = context.get_counter().unwrap(); |
