mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-15 05:19:23 +00:00
ids in crud repos
This commit is contained in:
@@ -22,6 +22,17 @@ abstract class AbstractExposedReadCRUDRepo<ObjectType, IdType>(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getIdsByPagination(pagination: Pagination): PaginationResult<IdType> {
|
||||
return transaction(db = database) {
|
||||
selectAll().paginate(pagination).map {
|
||||
it.asId
|
||||
}.createPaginationResult(
|
||||
pagination,
|
||||
selectAll().count()
|
||||
)
|
||||
}
|
||||
}
|
||||
override suspend fun getById(id: IdType): ObjectType? {
|
||||
return transaction(db = database) {
|
||||
select {
|
||||
|
@@ -4,6 +4,7 @@ import org.jetbrains.exposed.sql.*
|
||||
|
||||
interface CommonExposedRepo<IdType, ObjectType> : ExposedRepo {
|
||||
val ResultRow.asObject: ObjectType
|
||||
val ResultRow.asId: IdType
|
||||
val selectById: ISqlExpressionBuilder.(IdType) -> Op<Boolean>
|
||||
val selectByIds: ISqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
|
||||
get() = { list ->
|
||||
|
@@ -15,7 +15,13 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
|
||||
CommonExposedRepo<Key, Value>,
|
||||
Table(tableName ?: "") {
|
||||
abstract val keyColumn: Column<*>
|
||||
|
||||
/**
|
||||
* Same as [asId] in context of KeyValue repo
|
||||
*/
|
||||
abstract val ResultRow.asKey: Key
|
||||
override val ResultRow.asId: Key
|
||||
get() = asKey
|
||||
abstract val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean>
|
||||
|
||||
override suspend fun get(k: Key): Value? = transaction(database) {
|
||||
|
@@ -17,6 +17,8 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
|
||||
Table(tableName ?: "") {
|
||||
abstract val keyColumn: Column<*>
|
||||
abstract val ResultRow.asKey: Key
|
||||
override val ResultRow.asId: Key
|
||||
get() = asKey
|
||||
abstract val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean>
|
||||
|
||||
override suspend fun count(k: Key): Long = transaction(database) { select { selectById(k) }.count() }
|
||||
|
Reference in New Issue
Block a user