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

14 Views Asked by At

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?

1

There are 1 best solutions below

0
aismael On

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.