vanth/store, tests: Add persistent SQLite and in-memory store backends with CRUD operations

- Added `rusqlite` and `sqlx` dependencies to support SQLite backend functionality for the store.
- Implemented `Store` struct with backend switching between in-memory (`HashMap`) and SQLite-based storage.
- Added CRUD operations (`read`, `write`, `delete`) to the `Store` API with error handling.
- Created integration tests for SQLite store persistence and basic operations.
This commit is contained in:
Markus Scully 2025-08-05 18:26:08 +03:00
parent b36f178999
commit a1cc9b6e04
Signed by: mascully
GPG key ID: 93CA5814B698101C
6 changed files with 1375 additions and 74 deletions

View file

@ -0,0 +1,26 @@
use vanth::store::Store;
use std::path::PathBuf;
use tempfile::TempDir;
#[test]
fn test_sqlite_store() {
let dir = TempDir::new().unwrap();
let path = dir.path().join("test.db");
let mut store = Store::from_path(path.clone()).unwrap();
assert_eq!(store.read(b"key_1"), Ok(None));
assert_eq!(store.write(b"key_1", b"value_1"), Ok(()));
let value = store.read(b"key_1").unwrap();
assert_eq!(value.as_deref(), Some(b"value_1" as &[u8]));
drop(store);
let mut store = Store::from_path(path.clone()).unwrap();
let value = store.read(b"key_1").unwrap();
assert_eq!(value.as_deref(), Some(b"value_1" as &[u8]));
store.delete(b"key_1").unwrap();
assert_eq!(store.read(b"key_1"), Ok(None));
}