pub struct Database { /* private fields */ }Expand description
Abstraction for flora’s primary datastore (SQLite).
Implementations§
Source§impl Database
impl Database
Sourcepub async fn activate_wal(&self) -> Result<(), DatabaseError>
pub async fn activate_wal(&self) -> Result<(), DatabaseError>
Enables the WAL
See https://sqlite.org/wal.html
§Errors
Returns DatabaseError if WAL activation fails.
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, activates WAL, creates a ‘records’ table, and creates indexes.
§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.
Sourcepub async fn get_all_records(&self) -> Result<Vec<DbRecord>, DatabaseError>
pub async fn get_all_records(&self) -> Result<Vec<DbRecord>, DatabaseError>
Selects all rows in the records table, without any pagination.
§Errors
Returns DatabaseError if the operation fails.
Sourcepub async fn get_all_meta(&self) -> Result<Vec<DbRecordMeta>, DatabaseError>
pub async fn get_all_meta(&self) -> Result<Vec<DbRecordMeta>, DatabaseError>
Selects all rows in the records table, without any pagination,
and returns their metadata (all fields except serialized data
of the page content).
§Errors
Returns DatabaseError if the operation fails.