Adds Store::clear

pull/71/head
Tpt 4 years ago
parent 4b7b537ebd
commit 00ec99450a
  1. 2
      CHANGELOG.md
  2. 22
      lib/src/store/memory.rs
  3. 45
      lib/src/store/rocksdb.rs
  4. 17
      lib/src/store/sled.rs

@ -7,7 +7,7 @@
- A simple built-in HTTP client. In the Rust library, is disabled by default behind the `http_client` feature. It powers SPARQL federation and SPARQL UPDATE `LOAD` operations.
- `std::str::FromStr` implementations to `NamedNode`, `BlankNode`, `Literal`, `Term` and `Variable` allowing to easily parse Turtle/SPARQL serialization of these terms.
- Optional Sled storage for `oxigraph_server`.
- `(Memory|RocksDB|Sled)Store::drop_graph`.
- `(Memory|RocksDB|Sled)Store::drop_graph` and `(Memory|RocksDB|Sled)Store::clear`.
### Removed
- The `default_graph_uris` and `named_graph_uris` parameters from `pyoxigraph` `query` methods.

@ -484,6 +484,27 @@ impl MemoryStore {
}
}
/// Clears the store.
///
/// Usage example:
/// ```
/// use oxigraph::MemoryStore;
/// use oxigraph::model::{NamedNode, Quad};
///
/// let ex = NamedNode::new("http://example.com")?;
/// let quad = Quad::new(ex.clone(), ex.clone(), ex.clone(), ex);
/// let store = MemoryStore::new();
/// store.insert(quad.clone());
/// assert_eq!(1, store.len());
///
/// store.clear();
/// assert_eq!(0, store.len());
/// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ```
pub fn clear(&self) {
*self.indexes_mut() = MemoryStoreIndexes::default();
}
#[allow(clippy::expect_used)]
fn indexes(&self) -> RwLockReadGuard<'_, MemoryStoreIndexes> {
self.indexes
@ -900,6 +921,7 @@ impl StrEncodingAware for MemoryStoreIndexes {
type Error = Infallible;
type StrId = LargeSpur;
}
impl WritableEncodedStore for MemoryStoreIndexes {
fn insert_encoded(&mut self, quad: &EncodedQuad) -> Result<(), Infallible> {
if quad.graph_name.is_default_graph() {

@ -367,6 +367,23 @@ impl RocksDbStore {
}
}
/// Clears the store.
///
/// See [`MemoryStore`](super::memory::MemoryStore::clear()) for a usage example.
pub fn clear(&self) -> Result<(), io::Error> {
self.clear_cf(self.id2str_cf())?;
self.clear_cf(self.spog_cf())?;
self.clear_cf(self.posg_cf())?;
self.clear_cf(self.ospg_cf())?;
self.clear_cf(self.gspo_cf())?;
self.clear_cf(self.gpos_cf())?;
self.clear_cf(self.gosp_cf())?;
self.clear_cf(self.dspo_cf())?;
self.clear_cf(self.dpos_cf())?;
self.clear_cf(self.dosp_cf())?;
Ok(())
}
fn id2str_cf(&self) -> &ColumnFamily {
get_cf(&self.db, ID2STR_CF)
}
@ -655,6 +672,34 @@ impl RocksDbStore {
encoding,
}
}
fn clear_cf(&self, cf: &ColumnFamily) -> Result<(), io::Error> {
self.db
.delete_range_cf(
cf,
[
u8::MIN,
u8::MIN,
u8::MIN,
u8::MIN,
u8::MIN,
u8::MIN,
u8::MIN,
u8::MIN,
],
[
u8::MAX,
u8::MAX,
u8::MAX,
u8::MAX,
u8::MAX,
u8::MAX,
u8::MAX,
u8::MAX,
],
)
.map_err(map_err)
}
}
impl fmt::Display for RocksDbStore {

@ -398,6 +398,23 @@ impl SledStore {
Ok(())
}
/// Clears the store.
///
/// See [`MemoryStore`](super::memory::MemoryStore::clear()) for a usage example.
pub fn clear(&self) -> Result<(), io::Error> {
self.dspo.clear()?;
self.dpos.clear()?;
self.dosp.clear()?;
self.gspo.clear()?;
self.gpos.clear()?;
self.gosp.clear()?;
self.spog.clear()?;
self.posg.clear()?;
self.ospg.clear()?;
self.id2str.clear()?;
Ok(())
}
fn contains_encoded(&self, quad: &EncodedQuad) -> Result<bool, io::Error> {
let mut buffer = Vec::with_capacity(4 * WRITTEN_TERM_MAX_SIZE);
if quad.graph_name.is_default_graph() {

Loading…
Cancel
Save