kanban_persistence_sqlite/
lib.rs1pub mod backend_factory;
2pub mod sqlite_backend;
3pub mod sqlite_store;
4
5pub use backend_factory::SqliteBackendFactory;
6pub use sqlite_backend::SqliteBackend;
7
8pub use sqlite_store::SqliteStore;
9pub use sqlite_store::SUPPORTED_SCHEMA_VERSION;
10
11#[cfg(feature = "test-helpers")]
12use kanban_persistence::PersistenceError;
13
14#[cfg(feature = "test-helpers")]
28pub async fn write_test_metadata_with_schema_version(
29 path: &std::path::Path,
30 version: u32,
31) -> Result<(), PersistenceError> {
32 use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
33 let pool = SqlitePoolOptions::new()
34 .max_connections(1)
35 .connect_with(
36 SqliteConnectOptions::new()
37 .filename(path)
38 .create_if_missing(true),
39 )
40 .await
41 .map_err(|e| PersistenceError::Database(e.to_string()))?;
42 sqlx::raw_sql(&format!(
43 "CREATE TABLE IF NOT EXISTS metadata (
44 id INTEGER PRIMARY KEY CHECK (id = 1),
45 instance_id TEXT NOT NULL,
46 saved_at TEXT NOT NULL,
47 schema_version INTEGER NOT NULL DEFAULT {SUPPORTED_SCHEMA_VERSION},
48 writer_version TEXT,
49 writer_commit TEXT
50 );
51 INSERT OR REPLACE INTO metadata (id, instance_id, saved_at, schema_version)
52 VALUES (1, '550e8400-e29b-41d4-a716-446655440000', '2030-01-01T00:00:00Z', {version});"
53 ))
54 .execute(&pool)
55 .await
56 .map_err(|e| PersistenceError::Database(e.to_string()))?;
57 pool.close().await;
58 Ok(())
59}
60
61#[cfg(feature = "test-helpers")]
69pub async fn read_test_schema_version(
70 path: &std::path::Path,
71) -> Result<Option<u32>, PersistenceError> {
72 use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
73 let pool = SqlitePoolOptions::new()
74 .max_connections(1)
75 .connect_with(SqliteConnectOptions::new().filename(path))
76 .await
77 .map_err(|e| PersistenceError::Database(e.to_string()))?;
78 let version: Option<u32> =
79 sqlx::query_scalar("SELECT schema_version FROM metadata WHERE id = 1")
80 .fetch_optional(&pool)
81 .await
82 .map_err(|e| PersistenceError::Database(e.to_string()))?;
83 pool.close().await;
84 Ok(version)
85}