Another question <@U01SP2GJYAU> if I can, when usi...
# komapper
d
Another question @Toshihiro Nakamura if I can, when using selectAsEntity with one of the fields as LocalDate, and I need to pass a literal from
Clock.todayIn(TimeZone.UTC)
, I don't know what to use... shouldn't there be a localDateLiteral for this (in jetbrains exposed they actually have such a function...)?
I'm using this in an
insert(...).select { ... }
so I don't have a choice..
I don't really want to have to worry about converting it to the underlying db format, it would be nice if a Komapper abstraction could do this for me...
It seems like this does the trick... but I wonder if it's db dependant and correct?
Copy code
fun literalLocalDate(date: LocalDate): ColumnExpression<String, String> =
    literal(date.toString().replace("-",""))
t
I might not have understood your problem correctly, but it seems you don’t want to retrieve data from the database, but instead, you want to set data within your application, right? Please try the following.
Copy code
.selectAsAddressDto(
    street = a.street,
    date = nullLitral<LocalDate>.transform { Clock.todayIn(TimeZone.UTC) }, 
)
d
That gives me an
Copy code
java.lang.UnsupportedOperationException
	at org.komapper.core.dsl.expression.NullLiteralExpression.getOwner(LiteralExpression.kt:13)
It seems like this is causing the problem:
Copy code
data class NullLiteralExpression<EXTERNAL : Any, INTERNAL : Any>(
    override val exteriorClass: KClass<EXTERNAL>,
    override val interiorClass: KClass<INTERNAL>,
) :
    LiteralExpression<EXTERNAL, INTERNAL> {
    override val owner: TableExpression<*>
        get() = throw UnsupportedOperationException()
selectAsEntity seems to try to access that owner property @Toshihiro Nakamura....
but instead, you want to set data within your application, right?
exactly...
Or maybe even just rely on
@KomapperUpdateAt
to update it in that particular case...
But there might still be cases I need to set it.
t
Try this function:
Copy code
fun todayIn(): ColumnExpression<LocalDate, LocalDate> {
    val operand = Operand.SimpleArgument(LocalDate::class, Clock.todayIn(TimeZone.UTC))
    return columnExpression(LocalDate::class, "todayIn", listOf(operand)) {
        visit(operand)
    }
}
Use the above function as follows:
Copy code
QueryDsl.insert(a).select {
    QueryDsl.from(a)
        .where { a.id eq newAddress.id }
        .selectAsEntity(a, a.street, todayIn(), todayIn())
}
d
Yeah, that seems to work, thanks! So I can really make my own
literalLocalDate()
then...
Copy code
fun literalLocalDate(date: LocalDate): ColumnExpression<LocalDate, LocalDate> {
    val operand = Operand.SimpleArgument(LocalDate::class, date)
    return columnExpression(LocalDate::class, "literalLocalDate", listOf(operand)) {
        visit(operand)
    }
}