Skip to content

Commit 86e1bad

Browse files
committed
Move SqliteStore logic to _internal methods
.. to be easier reusable via `KVStore` also
1 parent ee122f2 commit 86e1bad

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
@@ -126,10 +126,8 @@ impl SqliteStore {
126126
pub fn get_data_dir(&self) -> PathBuf {
127127
self.data_dir.clone()
128128
}
129-
}
130129

131-
impl KVStoreSync for SqliteStore {
132-
fn read(
130+
fn read_internal(
133131
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
134132
) -> io::Result<Vec<u8>> {
135133
check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "read")?;
@@ -177,7 +175,7 @@ impl KVStoreSync for SqliteStore {
177175
Ok(res)
178176
}
179177

180-
fn write(
178+
fn write_internal(
181179
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
182180
) -> io::Result<()> {
183181
check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "write")?;
@@ -213,7 +211,7 @@ impl KVStoreSync for SqliteStore {
213211
})
214212
}
215213

216-
fn remove(
214+
fn remove_internal(
217215
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, _lazy: bool,
218216
) -> io::Result<()> {
219217
check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "remove")?;
@@ -245,7 +243,9 @@ impl KVStoreSync for SqliteStore {
245243
Ok(())
246244
}
247245

248-
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
246+
fn list_internal(
247+
&self, primary_namespace: &str, secondary_namespace: &str,
248+
) -> io::Result<Vec<String>> {
249249
check_namespace_key_validity(primary_namespace, secondary_namespace, None, "list")?;
250250

251251
let locked_conn = self.connection.lock().unwrap();
@@ -285,6 +285,30 @@ impl KVStoreSync for SqliteStore {
285285
}
286286
}
287287

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

0 commit comments

Comments
 (0)