Abstract database behind generic interface and implement alternative drivers #322

Merged
lx merged 64 commits from db-abstraction into main 2022-06-08 08:01:56 +00:00
Showing only changes of commit e42c7bed38 - Show all commits

View file

@ -48,10 +48,10 @@ impl SqliteDb {
} }
impl SqliteDbInner { impl SqliteDbInner {
fn get_tree(&self, i: usize) -> Result<String> { fn get_tree(&self, i: usize) -> Result<&'_ str> {
self.trees self.trees
.get(i) .get(i)
.cloned() .map(String::as_str)
.ok_or_else(|| Error("invalid tree id".into())) .ok_or_else(|| Error("invalid tree id".into()))
} }
} }
@ -269,8 +269,8 @@ struct SqliteTx<'a> {
} }
impl<'a> SqliteTx<'a> { impl<'a> SqliteTx<'a> {
fn get_tree(&self, i: usize) -> Result<String> { fn get_tree(&self, i: usize) -> Result<&'_ str> {
self.trees.get(i).cloned().ok_or_else(|| { self.trees.get(i).map(String::as_ref).ok_or_else(|| {
Error( Error(
"invalid tree id (it might have been openned after the transaction started)".into(), "invalid tree id (it might have been openned after the transaction started)".into(),
) )