Skip to content

Commit 7d1d0d5

Browse files
committed
f No need for transaction in write
1 parent 48c530d commit 7d1d0d5

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/io/sqlite_store.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,35 +87,27 @@ impl KVStore for SqliteStore {
8787
}
8888

8989
fn write(&self, namespace: &str, key: &str, buf: &[u8]) -> std::io::Result<()> {
90-
let mut locked_conn = self.connection.lock().unwrap();
91-
92-
let sql_tx = locked_conn.transaction().map_err(|_| {
93-
let msg = format!("Failed to start transaction");
94-
std::io::Error::new(std::io::ErrorKind::Other, msg)
95-
})?;
90+
let locked_conn = self.connection.lock().unwrap();
9691

9792
let sql = format!(
98-
"INSERT OR REPLACE INTO {} (namespace, key, value) VALUES (:namespace, :key, :data);",
93+
"INSERT OR REPLACE INTO {} (namespace, key, value) VALUES (:namespace, :key, :value);",
9994
KV_TABLE_NAME
10095
);
101-
sql_tx
96+
97+
locked_conn
10298
.execute(
10399
&sql,
104100
named_params! {
105101
":namespace": namespace,
106102
":key": key,
107-
":data": buf,
103+
":value": buf,
108104
},
109105
)
110106
.map_err(|_| {
111107
let msg = format!("Failed to write to key: {}/{}", namespace, key);
112108
std::io::Error::new(std::io::ErrorKind::Other, msg)
113109
})?;
114-
115-
sql_tx.commit().map_err(|_| {
116-
let msg = format!("Failed to commit transaction");
117-
std::io::Error::new(std::io::ErrorKind::Other, msg)
118-
})
110+
Ok(())
119111
}
120112

121113
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<bool> {

0 commit comments

Comments
 (0)