WasmStorageImplementation enum
The storage implementation used by the drift
and sqlite3
packages to
emulate a synchronous file system on the web, used by the sqlite3 C library
to store databases.
As persistence APIs exposed by Browsers are usually asynchronous, faking a synchronous file system
Values
-
Uses the Origin private file system APIs provided my modern browsers to persist data.
In this storage mode, drift will host a single shared worker between tabs. As the file system API is only available in dedicated workers, the shared worker will spawn an internal dedicated worker which is thus shared between tabs as well.
The OPFS API allows synchronous access to files, but only after they have been opened asynchronously. Since sqlite3 only needs access to two files for a database files, we can just open them once and keep them open while the database is in use.
This mode is a very reliable and efficient approach to access sqlite3 on the web, and the preferred mode used by drift.
While the relevant specifications allow shared workers to spawn nested workers, this is only implemented in Firefox at the time of writing. Chrome (https://crbug.com/1088481) and Safari don't support this yet.
- opfsLocks → const WasmStorageImplementation
-
Uses the Origin private file system APIs provided my modern browsers to persist data.
Unlike opfsShared, this storage implementation does not use a shared worker (either because it is not available or because the current browser doesn't allow shared workers to spawn dedicated workers). Instead, each tab spawns two dedicated workers that use
Atomics.wait
andAtomics.notify
to turn the asynchronous OPFS API into a synchronous file system implementation.While being less efficient than opfsShared, this mode is also very reliable and used by the official WASM builds of the sqlite3 project as well.
It requires cross-origin isolation, which needs to be enabled by serving your app with special headers:
Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp
-
Emulates a file system over
IndexedDB
in a shared worker. - unsafeIndexedDb → const WasmStorageImplementation
-
Uses the asynchronous IndexedDB API outside of any worker to persist data.
Unlike opfsShared, opfsLocks or sharedIndexedDb, this storage implementation can't prevent data races if your app is opened in multiple tabs at the same time, which is why it's declared as as unsafe.
- inMemory → const WasmStorageImplementation
-
A fallback storage implementation that doesn't store anything.
This implementation is chosen when none of the features needed for other storage implementations are supported by the current browser. In this case, WasmDatabaseResult.missingFeatures enumerates missing browser features.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- index → int
-
A numeric identifier for the enumerated value.
no setterinherited
- name → String
-
Available on Enum, provided by the EnumName extension
The name of the enum value.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
-
values
→ const List<
WasmStorageImplementation> - A constant List of the values in this enum, in order of their declaration.