pub struct Database { /* private fields */ }
Expand description
The Seshat database.
Implementations§
source§impl Database
impl Database
sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<Database>where
PathBuf: From<P>,
pub fn new<P: AsRef<Path>>(path: P) -> Result<Database>where PathBuf: From<P>,
Create a new Seshat database or open an existing one.
Arguments
path
- The directory where the database will be stored in. This should be an empty directory if a new database should be created.
sourcepub fn new_with_config<P: AsRef<Path>>(
path: P,
config: &Config
) -> Result<Database>where
PathBuf: From<P>,
pub fn new_with_config<P: AsRef<Path>>( path: P, config: &Config ) -> Result<Database>where PathBuf: From<P>,
Create a new Seshat database or open an existing one with the given configuration.
Arguments
path
- The directory where the database will be stored in. This should be an empty directory if a new database should be created.config
- Configuration that changes the behaviour of the database.
sourcepub fn change_passphrase(self, new_passphrase: &str) -> Result<()>
pub fn change_passphrase(self, new_passphrase: &str) -> Result<()>
Change the passphrase of the Seshat database.
Note that this consumes the database object and any searcher objects can’t be used anymore. A new database will have to be opened and new searcher objects as well.
Arguments
path
- The directory where the database will be stored in. This should be an empty directory if a new database should be created.new_passphrase
- The passphrase that should be used instead of the current one.
sourcepub fn get_size(&self) -> Result<u64>
pub fn get_size(&self) -> Result<u64>
Get the size of the database. This returns the number of bytes the database is using on disk.
sourcepub fn get_path(&self) -> &Path
pub fn get_path(&self) -> &Path
Get the path of the directory where the Seshat database lives in.
sourcepub fn add_event(&self, event: Event, profile: Profile)
pub fn add_event(&self, event: Event, profile: Profile)
Add an event with the given profile to the database.
Arguments
event
- The directory where the database will be stored in. Thisprofile
- The directory where the database will be stored in. This
This is a fast non-blocking operation, it only queues up the event to be
added to the database. The events will be committed to the database
only when the user calls the commit()
method.
sourcepub fn delete_event(&self, event_id: &str) -> Receiver<Result<bool>>
pub fn delete_event(&self, event_id: &str) -> Receiver<Result<bool>>
Delete an event from the database.
Arguments
event_id
- The event id of the event that will be deleted.
Note for the event to be completely removed a commit needs to be done.
Returns a receiver that will receive an boolean once the event has been deleted. The boolean indicates if the event was deleted or if a commit will be needed.
sourcepub fn commit(&mut self) -> Result<()>
pub fn commit(&mut self) -> Result<()>
Commit the currently queued up events. This method will block. A
non-blocking version of this method exists in the commit_no_wait()
method.
sourcepub fn force_commit(&mut self) -> Result<()>
pub fn force_commit(&mut self) -> Result<()>
Commit the currently queued up events forcing the commit to the index.
Commits are usually rate limited. This gets around the limit and forces the documents to be added to the index.
This method will block. A non-blocking version of this method exists in
the force_commit_no_wait()
method.
This should only be used for testing purposes.
sourcepub fn reload(&mut self) -> Result<()>
pub fn reload(&mut self) -> Result<()>
Reload the database so that a search reflects the state of the last commit. Note that this happens automatically and this method should be used only in unit tests.
sourcepub fn commit_no_wait(&mut self) -> Receiver<Result<()>>
pub fn commit_no_wait(&mut self) -> Receiver<Result<()>>
Commit the currently queued up events without waiting for confirmation that the operation is done.
Returns a receiver that will receive an empty message once the commit is done.
sourcepub fn force_commit_no_wait(&mut self) -> Receiver<Result<()>>
pub fn force_commit_no_wait(&mut self) -> Receiver<Result<()>>
Commit the currently queued up events forcing the commit to the index.
Commits are usually rate limited. This gets around the limit and forces the documents to be added to the index.
This should only be used for testing purposes.
Returns a receiver that will receive an empty message once the commit is done.
sourcepub fn add_historic_events(
&self,
events: Vec<(Event, Profile)>,
new_checkpoint: Option<CrawlerCheckpoint>,
old_checkpoint: Option<CrawlerCheckpoint>
) -> Receiver<Result<bool>>
pub fn add_historic_events( &self, events: Vec<(Event, Profile)>, new_checkpoint: Option<CrawlerCheckpoint>, old_checkpoint: Option<CrawlerCheckpoint> ) -> Receiver<Result<bool>>
Add the given events from the room history to the database.
Arguments
events
- The events that will be added.new_checkpoint
- A checkpoint that states where we need to continue fetching events from the room history. This checkpoint will be persisted in the database.old_checkpoint
- The checkpoint that was used to fetch the given events. This checkpoint will be removed from the database.
sourcepub fn search(&self, term: &str, config: &SearchConfig) -> Result<SearchBatch>
pub fn search(&self, term: &str, config: &SearchConfig) -> Result<SearchBatch>
Search the index and return events matching a search term. This is just a helper function that gets a searcher and performs a search on it immediately.
Arguments
term
- The search term that should be used to search the index.
sourcepub fn get_searcher(&self) -> Searcher
pub fn get_searcher(&self) -> Searcher
Get a searcher that can be used to perform a search.
sourcepub fn get_connection(&self) -> Result<Connection>
pub fn get_connection(&self) -> Result<Connection>
Get a database connection. Note that this connection should only be used for reading.
Auto Trait Implementations§
impl !RefUnwindSafe for Database
impl Send for Database
impl !Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.