8000 [Web] Drift not persisting db changes · Issue #3568 · simolus3/drift · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Web] Drift not persisting db changes #3568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zkrige opened this issue May 21, 2025 · 2 comments
Open

[Web] Drift not persisting db changes #3568

zkrige opened this issue May 21, 2025 · 2 comments

Comments

@zkrige
Copy link
zkrige commented May 21, 2025
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?

@simolus3
Copy link
Owner

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?

@zkrige
Copy link
Author
zkrige commented May 22, 2025

Using WasmStorageImplementation.sharedIndexedDb due to missing browser features: {MissingBrowserFeature.dedicatedWorkersInSharedWorkers, MissingBrowserFeature.sharedArrayBuffers}

flutter run -d chrome --web-port 5555

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0