Skip to content

How do I use a pre-populated sqlite db on flutter web with drift? #2870

Answered by ehtiqamar
ehtiqamar asked this question in Q&A
Discussion options

You must be logged in to vote

I've used this code to load my existing db on web:

DatabaseConnection connect() {
  return DatabaseConnection.delayed(Future(() async {
    final db = await WasmDatabase.open(
      databaseName: 'sqlite',
      sqlite3Uri: Uri.parse('sqlite3.wasm'),
      driftWorkerUri: Uri.parse('drift_worker.js'),
      initializeDatabase: () async {
        logger.d("initializeDatabase: Initializing web db");

        Uint8List? oldDatabase;

        final blob = await rootBundle.load('assets/sqlite.db');
        final buffer = blob.buffer;
        oldDatabase =
            buffer.asUint8List(blob.offsetInBytes, blob.lengthInBytes);
        logger.d("Old Database: $oldDatabase");
        return oldDa…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@ehtiqamar
Comment options

@ehtiqamar
Comment options

Answer selected by simolus3
@simolus3
Comment options

@ehtiqamar
Comment options

@ehtiqamar
Comment options

@simolus3
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants