Search code examples
android-jetpack-composeandroid-sqliteandroid-roomkotlin-multiplatform

I need to keep data on the device with Jetpack compose multiplatform


I am developing an application that will work for both desktop and android with Jetpack compose multiplatform. I am new to multiplatform, I was an android developer before, but I did not need to save data to the device, which database should I use in this regard? And which one should I work with for multiplatform I found room database but usually resources show the installation of android and ios applications for kmp I need installation for desktop I am looking for resource suggestions


Solution

  • for android, you can use old ways in Android development. for desktop and ios you can use this:

    actual class DatabaseImpl : Database { private val db: MyDatabase = MyDatabase( SqlDriver.create() // Initialize SQLDelight database driver for the platform )

    actual override fun insertItem(item: MyEntity) {
        db.myQueries.insertItem(item)
    }
    
    actual override fun getItems(): List<MyEntity> {
        return db.myQueries.selectAllItems().executeAsList()
       }
    }