mirror of https://github.com/AMT-Cheif/drift.git
Remove outdated warnings about drift/wasm
This commit is contained in:
parent
023512cae3
commit
a6bdd26c93
|
@ -5,17 +5,18 @@ import 'package:sqlite3/wasm.dart';
|
||||||
|
|
||||||
QueryExecutor connect() {
|
QueryExecutor connect() {
|
||||||
return LazyDatabase(() async {
|
return LazyDatabase(() async {
|
||||||
// Load wasm bundle
|
// Create virtual filesystem for sqlite3 implemented over blobs stored in an
|
||||||
final response = await http.get(Uri.parse('sqlite3.wasm'));
|
// IndexedDB database (named `my_app` here).
|
||||||
// Create a virtual file system backed by IndexedDb with everything in
|
|
||||||
// `/drift/my_app/` being persisted.
|
|
||||||
final fs = await IndexedDbFileSystem.open(dbName: 'my_app');
|
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(
|
final sqlite3 = await WasmSqlite3.load(
|
||||||
response.bodyBytes,
|
response.bodyBytes,
|
||||||
SqliteEnvironment(fileSystem: fs),
|
SqliteEnvironment(fileSystem: fs),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Then, open a database inside that persisted folder.
|
// Then, open a database:
|
||||||
return WasmDatabase(sqlite3: sqlite3, path: '/drift/my_app/app.db');
|
return WasmDatabase(sqlite3: sqlite3, path: '/app.db');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ You can grab the latest version of `sql-wasm.js` and `sql-wasm.wasm` [here](http
|
||||||
and copy them into your `web` folder.
|
and copy them into your `web` folder.
|
||||||
|
|
||||||
A full example that works on the web (and all other platforms) is available
|
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
|
## 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.
|
||||||
|
@ -272,15 +272,16 @@ You can pass that DatabaseConnection to your database by enabling the `generate_
|
||||||
|
|
||||||
## New web backend {#drift-wasm}
|
## 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.
|
This approach enables optimizations making this backend more efficient that the existing web version of drift.
|
||||||
It binds to a sqlite3 WebAssembly module directly, without requireing an external JavaScript library.
|
However, it should be noted that this backend is much newer and may potentially be less stable at the moment.
|
||||||
Unlike sql.js, which uses Emscripten, the new backend uses a custom [sqlite3 VFS](https://www.sqlite.org/vfs.html)
|
We encourage you to use it and report any issues you may find, but please keep in mind that it may have some
|
||||||
and doesn't require any dependencies apart from sqlite3 itself.
|
rough edges.
|
||||||
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.
|
|
||||||
|
|
||||||
As this version of sqlite3 was compiled with a custom VFS, you can't re-use the WebAssembly module from sql.js.
|
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
|
Instead, grab a sqlite3.wasm file from the [releases](https://github.com/simolus3/sqlite3.dart/releases) of the
|
||||||
|
|
|
@ -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.
|
/// on external JavaScript sources.
|
||||||
///
|
///
|
||||||
/// This library is highly experimental and not production readdy at the moment.
|
/// While the implementation is tested and no API breaking changes are expected
|
||||||
/// It exists for development and testing purposes for interested users.
|
/// 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
|
/// A generally less efficient, but currently more stable backend is available
|
||||||
/// semantic versioning. Future drift updates with a minor update might break
|
/// through the `package:drift/web.dart` library described in the
|
||||||
/// APIs defined in this package or change the way data is persisted in
|
/// [documentation][https://drift.simonbinder.eu/web/].
|
||||||
/// 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/).
|
|
||||||
@experimental
|
@experimental
|
||||||
library drift.wasm;
|
library drift.wasm;
|
||||||
|
|
||||||
|
@ -32,7 +29,10 @@ typedef WasmDatabaseSetup = void Function(CommonDatabase database);
|
||||||
/// database.
|
/// database.
|
||||||
///
|
///
|
||||||
/// Using this database requires adding a WebAssembly file for sqlite3 to your
|
/// 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 {
|
class WasmDatabase extends DelegatedDatabase {
|
||||||
WasmDatabase._(DatabaseDelegate delegate, bool logStatements)
|
WasmDatabase._(DatabaseDelegate delegate, bool logStatements)
|
||||||
: super(delegate, isSequential: true, logStatements: logStatements);
|
: super(delegate, isSequential: true, logStatements: logStatements);
|
||||||
|
|
Loading…
Reference in New Issue