openConnection function

DatabaseConnection openConnection()

Implementation

DatabaseConnection openConnection() {
  // Use a delayed connection to asynchronously load sqlite3.wasm and the drift worker.
  return DatabaseConnection.delayed(
    Future(() async {
      const workerJs = kReleaseMode ? 'worker.dart.min.js' : 'worker.dart.js';
      final opened = await WasmDatabase.open(
        databaseName: 'remote_cache_sync', // prefer simple identifiers
        sqlite3Uri: Uri.parse('sqlite3.wasm'),
        driftWorkerUri: Uri.parse(workerJs),
      );
      if (opened.missingFeatures.isNotEmpty) {
        // Consider surfacing this to the user if persistence is critical.
        // e.g., Safari Private Mode may fall back to in-memory storage.
        // ignore: avoid_print
        print(
          'Drift(web) missing features: ${opened.missingFeatures}. '
          'Using ${opened.chosenImplementation}.',
        );
      }
      return opened.resolvedExecutor;
    }),
  );
}