数据库在Jetpack Compose桌面上

huangapple go评论92阅读模式
英文:

Database on Jetpack compose desktop

问题

我正在使用Jetpack Compose Desktop进行开发,但在寻找有关可用于数据库存储的库的最新信息方面遇到了困难。显然,Room不是一个选项。我听说sqldelight是一个选项,但找不到任何关于设置的资源。提前感谢。

英文:

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.

答案1

得分: 0

我在使用Kotlin和Compose UI构建的桌面应用程序中使用SqlDelight。以下是可能对您有帮助的资源:

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}"
    }

英文:

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}"
    }

huangapple
  • 本文由 发表于 2023年8月4日 03:00:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76830948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定