-
Notifications
You must be signed in to change notification settings - Fork 545
Closed
Labels
Description
SQLDelight Version
2.0.0-alpha03
Operating System
macOS 13
Gradle Version
7.4.2
Kotlin Version
1.7.0
Dialect
Custom
AGP Version
No response
Describe the Bug
Hey, I use a custom dialect which basically just replaces the java time api with kotlinx-datetime in the mapper, so you don't need x adapter.
But converting the time types requires the usage of kotlin extension functions.
// ... removed other dialect code
override fun cursorGetter(columnIndex: Int, cursorName: String): CodeBlock {
return with(CodeBlock.builder()) {
when (this@PostgreSqlType) {
TIMESTAMP_TIMEZONE -> add(
"($cursorName.getObject($columnIndex) as java.time.OffsetDateTime?)?.toInstant()?.%M()",
MemberName("kotlinx.datetime", "toKotlinInstant", isExtension = true)
)
UUID -> add("($cursorName.getObject($columnIndex) as java.util.UUID?)")
.add("?.%M()", MemberName("kotlinx.uuid", "toKotlinUUID", isExtension = true))
}
}.build()
}
}
results into this code:
mapper(
cursor.getString(0)!!,
(cursor.getObject(1) as
java.time.OffsetDateTime?)?.toInstant()?.kotlinx.datetime.toKotlinInstant()!!
)
I thought, this is a kotlinpoet issue, but I can't reproduce it with a small reproducer. So maybe sqldelight does some magic.
kotlinPoetWorkingReproducer.zip
Stacktrace
No response
Gradle Build Script
plugins {
kotlin("jvm") version "1.7.0"
id("app.cash.sqldelight") version "2.0.0-alpha03"
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
}
sqldelight {
database("DB") {
dialect(projects.dialect)
packageName = "example"
}
}