Hi, would it be possible to have software delete implemented in this library?
Also created_at updated_at support would be nice.
sample implementations: https://gist.github.com/logrusorgru/82b002b8807253b2adef
@BugsBunnyBR , I'm not sure about wide usefulness of this feature. Besides you can easily implement it by yourself. Try something like this:
abstract class ExtendedIntIdTable(name: String ) : IntIdTable(name) {
val createdAt = datetime("createdAt").default(DateTime.now())
val updatedAt = datetime("updatedAt").nullable()
val deletedAt = datetime("deletedAt").nullable()
}
abstract class ExtendedIntEntity(id: EntityID<Int>, table: ExtendedIntIdTable) : IntEntity(id) {
val createdAt by table.createdAt
var updatedAt by table.updatedAt
var deletedAt by table.deletedAt
override fun delete() {
deletedAt = DateTime.now()
}
}
abstract class ExtendedIntEntityClass<E:ExtendedIntEntity>(table: ExtendedIntIdTable) : IntEntityClass<E>(table) {
init {
EntityHook.subscribe { action ->
if (action.changeType == EntityChangeType.Updated)
action.toEntity(this)?.updatedAt = DateTime.now()
}
}
}
object FooTable : ExtendedIntIdTable("Foo") {
val bar = varchar("bar", 255).nullable()
}
class FooEntity(id: EntityID<Int>) : ExtendedIntEntity(id, FooTable) {
val bar by FooTable.bar
companion object : ExtendedIntEntityClass<FooEntity>(FooTable)
}
With this solution, if someone changes the data directly in the database it would not have the data updated. The best option would be to have it in the create table as in the gist.
I'm not sure that ON UPDATE current_timestamp syntax will work on MySQL. I guess it will require to create trigger for that.
It works on MySQL.
https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
Nice, I don't know about that.
https://github.com/JetBrains/Exposed/wiki/DAO#auto-fill-created-and-updated-columns-on-entity-change
Most helpful comment
@BugsBunnyBR , I'm not sure about wide usefulness of this feature. Besides you can easily implement it by yourself. Try something like this: