From 7ff54ed0dedc5b20a2dc696074304f80b6b93130 Mon Sep 17 00:00:00 2001 From: dbr Date: Fri, 7 May 2021 22:24:55 +1000 Subject: [PATCH] WIP. Open new connection for each transaction as workaround --- sync-server/src/storage/sqlite.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/sync-server/src/storage/sqlite.rs b/sync-server/src/storage/sqlite.rs index a6eaa0df4..98ac5feab 100644 --- a/sync-server/src/storage/sqlite.rs +++ b/sync-server/src/storage/sqlite.rs @@ -103,20 +103,20 @@ impl SqliteStorage { impl Storage for SqliteStorage { fn txn<'a>(&'a self) -> anyhow::Result> { - let mut con = self.new_connection()?; - let mut t = Txn{con, txn: None}; + let con = self.new_connection()?; + let t = Txn{con, txn: None}; Ok(Box::new(t)) } } struct Txn<'t> { con: Connection, - txn: Option<&'t rusqlite::Transaction<'t>>, + txn: Option>, } impl <'t>Txn<'t> { - fn get_txn(&mut self) -> Result<&'t rusqlite::Transaction, SqliteError> { - Ok(&self.con.transaction().unwrap()) + fn get_txn(&mut self) -> Result { + Ok(self.con.transaction().unwrap()) } } @@ -171,20 +171,28 @@ impl <'t>StorageTxn for Txn<'t> { parent_version_id: Uuid, history_segment: Vec, ) -> anyhow::Result<()> { + let t = self.get_txn()?; + let version = Version { version_id, parent_version_id, history_segment, }; - todo!(); + + t.execute( + "INSERT INTO versions (client_key, id, parent, history_segment)", + params![], + ).context("Add version query")?; + Ok(()) } fn commit(&mut self) -> anyhow::Result<()> { - let t = self + let t: rusqlite::Transaction = self .txn .take() - .ok_or(SqliteError::TransactionAlreadyCommitted)?; + .unwrap(); + //.ok_or(SqliteError::TransactionAlreadyCommitted)?; t.commit().context("Committing transaction")?; Ok(()) }