Skip to content

Initializing databse ASAP #3050

Answered by simolus3
Abbos27 asked this question in Q&A
Discussion options

You must be logged in to vote

NativeDatabase.createInBackground also uses another LazyDatabase 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:

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;
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Abbos27
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