ffi: Create parent dir to avoid misuse errors (#731)

This commit is contained in:
Simon Binder 2020-08-14 21:57:49 +02:00
parent a2b28945d1
commit ffc01e4516
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,7 @@
- New `DatabaseConnection.delayed` constructor to synchronously obtain a database connection
that requires async setup. This can be useful when connecting to a `MoorIsolate`.
- `VmDatabase`: Create directory of database file to avoid misuse errors from sqlite3.
## 3.3.1

View File

@ -64,6 +64,13 @@ class _VmDelegate extends DatabaseDelegate {
@override
Future<void> open(QueryExecutorUser user) async {
if (file != null) {
// Create the parent directory if it doesn't exist. sqlite will emit
// confusing misuse warnings otherwise
final dir = file.parent;
if (!dir.existsSync()) {
dir.createSync(recursive: true);
}
_db = sqlite3.open(file.path);
} else {
_db = sqlite3.openInMemory();