How to use in-memory database with existing database for testing #2963
Unanswered
dhemasnurjaya
asked this question in
Q&A
Replies: 1 comment
-
I'm not aware of a way to construct an in-memory database from the underlying bytes. So unfortunately it looks like creating a temporary file, copying the asset into that and then opening that as a database is the only way to go about this. If the constant writing and deleting for each test is a problem, you can perhaps solve the issue by only writing the database to disk once (and not deleting it after every test). Because once the database is on disk, you can create an in-memory copy of it: return LazyDatabase(() async {
final reference = sqlite3.open(dbFile.path);
final copy = sqlite3.openInMemory();
await reference.backup(copy, -1).drain();
return NativeDatabase.opened(copy);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm writing an integration test and I need to load my existing database (from assets) into in-memory database. How can I achieve this? For now I use a regular file then delete it in tearDown for workaround. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions