webext_storage::store

Struct WebExtStorageStore

source
pub struct WebExtStorageStore { /* private fields */ }
Expand description

A store is used to access storage.sync data. It manages an underlying database connection, and exposes methods for reading and writing storage items scoped to an extension ID. Each item is a JSON object, with one or more string keys, and values of any type that can serialize to JSON.

An application should create only one store, and manage the instance as a singleton. While this isn’t enforced, if you make multiple stores pointing to the same database file, you are going to have a bad time: each store will create its own database connection, using up extra memory and CPU cycles, and causing write contention. For this reason, you should only call Store::new() (or webext_store_new(), from the FFI) once.

Note that our Db implementation is behind an Arc<> because we share that connection with our sync engines - ie, these engines also hold an Arc<> around the same object.

Implementations§

source§

impl WebExtStorageStore

source

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

Creates a store backed by a database at db_path. The path can be a file path or file: URI.

source

pub fn interrupt_handle(&self) -> Arc<SqlInterruptHandle>

Returns an interrupt handle for this store.

source

pub fn set(&self, ext_id: &str, val: JsonValue) -> Result<StorageChanges>

Sets one or more JSON key-value pairs for an extension ID. Returns a list of changes, with existing and new values for each key in val.

source

pub fn usage(&self) -> Result<Vec<UsageInfo>>

Returns information about per-extension usage

source

pub fn get(&self, ext_id: &str, keys: JsonValue) -> Result<JsonValue>

Returns the values for one or more keys keys can be:

  • null, in which case all key-value pairs for the extension are returned, or an empty object if the extension doesn’t have any stored data.
  • A single string key, in which case an object with only that key and its value is returned, or an empty object if the key doesn’t
  • An array of string keys, in which case an object with only those keys and their values is returned. Any keys that don’t exist will be omitted.
  • An object where the property names are keys, and each value is the default value to return if the key doesn’t exist.

This method always returns an object (that is, a serde_json::Value::Object).

source

pub fn remove(&self, ext_id: &str, keys: JsonValue) -> Result<StorageChanges>

Deletes the values for one or more keys. As with get, keys can be either a single string key, or an array of string keys. Returns a list of changes, where each change contains the old value for each deleted key.

source

pub fn clear(&self, ext_id: &str) -> Result<StorageChanges>

Deletes all key-value pairs for the extension. As with remove, returns a list of changes, where each change contains the old value for each deleted key.

source

pub fn get_bytes_in_use(&self, ext_id: &str, keys: JsonValue) -> Result<u64>

Returns the bytes in use for the specified items (which can be null, a string, or an array)

source

pub fn close(&self) -> Result<()>

Closes the store and its database connection. See the docs for StorageDb::close for more details on when this can fail.

source

pub fn get_synced_changes(&self) -> Result<Vec<SyncedExtensionChange>>

Gets the changes which the current sync applied. Should be used immediately after the bridged engine is told to apply incoming changes, and can be used to notify observers of the StorageArea of the changes that were applied. The result is a Vec of already JSON stringified changes.

source

pub fn migrate(&self, filename: impl AsRef<Path>) -> Result<()>

Migrates data from a database in the format of the “old” kinto implementation. Information about how the migration went is stored in the database, and can be read using Self::take_migration_info.

Note that filename isn’t normalized or canonicalized.

source

pub fn take_migration_info(&self) -> Result<Option<MigrationInfo>>

Read-and-delete (e.g. take in rust parlance, see Option::take) operation for any MigrationInfo stored in this database.

source§

impl WebExtStorageStore

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T