Skip to content

feat: add external path support - #822

Open
lucasdidur wants to merge 3 commits into
pinchbv:developfrom
lucasdidur:feat/external-db-support
Open

lucasdidur wants to merge 3 commits into
pinchbv:developfrom
lucasdidur:feat/external-db-support

Conversation

@lucasdidur

Copy link
Copy Markdown

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();
  }

@ryanheise

Copy link
Copy Markdown

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.

@dfdgsdfg

Copy link
Copy Markdown

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

@ryanheise

Copy link
Copy Markdown

Actually, you can just do this:

sqfliteDatabaseFactory.setDatabasesPath(...);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants