diff --git a/kinode/src/sqlite.rs b/kinode/src/sqlite.rs index 7a744336..5cda7a0d 100644 --- a/kinode/src/sqlite.rs +++ b/kinode/src/sqlite.rs @@ -381,18 +381,6 @@ async fn handle_request( tx.commit()?; (serde_json::to_vec(&SqliteResponse::Ok).unwrap(), None) } - SqliteAction::Backup => { - for db_ref in state.open_dbs.iter() { - let db = db_ref.value().lock().await; - let result: rusqlite::Result<()> = db - .query_row("PRAGMA wal_checkpoint(TRUNCATE)", [], |_| Ok(())) - .map(|_| ()); - if let Err(e) = result { - return Err(SqliteError::RusqliteError(e.to_string())); - } - } - (serde_json::to_vec(&SqliteResponse::Ok).unwrap(), None) - } }; if let Some(target) = km.rsvp.or_else(|| expects_response.map(|_| source)) { @@ -530,10 +518,6 @@ async fn check_caps( Ok(()) } - SqliteAction::Backup => { - // flushing WALs for backup - Ok(()) - } } } diff --git a/lib/src/sqlite.rs b/lib/src/sqlite.rs index f0b997e3..1861b99d 100644 --- a/lib/src/sqlite.rs +++ b/lib/src/sqlite.rs @@ -13,25 +13,59 @@ pub struct SqliteRequest { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum SqliteAction { + /// Opens an existing sqlite database or creates a new one if it doesn't exist. Open, + /// Permanently deletes the entire sqlite database. RemoveDb, + /// Executes a write statement (INSERT/UPDATE/DELETE) + /// + /// * `statement` - SQL statement to execute + /// * `tx_id` - Optional transaction ID + /// * blob: Vec - Parameters for the SQL statement, where SqlValue can be: + /// - null + /// - boolean + /// - i64 + /// - f64 + /// - String + /// - Vec (binary data) Write { statement: String, tx_id: Option, }, + /// Executes a read query (SELECT) + /// + /// * blob: Vec - Parameters for the SQL query, where SqlValue can be: + /// - null + /// - boolean + /// - i64 + /// - f64 + /// - String + /// - Vec (binary data) Query(String), + /// Starts a new transaction BeginTx, - Commit { - tx_id: u64, - }, - Backup, + /// Commits transaction with given ID + Commit { tx_id: u64 }, } +/// Responses from SQLite operations #[derive(Clone, Debug, Serialize, Deserialize)] pub enum SqliteResponse { + /// Operation succeeded Ok, + /// Query returned results + /// + /// * blob: Vec> - Array of rows, where each row contains SqlValue types: + /// - null + /// - boolean + /// - i64 + /// - f64 + /// - String + /// - Vec (binary data) Read, + /// Transaction started with ID BeginTx { tx_id: u64 }, + /// Operation failed Err(SqliteError), }