Skip to content

Commit addefaa

Browse files
committed
Move SqliteStore logic to _internal methods
.. to be easier reusable via `KVStore` also
1 parent 523900f commit addefaa

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/io/sqlite_store/mod.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ impl SqliteStore {
128128
pub fn get_data_dir(&self) -> PathBuf {
129129
self.data_dir.clone()
130130
}
131-
}
132131

133-
impl KVStoreSync for SqliteStore {
134-
fn read(
132+
fn read_internal(
135133
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
136134
) -> io::Result<Vec<u8>> {
137135
check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "read")?;
@@ -179,7 +177,7 @@ impl KVStoreSync for SqliteStore {
179177
Ok(res)
180178
}
181179

182-
fn write(
180+
fn write_internal(
183181
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
184182
) -> io::Result<()> {
185183
check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "write")?;
@@ -215,7 +213,7 @@ impl KVStoreSync for SqliteStore {
215213
})
216214
}
217215

218-
fn remove(
216+
fn remove_internal(
219217
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, _lazy: bool,
220218
) -> io::Result<()> {
221219
check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "remove")?;
@@ -247,7 +245,9 @@ impl KVStoreSync for SqliteStore {
247245
Ok(())
248246
}
249247

250-
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
248+
fn list_internal(
249+
&self, primary_namespace: &str, secondary_namespace: &str,
250+
) -> io::Result<Vec<String>> {
251251
check_namespace_key_validity(primary_namespace, secondary_namespace, None, "list")?;
252252

253253
let locked_conn = self.connection.lock().unwrap();
@@ -287,6 +287,30 @@ impl KVStoreSync for SqliteStore {
287287
}
288288
}
289289

290+
impl KVStoreSync for SqliteStore {
291+
fn read(
292+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
293+
) -> io::Result<Vec<u8>> {
294+
self.read_internal(primary_namespace, secondary_namespace, key)
295+
}
296+
297+
fn write(
298+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
299+
) -> io::Result<()> {
300+
self.write_internal(primary_namespace, secondary_namespace, key, buf)
301+
}
302+
303+
fn remove(
304+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
305+
) -> io::Result<()> {
306+
self.remove_internal(primary_namespace, secondary_namespace, key, lazy)
307+
}
308+
309+
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
310+
self.list_internal(primary_namespace, secondary_namespace)
311+
}
312+
}
313+
290314
#[cfg(test)]
291315
mod tests {
292316
use super::*;

0 commit comments

Comments
 (0)