is anyone using SQLDelight server side to connect ...
# server
f
is anyone using SQLDelight server side to connect to postgresql that has a working gradle file
đź§µ 2
s
It should be the same for server-side than it’s for any other Gradle project. This is working for me.
Copy code
plugins {
  kotlin("jvm") version "1.6.10"
  id("com.squareup.sqldelight") version "1.5.3"
}

sqldelight {
  database("Database") {
    packageName = "io.github.nomisrev"
    dialect = "postgresql"
  }
}
This is how I am connecting
Copy code
fun Datasource() = HikariConfig().apply {
  jdbcUrl = "jdbc:<postgresql://localhost:5432/databaseName>"
  username = "admin"
  password = "admin"
  driverClassName = "org.postgresql.Driver"
}.let(::HikariDataSource)

val driver: SqlDriver = dataSource.asJdbcDriver()
Database.Schema.migrate(driver, 1, 1)
return driver
With these additional dependencies:
Copy code
implementation("com.zaxxer:HikariCP:5.0.1")
implementation("com.squareup.sqldelight:jdbc-driver:1.5.3")
implementation("org.postgresql:postgresql:42.2.20")
f
the gradle plugin looks to be generating some code from the migrations i have in the sqm file
though with the generated code I now get
Copy code
import com.concida.dal.newInstance
import com.concida.dal.schema
import com.squareup.sqldelight.Transacter
import com.squareup.sqldelight.db.SqlDriver

public interface Database : Transacter {
  public companion object {
    public val Schema: SqlDriver.Schema
      get() = Database::class.schema

    public operator fun invoke(driver: SqlDriver): Database = Database::class.newInstance(driver)
  }
}
it can’t find
Copy code
import com.concida.dal.newInstance
import com.concida.dal.schema
any idea what I put here or if these should be auto generated
cheers for your help
s
The
newInstance
and
schema
code is generated in this file for me.
Screenshot 2022-01-27 at 17.26.48.png
f
Ok I think the issue is my fault I simply had create table sqm file
I’ll need a schema and database file
no I don’t think that’s the issue
I tried generating with out table migration but now get /Users/bowker/Src/LocoVoco/LocoVoco/dal/src/main/sqldelight/Cafe.sq line 1:0 - SqlDelight files must be placed in a package directory.
which doesn’t look rite as packages would need to be under LocoVoco/dal/src/main/kotlin but the docs spedify src/main/sqldelight
h
Maybe this helps you: https://github.com/hfhbd/ComposeTodo/tree/main/clients/src/commonMain Edit, oh I thought I use migrations :D
f
I take it my issue isn’t
Copy code
fun Datasource() = HikariConfig().apply {
  jdbcUrl = "jdbc:<postgresql://localhost:5432/databaseName>"
  username = "admin"
  password = "admin"
  driverClassName = "org.postgresql.Driver"
}.let(::HikariDataSource)

val driver: SqlDriver = dataSource.asJdbcDriver()
Database.Schema.migrate(driver, 1, 1)
return drive
that I don’t have this when I run gradle
I thought that is only for connecting at runtime or am i missing something
yeah I’m trying with migrations but if I could get to work anyway that would be a start
cheers I look at that github link
h
BTW I added the derive schema from migration option: https://github.com/hfhbd/ComposeTodo/pull/456
f
I’ve tried both, weirdly with non schema migration I get /Users/bowker/Src/LocoVoco/LocoVoco/dal/src/main/sqldelight/schema.sq line 1:0 - SqlDelight files must be placed in a package directory
but my packages are under main/kotlin so doesn’t really make much sense
h
You should use the same package name used for kotlin files for SqlDelight files too.
f
yup it’s generating under the correct package name
just doesn’t greate me a schema or newInstance
seems a stupid question but I don’t need to create a datasource such as
Copy code
fun Datasource() = HikariConfig().apply {
  jdbcUrl = "jdbc:<postgresql://localhost:5432/databaseName>"
  username = "admin"
  password = "admin"
  driverClassName = "org.postgresql.Driver"
}.let(::HikariDataSource)
for this to work I thought that was just for connecting at runtime
h
Nope, for generating code, you dont need Hikari. You must move your
.sq
to src/main/com/example/something/foo.sq
f
ok cool got it working my problem was the path ive got it working at https://github.com/hfhbd/ComposeTodo/tree/main/clients/src/commonMain
basically I hadn’t got the directory structure correct
150 Views