dave08
04/11/2024, 12:50 PMQueryDsl.insert(..).values { ... }
when leaving out properties with a default value in the entity data class doesn't insert them automatically in the values block? I could use the single(...)
form, but then I'd have to include my createdAt and updatedAt properties that I'd like Komapper to fill in for me...Toshihiro Nakamura
04/11/2024, 12:54 PMsingle()
? That way, you won’t need to explicitly set values for the createdAt and updatedAt properties.dave08
04/11/2024, 12:56 PMdave08
04/11/2024, 12:57 PMdave08
04/11/2024, 12:59 PMClockProvider
...dave08
04/11/2024, 12:59 PMdave08
04/11/2024, 1:01 PMToshihiro Nakamura
04/11/2024, 1:04 PMdave08
04/11/2024, 1:06 PM@KomapperEntity
...
data class Foo(
...
val bar: Int = 1,
@KomapperCreatedAt
val createdAt: LocalDateTime = globalClock.now().toLocalDateTime()
)
And then use single(...) with that? Then it doesn't use @KomapperCreatedAt
at all, but rather a global clock I provide...dave08
04/11/2024, 1:08 PMdave08
04/11/2024, 1:11 PM!!
...dave08
04/11/2024, 1:14 PMvalues { }
here... but then I loose the defaultsToshihiro Nakamura
04/11/2024, 1:14 PM@KomapperEntity
data class Address(
@KomapperId
@KomapperAutoIncrement
val id: Int = 0,
val street: String,
@KomapperCreatedAt
val createdAt: LocalDateTime = LocalDateTime.MIN,
@KomapperUpdatedAt
val updatedAt: LocalDateTime = LocalDateTime.MIN,
)
fun main() {
val db = JdbcDatabase("jdbc:h2:mem:example;DB_CLOSE_DELAY=-1", clockProvider = { Clock.fixed(Instant.EPOCH, ZoneId.systemDefault()) })
val a = Meta.address
db.withTransaction {
db.runQuery {
QueryDsl.create(a)
}
val newAddress = db.runQuery {
// insert into ADDRESS (STREET, CREATED_AT, UPDATED_AT) values ('street A', '1970-01-01T09:00', '1970-01-01T09:00')
QueryDsl.insert(a).single(Address(street = "street A"))
}
}
}
dave08
04/11/2024, 1:16 PM@KomapperAutoIncrement
?dave08
04/11/2024, 1:18 PMLocalDateTime.MIN
? I guess this is the same question for both... when Komapper tries to handle things is there a way to tell it that I want to override it's handling in certain cases, and only have it do what it wants when a certain default value is used?dave08
04/11/2024, 1:20 PMvalues { }
doesn't work with default values, it's because ksp can't resolve that value... I remember seeing such an issue in another ksp lib... it's funny, I was half expecting that to work 🤷🏼♂️Toshihiro Nakamura
04/11/2024, 1:21 PMinsert(...).single(...)
, Komapper will always overwrite properties annotated with @KomapperCreatedAt
or @KomapperUpdatedAt
.dave08
04/11/2024, 1:22 PMdave08
04/11/2024, 1:22 PMdave08
04/11/2024, 1:25 PMToshihiro Nakamura
04/11/2024, 1:27 PMdave08
04/11/2024, 1:28 PMvalues { }
Komapper doesn't do that then?Toshihiro Nakamura
04/11/2024, 1:33 PMIf you do not explicitly call thefunction for properties with the following mapping definitions then the value is automatically set in the generated SQL:eq
•@KomapperSequence
•@KomapperVersion
•@KomapperCreatedAt
•@KomapperUpdatedAt
If you explicitly call thefunction for those properties, the explicit value takes precedence.eq
The definition ofSee https://www.komapper.org/docs/reference/query/querydsl/insert/#valuescannot be disabled with an explicit value.KomapperAutoIncrement
dave08
04/11/2024, 1:35 PM