Remove outdated warnings about drift/wasm

This commit is contained in:
Simon Binder 2023-03-20 17:41:57 +01:00
parent 023512cae3
commit a6bdd26c93
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
3 changed files with 29 additions and 27 deletions

View File

@ -5,17 +5,18 @@ import 'package:sqlite3/wasm.dart';
QueryExecutor connect() {
return LazyDatabase(() async {
// Load wasm bundle
final response = await http.get(Uri.parse('sqlite3.wasm'));
// Create a virtual file system backed by IndexedDb with everything in
// `/drift/my_app/` being persisted.
// Create virtual filesystem for sqlite3 implemented over blobs stored in an
// IndexedDB database (named `my_app` here).
final fs = await IndexedDbFileSystem.open(dbName: 'my_app');
// Load wasm bundle for sqlite3
final response = await http.get(Uri.parse('sqlite3.wasm'));
final sqlite3 = await WasmSqlite3.load(
response.bodyBytes,
SqliteEnvironment(fileSystem: fs),
);
// Then, open a database inside that persisted folder.
return WasmDatabase(sqlite3: sqlite3, path: '/drift/my_app/app.db');
// Then, open a database:
return WasmDatabase(sqlite3: sqlite3, path: '/app.db');
});
}

View File

@ -42,10 +42,10 @@ You can grab the latest version of `sql-wasm.js` and `sql-wasm.wasm` [here](http
and copy them into your `web` folder.
A full example that works on the web (and all other platforms) is available
[here](https://github.com/rodydavis/moor_shared).
[here](https://github.com/simolus3/drift/tree/develop/examples/app).
## Gotchas
The database implementation uses WebAssembly, which needs to be supported by your browser.
The database implementation uses WebAssembly, which needs to be supported by your browser.
Also, make sure that your webserver serves the `.wasm` file as `application/wasm`, browsers
won't accept it otherwise.
@ -272,15 +272,16 @@ You can pass that DatabaseConnection to your database by enabling the `generate_
## New web backend {#drift-wasm}
__Warning__: This new backend is currently in a very experimental state and not suitable for production use.
In recent versions, drift added support for a new backend exposed by the `package:drift/wasm.dart` library.
Unlike sql.js or the official sqlite3 WASM edition which both use Emscripten, this backend does not need any
external JavaScript sources.
All bindings, including a virtual filesystem implementation used to store your databases, are implemented in
Dart instead.
Starting from version `1.6.0`, drift supports the new `package:drift/wasm.dart` backend for web apps.
It binds to a sqlite3 WebAssembly module directly, without requireing an external JavaScript library.
Unlike sql.js, which uses Emscripten, the new backend uses a custom [sqlite3 VFS](https://www.sqlite.org/vfs.html)
and doesn't require any dependencies apart from sqlite3 itself.
The intention is that this build can be optimized for Dart-typical use-cases. For instance, the sql.js backend
needs to close and re-open the database connection for every save. The new backend can just use a custom
virtual file system that sqlite3 will then use internally.
This approach enables optimizations making this backend more efficient that the existing web version of drift.
However, it should be noted that this backend is much newer and may potentially be less stable at the moment.
We encourage you to use it and report any issues you may find, but please keep in mind that it may have some
rough edges.
As this version of sqlite3 was compiled with a custom VFS, you can't re-use the WebAssembly module from sql.js.
Instead, grab a sqlite3.wasm file from the [releases](https://github.com/simolus3/sqlite3.dart/releases) of the

View File

@ -1,16 +1,13 @@
/// A (very!) experimental web-compatible version of drift that doesn't depend
/// An experimental web-compatible version of drift that doesn't depend
/// on external JavaScript sources.
///
/// This library is highly experimental and not production readdy at the moment.
/// It exists for development and testing purposes for interested users.
/// While the implementation is tested and no API breaking changes are expected
/// to the public interface, it is still fairly new and may have remaining bugs
/// or issues.
///
/// While this library is marked as [experimental], it is not subject to
/// semantic versioning. Future drift updates with a minor update might break
/// APIs defined in this package or change the way data is persisted in
/// backwards-incompatible ways.
///
/// To use drift on the web, use the `package:drift/web.dart` library as
/// described in the [documentation](https://drift.simonbinder.eu/web/).
/// A generally less efficient, but currently more stable backend is available
/// through the `package:drift/web.dart` library described in the
/// [documentation][https://drift.simonbinder.eu/web/].
@experimental
library drift.wasm;
@ -32,7 +29,10 @@ typedef WasmDatabaseSetup = void Function(CommonDatabase database);
/// database.
///
/// Using this database requires adding a WebAssembly file for sqlite3 to your
/// app. Details for that are available [here](https://github.com/simolus3/sqlite3.dart/).
/// app.
/// The [documentation](https://drift.simonbinder.eu/web/#drift-wasm) describes
/// how to obtain this file. A [working example](https://github.com/simolus3/drift/blob/04539882330d80519128fec1ceb120fb1623a831/examples/app/lib/database/connection/web.dart#L27-L36)
/// is also available in the drift repository.
class WasmDatabase extends DelegatedDatabase {
WasmDatabase._(DatabaseDelegate delegate, bool logStatements)
: super(delegate, isSequential: true, logStatements: logStatements);