aboutsummaryrefslogtreecommitdiff
path: root/src/main/rust/store/mod.rs
diff options
context:
space:
mode:
authorKevin Hoerr <kjhoerr@submelon.dev>2026-02-26 21:57:41 +0000
committerKevin Hoerr <kjhoerr@submelon.dev>2026-02-26 21:57:41 +0000
commit47ea7901b73085ead704ec2bd45402ae0c4ce5a2 (patch)
tree28c5710b4ffe79c36cadcfdd3a28e30ec0fa2305 /src/main/rust/store/mod.rs
parent8a4f311c1d1fa4d978c93e58d95bf59a8a38b587 (diff)
downloadequity-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.rs34
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)]