-
I want to initialize my database as soon as possible, not lazily. Can I directly call NativeDatabase.createInBackground(file) and pass it to the super constructor of GeneratedDatabase? |
Beta Was this translation helpful? Give feedback.
Answered by
simolus3
Jun 13, 2024
Replies: 1 comment
-
Future<YourDatabaseClass> loadInitializedDatabase() async {
final database = YourDatabaseClass(LazyDatabase(...));
await database.customSelect('SELECT 1').get(); // run a statement, forcing the database to be initialized
return database;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Abbos27
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NativeDatabase.createInBackground
also uses anotherLazyDatabase
internally - it has to because it needs to spawn an isolate and setup a communication channel with it to actually use the database. The most reliable way to initialize the database right away is to use it, e.g. like this: