Hello all, I'm trying to setup SQLDelight for a Co...
# squarelibraries
h
Hello all, I'm trying to setup SQLDelight for a Compose project (Kotlin). When I follow the website I'm getting stuck at configuring the database. I have done the following: 1. imported the gradle plugin
Copy code
plugins {
    kotlin("jvm") version "1.5.31"
    id("org.jetbrains.compose") version "1.0.0-beta5"
    id("com.squareup.sqldelight") version "1.5.2"
}
2. added the driver dependency
Copy code
dependencies {
    implementation(compose.desktop.currentOs)
    implementation("com.squareup.sqldelight:sqlite-driver:1.5.2")

    testImplementation(kotlin("test"))
}
3. now I'm trying to add the configuration for the gradle-plugin
Copy code
sqldelight {
  Database { // This will be the name of the generated database class.
    packageName = "com.example"
  }
}
But I get error
Copy code
sqldelight {
    sqldelight.com.squareup.sqlite.migrations.Database {

    }
}
The error:
Copy code
build.gradle.kts:47:16: Unresolved reference: com
SQLDelight Gradle plugin was applied but there are no databases set up.
Seems like I'm not able to add Database like that (com is pointing out to the package name and marked red in my Intellij). If I remove the package name (sqldelight.
com
.squareup.sqlite.migrations) it does not work. Hope someone can help me out with this?
m
Looks like you're using
build.gradle.kts
? If that's the case, use
database("Database")
instead
👀 1
(I edited
create
by
database
above)
h
What do I need to pass as second parameter?
m
Does it need 2?
Ah a closure lambda
Copy code
sqldelight {
  database("Database") {
    packageName = "com.example"
  }
}
h
Ach yes.. true..
s
We should add kotlin code snippets to the documentation. Wanna send a PR @Humphrey considering you just went through this?
🙏 1
h
Good point. I got it working now! Will look at it tomorrow (PR). Now I'm interested on what's the best way to unit-test, and encapsulate the database behind an Repository and (possible use it in a service) from the Compose UI. I have SpringBoot experience but I am new to Compose.
s
there are some tests in the sample app that you can take a look at.
I've also got some tests in https://github.com/saket/press
303 Views