floor icon indicating copy to clipboard operation
floor copied to clipboard

GENERATED CODE _$AppDatabaseBuilder support database path

Open CrazyWalk opened this issue 4 years ago • 1 comments

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 .

CrazyWalk avatar Jul 16 '21 06:07 CrazyWalk

If it is a desktop platform:

import 'package:sqflite_common_ffi/sqflite_ffi.dart';
void main() {
    databaseFactoryFfi.setDatabasesPath(db_path);
}

springeye avatar Oct 09 '21 10:10 springeye