drift/examples/web_worker_example/web/worker.dart

20 lines
540 B
Dart
Raw Normal View History

2021-01-31 12:50:12 -08:00
import 'dart:html';
2021-10-08 14:33:39 -07:00
import 'package:drift/drift.dart';
import 'package:drift/web.dart';
import 'package:drift/remote.dart';
2021-01-31 12:50:12 -08:00
void main() {
final self = SharedWorkerGlobalScope.instance;
self.importScripts('sql-wasm.js');
2021-10-08 14:33:39 -07:00
final db = WebDatabase.withStorage(DriftWebStorage.indexedDb('worker',
2021-01-31 12:50:12 -08:00
migrateFromLocalStorage: false, inWebWorker: true));
final server = DriftServer(DatabaseConnection(db));
2021-01-31 12:50:12 -08:00
self.onConnect.listen((event) {
final msg = event as MessageEvent;
server.serve(msg.ports.first.channel());
});
}