Last active
August 20, 2024 09:01
-
-
Save binayshaw7777/1eadc9afaaaa3757c2ef44e0d8d34ca2 to your computer and use it in GitHub Desktop.
iOS 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/iosMain/kotlin/database/Database.kt | |
| import androidx.room.Room | |
| import androidx.room.RoomDatabase | |
| import data.database.UserDatabase | |
| import data.database.instantiateImpl // This shall show error, ignore it | |
| import platform.Foundation.NSHomeDirectory // This shall too in Windows. | |
| fun getUserDatabase(): RoomDatabase.Builder<UserDatabase> { | |
| val dbFile = NSHomeDirectory() + "/user.db" | |
| return Room.databaseBuilder<UserDatabase>( | |
| name = dbFile, | |
| factory = { UserDatabase::class.instantiateImpl() } // This too will show error | |
| ) | |
| .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
i am not able to get "import platform.Foundation.NSHomeDirectory " this import