I hope u will update documentation about embedding existing database assets into project.
Besides, I prefer using only moor things to do it.
_Originally posted by @KaungZawHtet in https://github.com/simolus3/moor/issues/26#issuecomment-517244493_
Any update on this issue ? I m trying to add existing database asset at assets/data/mydb.sqlite3 and failed. If we can do this, we can work with third party sqlite clients too leading to faster development.
Sorry for the delay, I'll try integrate proper support for that either this or next week to make this easier.
Until then, maybe you could use something like this setup to open the database, assuming your database file is called "app.db"
getDatabasesPath from sqflite directly. Then, you could use join(dbPath, 'app.db') to get the location where moor expects the database file to be.FlutterQueryExecutor.inDatabasePath('app.db')It works now. Point was that task of loading database asset needs to be created first before moor's Database obj is created. Thx for the reply
We now have some utils to make this easier on develop - the FlutterQueryExecutor takes a new parameter called creator which can create the database when it doesn't exist. Loading a database from an asset could be done with
https://github.com/simolus3/moor/blob/925f80aa9f35f00435d7cc8956c291df6abfceef/extras/integration_tests/flutter_db/lib/main.dart#L36-L44
Most helpful comment
We now have some utils to make this easier on
develop- theFlutterQueryExecutortakes a new parameter calledcreatorwhich can create the database when it doesn't exist. Loading a database from an asset could be done withhttps://github.com/simolus3/moor/blob/925f80aa9f35f00435d7cc8956c291df6abfceef/extras/integration_tests/flutter_db/lib/main.dart#L36-L44