[][src]Struct webext_storage::db::StorageDb

pub struct StorageDb {
    writer: Connection,
    interrupt_counter: Arc<AtomicUsize>,
}
[]

A StorageDb wraps a read-write SQLite connection, and handles schema migrations and recovering from database file corruption. It can be used anywhere a rusqlite::Connection is expected, thanks to its Deref{Mut} implementations.

We only support a single writer connection - so that's the only thing we store. It's still a bit overkill, but there's only so many yaks in a day.

Fields

writer: Connectioninterrupt_counter: Arc<AtomicUsize>

Implementations

impl StorageDb[src][]

pub fn new(db_path: impl AsRef<Path>) -> Result<Self>[src][]

Create a new, or fetch an already open, StorageDb backed by a file on disk.

fn new_named(db_path: PathBuf) -> Result<Self>[src]

pub fn interrupt_handle(&self) -> SqlInterruptHandle[src][]

Returns an interrupt handle for this database connection. This handle should be handed out to consumers that want to interrupt long-running operations. It's FFI-safe, and Send + Sync, since it only makes sense to use from another thread. Calling interrupt on the handle sets a flag on all currently active interrupt scopes.

pub fn begin_interrupt_scope(&self) -> SqlInterruptScope[src][]

Creates an object that knows when it's been interrupted. A new interrupt scope should be created inside each method that does long-running database work, like batch writes. This is the other side of a SqlInterruptHandle: when a handle is interrupted, it flags all active interrupt scopes as interrupted, too, so that they can abort pending work as soon as possible.

pub fn close(self) -> Result<(), (StorageDb, Error)>[src][]

Closes the database connection. If there are any unfinalized prepared statements on the connection, close will fail and the StorageDb will be returned to the caller so that it can retry, drop (via mem::drop)

Keep in mind that dropping the connection tries to close it again, and panics on error.

Trait Implementations

impl Deref for StorageDb[src][+]

type Target = Connection

The resulting type after dereferencing.

impl DerefMut for StorageDb[src][+]

Auto Trait Implementations

impl !RefUnwindSafe for StorageDb

impl Send for StorageDb

impl !Sync for StorageDb

impl Unpin for StorageDb

impl !UnwindSafe for StorageDb

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src][+]

impl<T> Borrow<T> for T where
    T: ?Sized
[src][+]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src][+]

impl<T> From<T> for T[src][+]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src][+]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src][+]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src][+]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[+]