Created
May 8, 2024 16:05
-
-
Save binayshaw7777/aa943fec06a2ac97964f1dc0126a4d11 to your computer and use it in GitHub Desktop.
Android Database builder for Room KMP/CMP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Save at: composeApp/src/androidMain/kotlin/com/yourOrg/projName/database/Database.kt | |
| import android.content.Context | |
| import androidx.room.Room | |
| import androidx.room.RoomDatabase | |
| import data.database.UserDatabase | |
| fun getUserDatabase(context: Context): RoomDatabase.Builder<UserDatabase> { | |
| val dbFile = context.getDatabasePath("user.db") | |
| return Room.databaseBuilder<UserDatabase>( | |
| context = context.applicationContext, | |
| name = dbFile.absolutePath | |
| ) | |
| .fallbackToDestructiveMigrationOnDowngrade(true) | |
| .setDriver(BundledSQLiteDriver()) // Very important | |
| .setQueryCoroutineContext(Dispatchers.IO) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment