|
|
@ -43,23 +43,8 @@ use std::error::Error; |
|
|
|
use std::io::{BufRead, Write}; |
|
|
|
use std::io::{BufRead, Write}; |
|
|
|
#[cfg(not(target_family = "wasm"))] |
|
|
|
#[cfg(not(target_family = "wasm"))] |
|
|
|
use std::path::Path; |
|
|
|
use std::path::Path; |
|
|
|
use std::path::PathBuf; |
|
|
|
|
|
|
|
use std::{fmt, str}; |
|
|
|
use std::{fmt, str}; |
|
|
|
|
|
|
|
|
|
|
|
pub struct SecondaryOptions { |
|
|
|
|
|
|
|
pub path: PathBuf, |
|
|
|
|
|
|
|
pub secondary_path: PathBuf, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct ReadOnlyOptions { |
|
|
|
|
|
|
|
pub path: PathBuf, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub enum StoreOpenOptions { |
|
|
|
|
|
|
|
OpenAsSecondary(SecondaryOptions), |
|
|
|
|
|
|
|
OpenAsReadOnly(ReadOnlyOptions), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// An on-disk [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset).
|
|
|
|
/// An on-disk [RDF dataset](https://www.w3.org/TR/rdf11-concepts/#dfn-rdf-dataset).
|
|
|
|
/// Allows to query and update it using SPARQL.
|
|
|
|
/// Allows to query and update it using SPARQL.
|
|
|
|
/// It is based on the [RocksDB](https://rocksdb.org/) key-value store.
|
|
|
|
/// It is based on the [RocksDB](https://rocksdb.org/) key-value store.
|
|
|
@ -109,7 +94,11 @@ impl Store { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Opens a [`Store`] and creates it if it does not exist yet.
|
|
|
|
/// Opens a read-write [`Store`] and creates it if it does not exist yet.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Only one read-write [`Store`] can exist at the same time.
|
|
|
|
|
|
|
|
/// If you want to have extra [`Store`] instance opened on a same data
|
|
|
|
|
|
|
|
/// use [`Store::open_secondary`] or [`Store::open_read_only`].
|
|
|
|
#[cfg(not(target_family = "wasm"))] |
|
|
|
#[cfg(not(target_family = "wasm"))] |
|
|
|
pub fn open(path: impl AsRef<Path>) -> Result<Self, StorageError> { |
|
|
|
pub fn open(path: impl AsRef<Path>) -> Result<Self, StorageError> { |
|
|
|
Ok(Self { |
|
|
|
Ok(Self { |
|
|
@ -117,11 +106,30 @@ impl Store { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Opens a [`Store`] with options
|
|
|
|
/// Opens a read-only clone of a running [`Store`].
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// It should only be used if a primary instance opened with [`Store::open`] is running at the same time.
|
|
|
|
|
|
|
|
/// `primary_path` must be the path of the primary instance and `secondary_path` an other directory for the secondary instance cache.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// If you want to simple read-only [`Store`] use [`Store::open_read_only`].
|
|
|
|
|
|
|
|
#[cfg(not(target_family = "wasm"))] |
|
|
|
|
|
|
|
pub fn open_secondary( |
|
|
|
|
|
|
|
primary_path: impl AsRef<Path>, |
|
|
|
|
|
|
|
secondary_path: impl AsRef<Path>, |
|
|
|
|
|
|
|
) -> Result<Self, StorageError> { |
|
|
|
|
|
|
|
Ok(Self { |
|
|
|
|
|
|
|
storage: Storage::open_secondary(primary_path.as_ref(), secondary_path.as_ref())?, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Opens a read-only [`Store`] from disk.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// It should not be already opened in write mode.
|
|
|
|
|
|
|
|
/// If you want to do so, use [`Store::open_secondary`].
|
|
|
|
#[cfg(not(target_family = "wasm"))] |
|
|
|
#[cfg(not(target_family = "wasm"))] |
|
|
|
pub fn open_with_options(options: StoreOpenOptions) -> Result<Self, StorageError> { |
|
|
|
pub fn open_read_only(path: impl AsRef<Path>) -> Result<Self, StorageError> { |
|
|
|
Ok(Self { |
|
|
|
Ok(Self { |
|
|
|
storage: Storage::open_with_options(options)?, |
|
|
|
storage: Storage::open_read_only(path.as_ref())?, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|