Initializer for web databases (#328)

This commit is contained in:
Simon Binder 2020-01-18 12:26:47 +01:00
parent d0cb2eec37
commit 83a3344719
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 280 additions and 17 deletions

View File

@ -0,0 +1,211 @@
import 'dart:convert';
import 'package:moor/moor_web.dart';
import 'package:test/test.dart';
// Created from an empty sqlite file with
// `CREATE TABLE foo (name TEXT)`
// `INSERT INTO foo ('hello world')`
const _rawDataBase64 = '''
U1FMaXRlIGZvcm1hdCAzABAAAQEAQCAgAAAAAgAAAAIAAAAAAAAAAAAAAAEAAAAE
AAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC
AC478Q0AAAABD9AAD9AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAA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AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAANAQIjaGVsbG8gd29ybGQ=
''';
void main() {
test('can initialize database when absent', () async {
var didCallInitializer = false;
final db = WebDatabase('name', initializer: () async {
didCallInitializer = true;
return base64.decode(_rawDataBase64.replaceAll('\n', ''));
});
db.databaseInfo = _FakeDatabase(db);
await db.ensureOpen();
expect(didCallInitializer, isTrue);
final result = await db.runSelect('SELECT * FROM foo', const []);
expect(result, [
{'name': 'hello world'}
]);
});
}
class _FakeDatabase extends GeneratedDatabase {
_FakeDatabase(QueryExecutor executor)
: super(const SqlTypeSystem.withDefaults(), executor);
@override
Iterable<TableInfo<Table, DataClass>> get allTables => const [];
@override
int get schemaVersion => 1;
}

View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="x-dart-test" href="initializer_test.dart">
<script src="sql-wasm.js"></script>
<script src="packages/test/dart.js"></script>
</head>
<body>
</body>
</html>

View File

@ -18,6 +18,7 @@
- Reduce unnecessary queries when a stream is unsubscribed and then re-subscribed ([#329](https://github.com/simolus3/moor/issues/329))
- Experimental new type inference for the sql analyzer. For details, check the
`use_experimental_inference` [build option](https://moor.simonbinder.eu/docs/advanced-features/builder_options/)
- Web: New `initializer` parameter to provide the database when it doesn't exist
## 2.2.0

View File

@ -70,6 +70,16 @@ class SqlJsDatabase {
final JsObject _obj;
SqlJsDatabase._(this._obj);
/// Returns the `user_version` pragma from sqlite.
int get userVersion {
return _selectSingleRowAndColumn('PRAGMA user_version;') as int;
}
/// Sets sqlite's `user_version` pragma to the specified [version].
set userVersion(int version) {
run('PRAGMA user_version = $version');
}
/// Calls `prepare` on the underlying js api
PreparedStatement prepare(String sql) {
final obj = _obj.callMethod('prepare', [sql]) as JsObject;
@ -97,12 +107,14 @@ class SqlJsDatabase {
/// [export].
int lastInsertId() {
// load insert id. Will return [{columns: [...], values: [[id]]}]
final results = _obj
.callMethod('exec', const ['SELECT last_insert_rowid();']) as JsArray;
return _selectSingleRowAndColumn('SELECT last_insert_rowid();') as int;
}
dynamic _selectSingleRowAndColumn(String sql) {
final results = _obj.callMethod('exec', [sql]) as JsArray;
final row = results.first as JsObject;
final data = (row['values'] as JsArray).first as JsArray;
return data.first as int;
return data.first;
}
/// Runs `export` on the underlying js api

View File

@ -1,23 +1,33 @@
part of 'package:moor/moor_web.dart';
/// Signature of a function that asynchronously initializes a web database if it
/// doesn't exist.
/// The bytes returned should represent a valid sqlite3 database file.
typedef CreateWebDatabase = Future<Uint8List> Function();
/// Experimental moor backend for the web. To use this platform, you need to
/// include the latest version of `sql.js` in your html.
class WebDatabase extends DelegatedDatabase {
/// A database executor that works on the web.
WebDatabase(String name, {bool logStatements = false})
: super(_WebDelegate(name),
///
/// [name] can be used to identify multiple databases. The optional
/// [initializer] can be used to initialize the database if it doesn't exist.
WebDatabase(String name,
{bool logStatements = false, CreateWebDatabase initializer})
: super(_WebDelegate(name, initializer),
logStatements: logStatements, isSequential: true);
}
class _WebDelegate extends DatabaseDelegate {
final String name;
final CreateWebDatabase initializer;
SqlJsDatabase _db;
String get _persistenceKey => 'moor_db_str_$name';
bool _inTransaction = false;
_WebDelegate(this.name);
_WebDelegate(this.name, this.initializer);
@override
set isInTransaction(bool value) {
@ -33,10 +43,12 @@ class _WebDelegate extends DatabaseDelegate {
bool get isInTransaction => _inTransaction;
@override
final TransactionDelegate transactionDelegate = const NoTransactionDelegate();
TransactionDelegate get transactionDelegate => const NoTransactionDelegate();
@override
DbVersionDelegate get versionDelegate => _WebVersionDelegate(name);
DbVersionDelegate get versionDelegate =>
_versionDelegate ??= _WebVersionDelegate(this);
DbVersionDelegate _versionDelegate;
@override
bool get isOpen => _db != null;
@ -47,7 +59,13 @@ class _WebDelegate extends DatabaseDelegate {
assert(dbVersion >= 1, 'Database schema version needs to be at least 1');
final module = await initSqlJs();
final restored = _restoreDb();
var restored = _restoreDb();
if (restored == null && initializer != null) {
restored = await initializer();
_storeData(restored);
}
_db = module.createDatabase(restored);
}
@ -138,23 +156,31 @@ class _WebDelegate extends DatabaseDelegate {
void _storeDb() {
if (!isInTransaction) {
final data = _db.export();
final binStr = bin2str.encode(data);
window.localStorage[_persistenceKey] = binStr;
_storeData(_db.export());
}
}
void _storeData(Uint8List data) {
final binStr = bin2str.encode(data);
window.localStorage[_persistenceKey] = binStr;
}
}
class _WebVersionDelegate extends DynamicVersionDelegate {
String get _versionKey => 'moor_db_version_$name';
final String name;
String get _versionKey => 'moor_db_version_${delegate.name}';
_WebVersionDelegate(this.name);
final _WebDelegate delegate;
_WebVersionDelegate(this.delegate);
// Note: Earlier moor versions used to store the database version in a special
// field in local storage (moor_db_version_<name>). Since 2.3, we instead use
// the user_version pragma, but still need to keep backwards compatibility.
@override
Future<int> get schemaVersion async {
if (!window.localStorage.containsKey(_versionKey)) {
return null;
return delegate._db?.userVersion;
}
final versionStr = window.localStorage[_versionKey];
@ -163,6 +189,7 @@ class _WebVersionDelegate extends DynamicVersionDelegate {
@override
Future<void> setSchemaVersion(int version) {
delegate._db.userVersion = version;
window.localStorage[_versionKey] = version.toString();
return Future.value();
}