Skip to content

Commit

Permalink
feat(services/rocksdb): Add scan support (#2827)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLerxky committed Aug 9, 2023
1 parent 90fc206 commit 1cd70e3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/src/services/rocksdb/backend.rs
Expand Up @@ -110,6 +110,8 @@ impl kv::Adapter for Adapter {
Capability {
read: true,
write: true,
list: true,
blocking: true,
..Default::default()
},
)
Expand Down Expand Up @@ -138,6 +140,25 @@ impl kv::Adapter for Adapter {
fn blocking_delete(&self, path: &str) -> Result<()> {
Ok(self.db.delete(path)?)
}

async fn scan(&self, path: &str) -> Result<Vec<String>> {
self.blocking_scan(path)
}

fn blocking_scan(&self, path: &str) -> Result<Vec<String>> {
let it = self.db.prefix_iterator(path).map(|r| r.map(|(k, _v)| k));
let mut res = Vec::default();

for i in it {
let bs = i?.to_vec();
res.push(String::from_utf8(bs).map_err(|err| {
Error::new(ErrorKind::Unexpected, "store key is not valid utf-8 string")
.set_source(err)
})?);
}

Ok(res)
}
}

impl From<rocksdb::Error> for Error {
Expand Down

0 comments on commit 1cd70e3

Please sign in to comment.