-
Hi
Thanks My code: @DriftDatabase(
tables: [..........],
)
class Database extends _$Database {
Database() : super(_openConnection());
@override
int get schemaVersion => _version;
@override
MigrationStrategy get migration => MigrationStrategy(
beforeOpen: (details) async {
await customStatement('PRAGMA foreign_keys = ON');
},
);
}
LazyDatabase _openConnection() {
return LazyDatabase(() async {
final dbFolder = await getApplicationDocumentsDirectory();
final file = File(path.join(dbFolder.path, _fileName));
return NativeDatabase(file, logStatements: kDebugMode);
});
} My dependencies: ...
path_provider: ^2.0.8
path: ^1.8.0
drift: ^1.2.0
...
drift_dev: ^1.2.0
build_runner: ^2.1.7 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can't use
I don't see why there should be a performance benefit. You binary size will certainly reduce (by around ~700 KiB when using app bundles). But when accessing the OS library through platform channels (which is necessary on Android), the overhead of serialization makes things much slower. This doesn't really matter for most apps, but a
The first one is not a concern anymore (since we can't load the library shipped with the OS at all), the second should also be fine (IIRC Android configures sqlite3 to take care of that automatically). |
Beta Was this translation helpful? Give feedback.
You can't use
dart:ffi
(or aNativeDatabase
) to access the sqlite3 library that comes with the operating system (well, at least not since Android 7). It's possible on iOS, but on Android you'd have to go through the Java APIs. Even when using drift, you can use the moor_flutter package to usesqflite
as a drift backend.sqflite
uses the Java APIs internally.I don't see why there should be a performance benefit. You binary size will certainly reduce (by around ~700 KiB when using app bundles). But when accessing the OS library through platform channels (which is necessary on Android), the overhead of serializat…