pub trait Database:
AsAny
+ Send
+ Sync {
// Required methods
fn get(&self, id: Id) -> DatabaseResult<Option<Box<dyn Ent>>>;
fn remove(&self, id: Id) -> DatabaseResult<bool>;
fn insert(&self, ent: Box<dyn Ent>) -> DatabaseResult<Id>;
fn get_all(&self, ids: Vec<Id>) -> DatabaseResult<Vec<Box<dyn Ent>>>;
fn find_all(&self, query: Query) -> DatabaseResult<Vec<Box<dyn Ent>>>;
}Expand description
Represents a synchronous database, which performs blocking CRUD operations using ents. Given that many database implementations handle interior mutability themselves, the API of this trait does not provide any mut guarantees itself.
Required Methods§
Sourcefn get(&self, id: Id) -> DatabaseResult<Option<Box<dyn Ent>>>
fn get(&self, id: Id) -> DatabaseResult<Option<Box<dyn Ent>>>
Retrieves a copy of a single, generic ent with the corresponding id
This should not connect the ent back to the database upon return as that decision should be made outside of the database itself.
Sourcefn remove(&self, id: Id) -> DatabaseResult<bool>
fn remove(&self, id: Id) -> DatabaseResult<bool>
Removes the ent with the corresponding id, triggering edge processing for all disconnected ents. Returns a boolean indicating if an ent was removed.
Sourcefn insert(&self, ent: Box<dyn Ent>) -> DatabaseResult<Id>
fn insert(&self, ent: Box<dyn Ent>) -> DatabaseResult<Id>
Inserts a new ent using its id as the primary index, overwriting any ent with a matching id. If the ent’s id is set to the ephemeral id (of 0), a unique id will be assigned to the ent prior to being inserted.
The ent’s id is returned after being inserted.
Implementations§
Source§impl dyn Database
Implementation for a generic trait object of Database that provides
methods to downcast into a concrete type
impl dyn Database
Implementation for a generic trait object of Database that provides
methods to downcast into a concrete type
Sourcepub fn as_database<D: Database>(&self) -> Option<&D>
pub fn as_database<D: Database>(&self) -> Option<&D>
Attempts to convert this dynamic Database ref into a concrete Database ref by downcasting
Sourcepub fn as_mut_database<D: Database>(&mut self) -> Option<&mut D>
pub fn as_mut_database<D: Database>(&mut self) -> Option<&mut D>
Attempts to convert this dynamic Database mutable ref into a concrete Database mutable ref by downcasting