com.tairitsu.ignotus.database.model.entity.BaseLongIdEntity.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of database-exposed Show documentation
Show all versions of database-exposed Show documentation
JetBrains Exposed ORM extension.
The newest version!
package com.tairitsu.ignotus.database.model.entity
import com.tairitsu.ignotus.database.model.table.BaseLongIdTable
import org.jetbrains.exposed.dao.*
import org.jetbrains.exposed.dao.id.EntityID
import java.time.LocalDateTime
/**
* Reference: https://github.com/paulkagiri/ExposedDatesAutoFill
*/
abstract class BaseLongIdEntity(id: EntityID, table: BaseLongIdTable) : LongEntity(id) {
val createdAt by table.createdAt
var updatedAt by table.updatedAt
}
/**
* Reference: https://github.com/paulkagiri/ExposedDatesAutoFill
*/
abstract class BaseLongIdEntityClass(table: BaseLongIdTable) : LongEntityClass(table) {
init {
EntityHook.subscribe { action ->
if (action.changeType == EntityChangeType.Updated || action.changeType == EntityChangeType.Created) {
try {
action.toEntity(this)?.updatedAt = LocalDateTime.now()
} catch (ignored: Exception) {
//nothing much to do here
}
}
}
}
}