数据库在Jetpack Compose桌面上

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

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

  1. kotlin {
  2. jvm {
  3. jvmToolchain(Deps.JDK)
  4. withJava()
  5. }
  6. sourceSets {
  7. val commonMain by getting {
  8. dependencies {
  9. implementation(Deps.Koin.CORE)
  10. //Database
  11. with(Deps.SQLDelight) {
  12. implementation(DRIVER)
  13. api(RUNTIME)
  14. api(COROUTINE_EXT)
  15. }
  16. }
  17. }
  18. val jvmMain by getting
  19. }
  20. }
  21. sqldelight {
  22. databases {
  23. create("AppDatabase") {
  24. packageName.set("com.mobiledevpro.database")
  25. }
  26. }
  27. }
  1. object SQLDelight {
  2. const val DRIVER = "app.cash.sqldelight:sqlite-driver:${Versions.SQL_DELIGHT}"
  3. const val RUNTIME = "app.cash.sqldelight:runtime:${Versions.SQL_DELIGHT}"
  4. const val COROUTINE_EXT = "app.cash.sqldelight:coroutines-extensions:${Versions.SQL_DELIGHT}"
  5. }
英文:

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

  1. kotlin {
  2. jvm {
  3. jvmToolchain(Deps.JDK)
  4. withJava()
  5. }
  6. sourceSets {
  7. val commonMain by getting {
  8. dependencies {
  9. implementation(Deps.Koin.CORE)
  10. //Database
  11. with(Deps.SQLDelight) {
  12. implementation(DRIVER)
  13. api(RUNTIME)
  14. api(COROUTINE_EXT)
  15. }
  16. }
  17. }
  18. val jvmMain by getting
  19. }
  20. }
  21. sqldelight {
  22. databases {
  23. create("AppDatabase") {
  24. packageName.set("com.mobiledevpro.database")
  25. }
  26. }
  27. }
  1. object SQLDelight {
  2. const val DRIVER = "app.cash.sqldelight:sqlite-driver:${Versions.SQL_DELIGHT}"
  3. const val RUNTIME = "app.cash.sqldelight:runtime:${Versions.SQL_DELIGHT}"
  4. const val COROUTINE_EXT = "app.cash.sqldelight:coroutines-extensions:${Versions.SQL_DELIGHT}"
  5. }

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:

确定