Struct native_db::Database

source ·
pub struct Database<'a> { /* private fields */ }
Expand description

The database instance. Allows you to create rw_transaction and r_transaction, watch queries, and unwatch etc.

§Example

use native_db::*;

fn main() -> Result<(), db_type::Error> {
   let models = Models::new();
   // Define models ...
   let db = Builder::new().create_in_memory(&models)?;
   // Open transactions
   // Watch data
   // Create snapshots
   // etc...
   Ok(())
}

Implementations§

source§

impl Database<'_>

source

pub fn rw_transaction(&self) -> Result<RwTransaction<'_>>

Creates a new read-write transaction. This transaction allows you to read and write data.

  • Write operations:
    • insert - Insert a item.
    • update - Update a item.
    • remove - Remove a item.
    • migrate - Migrate a model, affect all items.
    • commit - Commit the transaction.
    • abort - Abort the transaction.
  • Read operations:
    • get - Get a item.
    • scan - Scan items.
    • len - Get the number of items.
source

pub fn r_transaction(&self) -> Result<RTransaction<'_>>

Creates a new read-only transaction. This transaction allows you to read data.

  • Read operations:
    • get - Get a item.
    • scan - Scan items.
    • len - Get the number of items.
source§

impl Database<'_>

source

pub fn watch(&self) -> Watch<'_>

Watch queries.

  • get - Watch a item.
  • scan - Watch items.
source

pub fn unwatch(&self, id: u64) -> Result<bool>

Unwatch the given id. You can get the id from the return value of watch. If the id is not valid anymore, this function will do nothing and return false. If the id is valid, the corresponding watcher will be removed and return true. If the id is valid but the watcher is already removed, this function will return false.

source§

impl<'a> Database<'a>

source

pub fn redb_stats(&self) -> Result<Stats>

source§

impl Database<'_>

source

pub fn snapshot<'a>( &self, models: &'a Models, path: &Path, ) -> Result<Database<'a>>

Auto Trait Implementations§

§

impl<'a> !Freeze for Database<'a>

§

impl<'a> !RefUnwindSafe for Database<'a>

§

impl<'a> Send for Database<'a>

§

impl<'a> Sync for Database<'a>

§

impl<'a> Unpin for Database<'a>

§

impl<'a> !UnwindSafe for Database<'a>

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.