floor icon indicating copy to clipboard operation
floor copied to clipboard

feat: add external path support

Open lucasdidur opened this issue 1 year ago • 3 comments

Add support for Floor to set a external path to load/save database. App need to have storage permission managed by Permissions Manager.

  Future<AppDatabase> get appDatabase async {
    String externalPath = await ExternalPath.getExternalStoragePublicDirectory(
      ExternalPath.DIRECTORY_DOCUMENTS,
    );
    var dir = Directory(p.join(externalPath, 'My App'));
    if (!dir.existsSync()) {
      dir.create(recursive: true);
    }

    return $FloorAppDatabase.databaseBuilder(p.join(dir.path, DATABASE_NAME)).build();
  }

lucasdidur avatar Apr 03 '24 15:04 lucasdidur

I like this PR. For most apps, the database should probably not be stored where this package wants to store it - path_provider.getApplicationSupportDirectory() would be better in most cases. The sqflite documentation says as much, and suggests not using getDatabasesPath() in favour of using path_provider directly, and constructing your own database path to pass into the API.

ryanheise avatar Jul 01 '24 11:07 ryanheise

@stephanmantel Seems good to enough to merge. What do you think?

dfdgsdfg avatar Sep 27 '24 06:09 dfdgsdfg

Actually, you can just do this:

sqfliteDatabaseFactory.setDatabasesPath(...);

ryanheise avatar Nov 24 '24 03:11 ryanheise