androidsqldelight

How to use a custom directory for the db in SQLDelight - Android


The default SQLDriver AndroidSqliteDriver(OfflinePersonalDataDb.Schema, context, "test.db") creates the database in a default location:

/data/data/<Your-Application-Package-Name>/databases/test.db

can I change this location?


Solution

  • For future readers, the solution is to supply the absolute path to the name parameter in the constructor of AndroidSqliteDriver:

    AndroidSqliteDriver(OfflinePersonalDataDb.Schema, context, "/storage/emulated/0/Android/data/<package>/files/test.db")
    

    Here, I am giving a path in the SDCard in the emulator.

    Just make sure that your application has the read-write permissions to that location.