diff options
| author | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-02-26 21:57:41 +0000 |
|---|---|---|
| committer | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-02-26 21:57:41 +0000 |
| commit | 47ea7901b73085ead704ec2bd45402ae0c4ce5a2 (patch) | |
| tree | 28c5710b4ffe79c36cadcfdd3a28e30ec0fa2305 /src/main/rust/store/mod.rs | |
| parent | 8a4f311c1d1fa4d978c93e58d95bf59a8a38b587 (diff) | |
| download | equity-tracker-47ea7901b73085ead704ec2bd45402ae0c4ce5a2.tar.gz equity-tracker-47ea7901b73085ead704ec2bd45402ae0c4ce5a2.tar.bz2 equity-tracker-47ea7901b73085ead704ec2bd45402ae0c4ce5a2.zip | |
Use SQLite to store counter
Diffstat (limited to 'src/main/rust/store/mod.rs')
| -rw-r--r-- | src/main/rust/store/mod.rs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/main/rust/store/mod.rs b/src/main/rust/store/mod.rs index 42f1809..7c7d9ce 100644 --- a/src/main/rust/store/mod.rs +++ b/src/main/rust/store/mod.rs @@ -1,11 +1,23 @@ -pub mod sqlite; +mod sqlite; -use miette::Result; +use std::num::TryFromIntError; + +use ::sqlite::Error as SQLiteLibraryError; +use miette::{Diagnostic, Result}; +use thiserror::Error; pub enum Context { SQLite(sqlite::SQLite), } +#[derive(Debug, Diagnostic, Error)] +pub enum ContextError { + #[error("SQLite error")] + SQLiteError(#[from] SQLiteLibraryError), + #[error("Int conversion error")] + ConversionError(#[from] TryFromIntError), +} + impl Default for Context { fn default() -> Self { Context::SQLite(sqlite::SQLite::default()) @@ -13,7 +25,23 @@ impl Default for Context { } pub trait Store { - fn init(&mut self) -> Result<()>; + fn init(&mut self) -> Result<(), ContextError>; + fn get_counter(&self) -> Result<u8, ContextError>; + fn set_counter(&mut self, new_count: u8) -> Result<u8, ContextError>; +} + +impl Context { + pub fn unwrap_store(&mut self) -> &mut impl Store { + match self { + Context::SQLite(store) => store, + } + } + + pub fn get_store(&self) -> &impl Store { + match self { + Context::SQLite(store) => store, + } + } } #[cfg(test)] |
