ktorm
ktorm copied to clipboard
Is it possible to auto increment a column value on Update?
I have a column in a table called 'version' which keep tracks of the number of updates for the row. Is it possible to use Ktorm to auto increment this column value whenever Ktorm updates the entity? Thanks.
Self increment:
database.update(Foo) {
it.version to it.version + 1
where {
(it.id eq 1) and (it.version eq 1)
}
}
Generated SQL:
update foo set version = version + ? where id = ? and version = ?
Thanks Vincent, but is there a way that this can be managed by the entity class itself without using the DSL? (i.e. just do flushChanges()
on the entity object without the DSL?)
What I really want to achieve is to have Ktorm to do something like Hibernate/JPA Optimistic Locking. Using the version
as part of the WHERE clause whenever flushChanges()
Got it, but it is not supported yet. We can directly use SQL DSL as a workaround.