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<'_>
impl Database<'_>
sourcepub fn rw_transaction(&self) -> Result<RwTransaction<'_>>
pub fn rw_transaction(&self) -> Result<RwTransaction<'_>>
Creates a new read-write transaction. This transaction allows you to read and write data.
sourcepub fn r_transaction(&self) -> Result<RTransaction<'_>>
pub fn r_transaction(&self) -> Result<RTransaction<'_>>
source§impl Database<'_>
impl Database<'_>
sourcepub fn unwatch(&self, id: u64) -> Result<bool>
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
.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more