Database

Trait Database 

Source
pub trait Database {
    // Required methods
    fn select<T>(&self, query: Query<T>) -> IcDbmsResult<Vec<T::Record>>
       where T: TableSchema;
    fn insert<T>(&self, record: T::Insert) -> IcDbmsResult<()>
       where T: TableSchema,
             T::Insert: InsertRecord<Schema = T>;
    fn update<T>(&self, patch: T::Update) -> IcDbmsResult<u64>
       where T: TableSchema,
             T::Update: UpdateRecord<Schema = T>;
    fn delete<T>(
        &self,
        behaviour: DeleteBehavior,
        filter: Option<Filter>,
    ) -> IcDbmsResult<u64>
       where T: TableSchema;
    fn commit(&mut self) -> IcDbmsResult<()>;
    fn rollback(&mut self) -> IcDbmsResult<()>;
}
Expand description

This module defines the Database trait and related database functionalities.

Required Methods§

Source

fn select<T>(&self, query: Query<T>) -> IcDbmsResult<Vec<T::Record>>
where T: TableSchema,

Executes a SELECT query and returns the results.

§Arguments
  • query - The SELECT Query to be executed.
§Returns

The returned results are a vector of [table::TableRecord] matching the query.

Source

fn insert<T>(&self, record: T::Insert) -> IcDbmsResult<()>
where T: TableSchema, T::Insert: InsertRecord<Schema = T>,

Executes an INSERT query.

§Arguments
  • record - The INSERT record to be executed.
Source

fn update<T>(&self, patch: T::Update) -> IcDbmsResult<u64>
where T: TableSchema, T::Update: UpdateRecord<Schema = T>,

Executes an UPDATE query.

§Arguments
  • patch - The UPDATE patch to be applied.
  • filter - An optional Filter to specify which records to update.
§Returns

The number of rows updated.

Source

fn delete<T>( &self, behaviour: DeleteBehavior, filter: Option<Filter>, ) -> IcDbmsResult<u64>
where T: TableSchema,

Executes a DELETE query.

§Arguments
  • behaviour - The DeleteBehavior to apply for foreign key constraints.
  • filter - An optional Filter to specify which records to delete.
§Returns

The number of rows deleted.

Source

fn commit(&mut self) -> IcDbmsResult<()>

Commits the current transaction.

The transaction is consumed.

Any error during commit will trap the canister to ensure consistency.

Source

fn rollback(&mut self) -> IcDbmsResult<()>

Rolls back the current transaction.

The transaction is consumed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§