drift
drift copied to clipboard
[Web] Drift not persisting db changes
Future<QueryExecutor> openConnection() async {
final executor = driftDatabase(
name: 'database',
native: DriftNativeOptions(
databaseDirectory: () async => await getApplicationSupportDirectory(),
),
web: DriftWebOptions(
sqlite3Wasm: Uri.parse('sqlite3.wasm'),
driftWorker: Uri.parse('drift_worker.js'),
onResult: (result) {
if (result.missingFeatures.isNotEmpty) {
debugPrint('Drift fallback: ${result.missingFeatures}');
}
},
),
);
return executor.interceptWith(LogInterceptor());
}
class AppDatabase extends _$AppDatabase {
static AppDatabase? _instance;
AppDatabase._internal(super.e);
/// Initializes the singleton instance. Must be called once before using [getInstance].
static void init({required QueryExecutor executor}) {
if (_instance != null) return;
_instance = AppDatabase._internal(executor);
}
final connection = await openConnection();
AppDatabase.init(executor: connection);
await _database.delete(_database.users).go();
_database.select(_database.users).getSingleOrNull();
this shows the db is empty.
But, when I close my browser and run my app again,
_database.select(_database.users).getSingleOrNull();
returns a record
How do I prevent this from happening?
What does the Drift fallback line print? Could you also print the result.chosenImplementation?
How are you running the app, with flutter run or is this a built application?
Using WasmStorageImplementation.sharedIndexedDb due to missing browser features: {MissingBrowserFeature.dedicatedWorkersInSharedWorkers, MissingBrowserFeature.sharedArrayBuffers}
flutter run -d chrome --web-port 5555