Database

Trait Database 

Source
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§

Source

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.

Source

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.

Source

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.

Source

fn get_all(&self, ids: Vec<Id>) -> DatabaseResult<Vec<Box<dyn Ent>>>

Performs a retrieval of multiple ents of any type

Source

fn find_all(&self, query: Query) -> DatabaseResult<Vec<Box<dyn Ent>>>

Finds all generic ents that match the query

Implementations§

Source§

impl dyn Database

Implementation for a generic trait object of Database that provides methods to downcast into a concrete type

Source

pub fn as_database<D: Database>(&self) -> Option<&D>

Attempts to convert this dynamic Database ref into a concrete Database ref by downcasting

Source

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

Trait Implementations§

Source§

impl DatabaseExt for dyn Database

Source§

fn insert_typed<E: Ent>(&self, ent: E) -> DatabaseResult<Id>

Inserts an ent of a specific type
Source§

fn get_typed<E: Ent>(&self, id: Id) -> DatabaseResult<Option<E>>

Retrieves an ent by id with a specific type
Source§

fn get_all_typed<E: Ent>(&self, ids: Vec<Id>) -> DatabaseResult<Vec<E>>

Retrieves ents by id with a specific type
Source§

fn find_all_typed<E: Ent>(&self, query: Query) -> DatabaseResult<Vec<E>>

Finds ents that match the specified query and are of the specified type

Implementors§