floor
floor copied to clipboard
GENERATED CODE _$AppDatabaseBuilder support database path
Migrating from Android to flutter In order to be compatible, I need to specify the file of the database
Future<String> getDatabasePath(String userId) async {
Directory dir = await getApplicationSupportDirectory();
File file = new File('${dir.path}/user/$userId/data.db');
return Future.value(file.path);
}
but floor _$AppDatabaseBuilder only use database name. so I manually modify code file
Future<AppDatabase> database() async {
if (mDatabase == null) {
String path = await getDatabasePath(userId);
final database = $AppDatabase();
database.database = await database.open(
path,
[],
null,
);
mDatabase = database;
}
return Future.value(mDatabase!);
}
Hope to add this feature .
If it is a desktop platform:
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
void main() {
databaseFactoryFfi.setDatabasesPath(db_path);
}