IcDbmsDatabase

Struct IcDbmsDatabase 

Source
pub struct IcDbmsDatabase { /* private fields */ }
Expand description

The main DBMS struct.

This struct serves as the entry point for interacting with the DBMS engine.

It provides methods for executing queries.

The transaction field indicates whether the instance is operating within a transaction context. The Database can be instantiated for one-shot, with [Database::oneshot] operations (no transaction), or within a transaction context with [Database::from_transaction].

If a transaction is active, all operations will be part of that transaction until it is committed or rolled back.

Implementations§

Source§

impl IcDbmsDatabase

Source

pub fn oneshot(schema: impl DatabaseSchema + 'static) -> Self

Load an instance of the Database for one-shot operations (no transaction).

Source

pub fn from_transaction( schema: impl DatabaseSchema + 'static, transaction_id: TransactionId, ) -> Self

Load an instance of the Database within a transaction context.

Trait Implementations§

Source§

impl Database for IcDbmsDatabase

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.