mirror of https://github.com/AMT-Cheif/drift.git
Initializer for web databases (#328)
This commit is contained in:
parent
d0cb2eec37
commit
83a3344719
|
@ -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
|
||||||
|
AAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAA
|
||||||
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
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;
|
||||||
|
}
|
|
@ -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>
|
|
@ -18,6 +18,7 @@
|
||||||
- Reduce unnecessary queries when a stream is unsubscribed and then re-subscribed ([#329](https://github.com/simolus3/moor/issues/329))
|
- 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
|
- 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/)
|
`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
|
## 2.2.0
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,16 @@ class SqlJsDatabase {
|
||||||
final JsObject _obj;
|
final JsObject _obj;
|
||||||
SqlJsDatabase._(this._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
|
/// Calls `prepare` on the underlying js api
|
||||||
PreparedStatement prepare(String sql) {
|
PreparedStatement prepare(String sql) {
|
||||||
final obj = _obj.callMethod('prepare', [sql]) as JsObject;
|
final obj = _obj.callMethod('prepare', [sql]) as JsObject;
|
||||||
|
@ -97,12 +107,14 @@ class SqlJsDatabase {
|
||||||
/// [export].
|
/// [export].
|
||||||
int lastInsertId() {
|
int lastInsertId() {
|
||||||
// load insert id. Will return [{columns: [...], values: [[id]]}]
|
// load insert id. Will return [{columns: [...], values: [[id]]}]
|
||||||
final results = _obj
|
return _selectSingleRowAndColumn('SELECT last_insert_rowid();') as int;
|
||||||
.callMethod('exec', const ['SELECT last_insert_rowid();']) as JsArray;
|
}
|
||||||
|
|
||||||
|
dynamic _selectSingleRowAndColumn(String sql) {
|
||||||
|
final results = _obj.callMethod('exec', [sql]) as JsArray;
|
||||||
final row = results.first as JsObject;
|
final row = results.first as JsObject;
|
||||||
final data = (row['values'] as JsArray).first as JsArray;
|
final data = (row['values'] as JsArray).first as JsArray;
|
||||||
|
return data.first;
|
||||||
return data.first as int;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs `export` on the underlying js api
|
/// Runs `export` on the underlying js api
|
||||||
|
|
|
@ -1,23 +1,33 @@
|
||||||
part of 'package:moor/moor_web.dart';
|
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
|
/// Experimental moor backend for the web. To use this platform, you need to
|
||||||
/// include the latest version of `sql.js` in your html.
|
/// include the latest version of `sql.js` in your html.
|
||||||
class WebDatabase extends DelegatedDatabase {
|
class WebDatabase extends DelegatedDatabase {
|
||||||
/// A database executor that works on the web.
|
/// 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);
|
logStatements: logStatements, isSequential: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _WebDelegate extends DatabaseDelegate {
|
class _WebDelegate extends DatabaseDelegate {
|
||||||
final String name;
|
final String name;
|
||||||
|
final CreateWebDatabase initializer;
|
||||||
SqlJsDatabase _db;
|
SqlJsDatabase _db;
|
||||||
|
|
||||||
String get _persistenceKey => 'moor_db_str_$name';
|
String get _persistenceKey => 'moor_db_str_$name';
|
||||||
|
|
||||||
bool _inTransaction = false;
|
bool _inTransaction = false;
|
||||||
|
|
||||||
_WebDelegate(this.name);
|
_WebDelegate(this.name, this.initializer);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
set isInTransaction(bool value) {
|
set isInTransaction(bool value) {
|
||||||
|
@ -33,10 +43,12 @@ class _WebDelegate extends DatabaseDelegate {
|
||||||
bool get isInTransaction => _inTransaction;
|
bool get isInTransaction => _inTransaction;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final TransactionDelegate transactionDelegate = const NoTransactionDelegate();
|
TransactionDelegate get transactionDelegate => const NoTransactionDelegate();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
DbVersionDelegate get versionDelegate => _WebVersionDelegate(name);
|
DbVersionDelegate get versionDelegate =>
|
||||||
|
_versionDelegate ??= _WebVersionDelegate(this);
|
||||||
|
DbVersionDelegate _versionDelegate;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get isOpen => _db != null;
|
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');
|
assert(dbVersion >= 1, 'Database schema version needs to be at least 1');
|
||||||
|
|
||||||
final module = await initSqlJs();
|
final module = await initSqlJs();
|
||||||
final restored = _restoreDb();
|
var restored = _restoreDb();
|
||||||
|
|
||||||
|
if (restored == null && initializer != null) {
|
||||||
|
restored = await initializer();
|
||||||
|
_storeData(restored);
|
||||||
|
}
|
||||||
|
|
||||||
_db = module.createDatabase(restored);
|
_db = module.createDatabase(restored);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,23 +156,31 @@ class _WebDelegate extends DatabaseDelegate {
|
||||||
|
|
||||||
void _storeDb() {
|
void _storeDb() {
|
||||||
if (!isInTransaction) {
|
if (!isInTransaction) {
|
||||||
final data = _db.export();
|
_storeData(_db.export());
|
||||||
final binStr = bin2str.encode(data);
|
|
||||||
window.localStorage[_persistenceKey] = binStr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _storeData(Uint8List data) {
|
||||||
|
final binStr = bin2str.encode(data);
|
||||||
|
window.localStorage[_persistenceKey] = binStr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _WebVersionDelegate extends DynamicVersionDelegate {
|
class _WebVersionDelegate extends DynamicVersionDelegate {
|
||||||
String get _versionKey => 'moor_db_version_$name';
|
String get _versionKey => 'moor_db_version_${delegate.name}';
|
||||||
final String 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
|
@override
|
||||||
Future<int> get schemaVersion async {
|
Future<int> get schemaVersion async {
|
||||||
if (!window.localStorage.containsKey(_versionKey)) {
|
if (!window.localStorage.containsKey(_versionKey)) {
|
||||||
return null;
|
return delegate._db?.userVersion;
|
||||||
}
|
}
|
||||||
final versionStr = window.localStorage[_versionKey];
|
final versionStr = window.localStorage[_versionKey];
|
||||||
|
|
||||||
|
@ -163,6 +189,7 @@ class _WebVersionDelegate extends DynamicVersionDelegate {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setSchemaVersion(int version) {
|
Future<void> setSchemaVersion(int version) {
|
||||||
|
delegate._db.userVersion = version;
|
||||||
window.localStorage[_versionKey] = version.toString();
|
window.localStorage[_versionKey] = version.toString();
|
||||||
return Future.value();
|
return Future.value();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue