pub struct TempDb { /* private fields */ }Expand description
Data structure to keep the temporary file holding the database alive, because it will get unlinked on drop.
Implementations§
Source§impl TempDb
impl TempDb
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Creates a new database at a temporary path.
§Errors
Returns anyhow::Error if we can’t:
- Create a new
NamedTempFilefor the database - Initialize the database at the temporary path
Methods from Deref<Target = Database>§
Sourcepub async fn optimize(&self) -> Result<(), DatabaseError>
pub async fn optimize(&self) -> Result<(), DatabaseError>
Runs “PRAGMA optimize=0x10002”.
See https://sqlite.org/lang_analyze.html.
§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.
Returns the number of documents affected (should be 1 if a document matching the id was deleted, and 0 if no matching document was found in the DB).
§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,
start_row: Option<i64>,
) -> Result<Vec<DbRecord>, DatabaseError>
pub async fn get_all_records( &self, start_row: Option<i64>, ) -> 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,
start_row: Option<i64>,
) -> Result<Vec<DbRecordMeta>, DatabaseError>
pub async fn get_all_meta( &self, start_row: Option<i64>, ) -> 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.
Sourcepub async fn get_all_ids(&self) -> Result<Vec<i64>, DatabaseError>
pub async fn get_all_ids(&self) -> Result<Vec<i64>, DatabaseError>
Sourcepub async fn most_recent_meta(
&self,
start_idx: Option<usize>,
) -> Result<Vec<DbRecordMeta>, DatabaseError>
pub async fn most_recent_meta( &self, start_idx: Option<usize>, ) -> Result<Vec<DbRecordMeta>, DatabaseError>
Similar to Database::get_all_meta, except orders records by
descending order of timestamp_flora.
Returns an empty list if the given index is out of bounds.
Sourcepub async fn update_record_data(
&self,
record: DbRecord,
) -> Result<i64, DatabaseError>
pub async fn update_record_data( &self, record: DbRecord, ) -> Result<i64, DatabaseError>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TempDb
impl !UnwindSafe for TempDb
impl Freeze for TempDb
impl Send for TempDb
impl Sync for TempDb
impl Unpin for TempDb
impl UnsafeUnpin for TempDb
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request