databaseandroid-jetpack-composedesktopsqldelight

Database on Jetpack compose desktop


I'm developing with Jetpack Compose Desktop and having a hard time finding any up to date information on what libraries are available for database storage. Room is obviously not an option. I have heard sqldelight is an option but not able to find any resources for setup. Thanks in advance.


Solution

  • I use SqlDelight in Desktop app build with Kotlin and Compose UI. Here is a resource might help to you as well:

    https://cashapp.github.io/sqldelight/2.0.0/multiplatform_sqlite/

    Build.gradle.kts

    kotlin {
            jvm {
                jvmToolchain(Deps.JDK)
                withJava()
            }
        
            sourceSets {
                val commonMain by getting {
                    dependencies {
                        implementation(Deps.Koin.CORE)
        
                        //Database
                        with(Deps.SQLDelight) {
                            implementation(DRIVER)
                            api(RUNTIME)
                            api(COROUTINE_EXT)
                        }
        
                    }
                }
        
                val jvmMain by getting
            }
        }
        
        sqldelight {
            databases {
                create("AppDatabase") {
                    packageName.set("com.mobiledevpro.database")
                }
            }
        }
    
    
        object SQLDelight {
            const val DRIVER = "app.cash.sqldelight:sqlite-driver:${Versions.SQL_DELIGHT}"
            const val RUNTIME = "app.cash.sqldelight:runtime:${Versions.SQL_DELIGHT}"
            const val COROUTINE_EXT = "app.cash.sqldelight:coroutines-extensions:${Versions.SQL_DELIGHT}"
        }