glp-companion/lib/core/database/connection/web.dart

21 lines
761 B
Dart

import 'package:drift/drift.dart';
import 'package:drift/wasm.dart';
/// Opens the browser database via SQLite compiled to WebAssembly.
///
/// SQLCipher cannot run in the browser, so web builds persist an unencrypted
/// database in OPFS/IndexedDB. [WasmDatabase.open] expects `sqlite3.wasm`
/// (from the `sqlite3.dart` releases) and `drift_worker.js` (from the drift
/// releases) to be copied into the `web/` directory of the Flutter host
/// project.
QueryExecutor openDatabaseConnection() {
return LazyDatabase(() async {
final result = await WasmDatabase.open(
databaseName: 'glp1_companion',
sqlite3Uri: Uri.parse('sqlite3.wasm'),
driftWorkerUri: Uri.parse('drift_worker.js'),
);
return result.resolvedExecutor;
});
}