pub struct Database<F: Flash, M: RawMutex> { /* private fields */ }
Expand description
The main database struct.
Implementations§
source§impl<F: Flash, M: RawMutex> Database<F, M>
impl<F: Flash, M: RawMutex> Database<F, M>
sourcepub fn new(flash: F, config: Config) -> Self
pub fn new(flash: F, config: Config) -> Self
Create a new database.
This does no flash operations, and always succeeds. Actually mounting the database is done lazily, when the first operation (read or write) is done.
If the storage is not formatted, you have to call format
before first use.
You can call mount
to force eagerly mounting the database. This can be
useful to detect whether the storage is formatted or not, so that you can format it if it isn’t
before first use.
sourcepub async fn lock_flash(&self) -> impl DerefMut<Target = F> + '_
pub async fn lock_flash(&self) -> impl DerefMut<Target = F> + '_
Get an exclusive lock for the underlying flash.
This returns a “mutex guard”-like object that gives exclusive access to the flash. All other concurrent operations on the database will wait on this object to be dropped.
Note that actually writing to the flash behind ekv
’s back will result
in corruption. This is intended for other tasks, for example
reading the flash memory’s serial number, or statistics.
sourcepub async fn format(&self) -> Result<(), FormatError<F::Error>>
pub async fn format(&self) -> Result<(), FormatError<F::Error>>
Format the database storage.
This will format the underlying storage into an empty key-value database. If the storage was already formatted, all data will be lost.
sourcepub async fn mount(&self) -> Result<(), MountError<F::Error>>
pub async fn mount(&self) -> Result<(), MountError<F::Error>>
Force eagerly mounting the database storage.
You don’t have to call this method, mounting is done lazily on first operation.
Eagerly mounting can still be useful, to detect whether the storage is formatted or not, so that you can format it if it isn’t before first use.
sourcepub async fn read_transaction(&self) -> ReadTransaction<'_, F, M>
pub async fn read_transaction(&self) -> ReadTransaction<'_, F, M>
Open a read transaction.
This will wait if there’s a write transaction either being currently committed, or waiting to be committed because there are other read transactions open.
Dropping the ReadTransaction
closes the transaction. Make sure to drop it as soon
as possible, to not delay write transaction commits.
sourcepub async fn write_transaction(&self) -> WriteTransaction<'_, F, M>
pub async fn write_transaction(&self) -> WriteTransaction<'_, F, M>
Open a write transaction.
This will wait if there’s another write transaction already open.
To make all the writes permanent, call commit
.
Dropping the WriteTransaction
without committing closes the transaction
and discards all written data.