fix: Linux database

This commit is contained in:
Christian Pauly 2020-10-04 18:21:56 +02:00
parent 7ec349b980
commit 772ff33d8e

View File

@ -2,6 +2,7 @@ import 'dart:ffi';
import 'dart:io'; import 'dart:io';
import 'dart:isolate'; import 'dart:isolate';
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart' show getDatabasesPath; import 'package:sqflite/sqflite.dart' show getDatabasesPath;
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -64,22 +65,17 @@ Future<Database> constructDb(
final isolate = (await receivePort.first as MoorIsolate); final isolate = (await receivePort.first as MoorIsolate);
return Database.connect(await isolate.connect()); return Database.connect(await isolate.connect());
} else if (Platform.isLinux) { } else if (Platform.isLinux) {
debugPrint('[Moor] using desktop moor'); debugPrint('[Moor] using Linux desktop moor');
open.overrideFor(OperatingSystem.linux, _openOnLinux); final appDocDir = await getApplicationSupportDirectory();
return Database(moor.VmDatabase.memory()); return Database(moor.VmDatabase(File('${appDocDir.path}/$filename')));
} else if (Platform.isWindows) { } else if (Platform.isWindows) {
debugPrint('[Moor] using desktop moor'); debugPrint('[Moor] using Windows desktop moor');
open.overrideFor(OperatingSystem.linux, _openOnWindows); open.overrideFor(OperatingSystem.windows, _openOnWindows);
return Database(moor.VmDatabase.memory()); return Database(moor.VmDatabase.memory());
} }
throw Exception('Platform not supported'); throw Exception('Platform not supported');
} }
DynamicLibrary _openOnLinux() {
final libraryNextToScript = File('/usr/lib/x86_64-linux-gnu/libsqlite3.so');
return DynamicLibrary.open(libraryNextToScript.path);
}
DynamicLibrary _openOnWindows() { DynamicLibrary _openOnWindows() {
final script = File(Platform.script.toFilePath()); final script = File(Platform.script.toFilePath());
final libraryNextToScript = File('${script.path}/sqlite3.dll'); final libraryNextToScript = File('${script.path}/sqlite3.dll');