io.tcds.orm.statement.Statement.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of orm Show documentation
Show all versions of orm Show documentation
Kotlin Simple ORM is a simple but powerful database orm for kotlin applications
package io.tcds.orm.statement
import io.tcds.orm.Condition
import io.tcds.orm.Param
import io.tcds.orm.column.DateTimeColumn
import io.tcds.orm.extension.*
import java.time.LocalDateTime
data class Statement(val conditions: MutableList>) {
companion object {
fun deletedAt() = DateTimeColumn("deleted_at") { LocalDateTime.now() }
}
fun toStmt() = conditions.toStmt()
fun toSql() = conditions.toSql()
fun add(condition: Pair): Statement {
when (conditions.isEmpty()) {
true -> conditions.add(Pair(Operator.NONE, condition.second))
else -> conditions.add(condition)
}
return this
}
fun params(): List> {
val params = mutableListOf>()
conditions.forEach { params.addAll(it.second.params()) }
return params
}
fun getSoftDeleteQueryParams(): List> {
val deletedAt = deletedAt()
val params = mutableListOf>(Param(deletedAt, LocalDateTime.now()))
conditions.forEach { params.addAll(it.second.params()) }
return params
}
fun getSoftDeleteStatement(): Statement {
val deletedAt = deletedAt()
if (conditions.isEmpty()) return where(deletedAt.isNull())
return where(StatementGroup(conditions.removeWhere())) and deletedAt.isNull()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy