pub struct Database { /* private fields */ }Expand description
Abstraction for flora’s primary datastore (SQLite).
Implementations§
Source§impl Database
impl Database
Sourcepub async fn new_with_records_table(
path: impl AsRef<Path>,
) -> Result<Self, DatabaseError>
pub async fn new_with_records_table( path: impl AsRef<Path>, ) -> Result<Self, DatabaseError>
Initializes the database with a ‘records’ table.
§Errors
Returns DatabaseError if the operation fails.
Sourcepub async fn count(&self) -> Result<i64, DatabaseError>
pub async fn count(&self) -> Result<i64, DatabaseError>
Queries the database to get a count of records it contains.
§Errors
Returns DatabaseError if the operation fails.
Sourcepub async fn insert(&self, record: DbRecord) -> Result<i64, DatabaseError>
pub async fn insert(&self, record: DbRecord) -> Result<i64, DatabaseError>
Inserts the given record into the Database.
Returns the ID of the inserted row.
§Errors
Returns DatabaseError if the insert operation fails.
Sourcepub async fn delete(&self, id: i64) -> Result<usize, DatabaseError>
pub async fn delete(&self, id: i64) -> Result<usize, DatabaseError>
Deletes the record corresponding to the given id.
§Errors
Returns DatabaseError if the operation fails.
Sourcepub async fn get_record(&self, id: i64) -> Result<DbRecord, DatabaseError>
pub async fn get_record(&self, id: i64) -> Result<DbRecord, DatabaseError>
Sourcepub async fn get_many_records(
&self,
ids: &[i64],
) -> Result<Vec<DbRecord>, DatabaseError>
pub async fn get_many_records( &self, ids: &[i64], ) -> Result<Vec<DbRecord>, DatabaseError>
Get multiple records from SQLite given their IDs.
§Errors
Returns DatabaseError if the operation fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
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