pub trait Db {
Show 13 methods
// Required methods
fn txn(&self) -> Transaction;
fn group(&self, spec: GroupSpec) -> Box<dyn Group>;
fn cursor(&self) -> NewCursor;
fn doc_get(&self, doc: &Hash) -> Result<Option<Arc<Document>>, Box<DbError>>;
fn query(&self, doc: &Hash, query: DbQuery) -> Box<dyn CursorQuery>;
fn schema_get(
&self,
schema: &Hash,
) -> Result<Option<Arc<Schema>>, Box<DbError>>;
fn schema_add(
&self,
schema: Arc<Document>,
) -> Result<Result<Arc<Schema>, FogError>, Box<DbError>>;
fn schema_del(&self, schema: &Hash) -> Result<bool, Box<DbError>>;
fn schema_list(&self) -> Vec<Hash>;
fn name_get(&self, name: &str) -> Result<Option<Hash>, Box<DbError>>;
fn name_add(
&self,
name: &str,
hash: &Hash,
) -> Result<Option<Hash>, Box<DbError>>;
fn name_del(&self, schema: &Hash) -> Result<Option<Hash>, Box<DbError>>;
fn name_list(&self) -> Vec<(String, Hash)>;
}
Expand description
An implementation of a fog-pack database. Provides cursor, transaction, schema, group, and name access.
- Transactions may be executed upon by calling
Db::txn
. - Groups may be opened through the database by calling
Db::group
. - Schemas may be added, retrieved, and removed from the database.
- Name-to-Document mappings may be added, retrieved, and removed from the database. These mappings function as the roots of the database’s Document tree, pinning documents to the database.
Required Methods§
Sourcefn txn(&self) -> Transaction
fn txn(&self) -> Transaction
Start a new transaction with this database
Sourcefn doc_get(&self, doc: &Hash) -> Result<Option<Arc<Document>>, Box<DbError>>
fn doc_get(&self, doc: &Hash) -> Result<Option<Arc<Document>>, Box<DbError>>
Get a document directly from the database
Sourcefn query(&self, doc: &Hash, query: DbQuery) -> Box<dyn CursorQuery>
fn query(&self, doc: &Hash, query: DbQuery) -> Box<dyn CursorQuery>
Make a query directly on the database
Sourcefn schema_get(&self, schema: &Hash) -> Result<Option<Arc<Schema>>, Box<DbError>>
fn schema_get(&self, schema: &Hash) -> Result<Option<Arc<Schema>>, Box<DbError>>
Get a schema in the database
Sourcefn schema_add(
&self,
schema: Arc<Document>,
) -> Result<Result<Arc<Schema>, FogError>, Box<DbError>>
fn schema_add( &self, schema: Arc<Document>, ) -> Result<Result<Arc<Schema>, FogError>, Box<DbError>>
Add a schema to the database. Fails if the schema document wasn’t valid.
Sourcefn schema_del(&self, schema: &Hash) -> Result<bool, Box<DbError>>
fn schema_del(&self, schema: &Hash) -> Result<bool, Box<DbError>>
Remove a schema from the database. Returns false if the schema wasn’t in the database.
Sourcefn schema_list(&self) -> Vec<Hash>
fn schema_list(&self) -> Vec<Hash>
Get a list of all schemas in the database.
Sourcefn name_get(&self, name: &str) -> Result<Option<Hash>, Box<DbError>>
fn name_get(&self, name: &str) -> Result<Option<Hash>, Box<DbError>>
Get a hash associated with a name in the database.
Sourcefn name_add(
&self,
name: &str,
hash: &Hash,
) -> Result<Option<Hash>, Box<DbError>>
fn name_add( &self, name: &str, hash: &Hash, ) -> Result<Option<Hash>, Box<DbError>>
Add a name-to-hash mapping to the database. This pins the document inside the database, once it’s been added. This should be done before adding the document in a transaction. Returns the previous hash, if there was one.