mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-23 00:57:15 +00:00
commit
c5a32e2b1b
37
CHANGELOG.md
37
CHANGELOG.md
@ -1,10 +1,36 @@
|
||||
# Changelog
|
||||
|
||||
## 0.1.0
|
||||
## 0.2.0
|
||||
|
||||
Inited :)
|
||||
* `Repos`
|
||||
* `Exposed`
|
||||
* Now this project depend on `micro_utils.coroutines`
|
||||
* Typealias `ColumnAllocator` has been replaced to root exposed package
|
||||
* Interface `ExposedRepo` has been added
|
||||
* `ExposedCRUDRepo` now extends `ExposedRepo` instead of simple `Repo`
|
||||
* New extension `initTable` for classes which are `Table` and `ExposedRepo` at the same time
|
||||
* `KeyValue`:
|
||||
* Class `AbstractExposedReadKeyValueRepo`
|
||||
* Renamed to `ExposedReadKeyValueRepo`
|
||||
* Changed incoming types to `ColumnAllocator`
|
||||
* `open` instead of `abstract`
|
||||
* Implements `ExposedRepo`
|
||||
* Class `AbstractExposedKeyValueRepo`
|
||||
* Renamed to `ExposedKeyValueRepo`
|
||||
* Changed incoming types to `ColumnAllocator`
|
||||
* `open` instead of `abstract`
|
||||
* `OneToMany`:
|
||||
* Class `AbstractExposedReadOneToManyKeyValueRepo`
|
||||
* Renamed to `ExposedReadOneToManyKeyValueRepo`
|
||||
* Changed incoming arguments order
|
||||
* Implements `ExposedRepo`
|
||||
* Class `AbstractExposedOneToManyKeyValueRepo`
|
||||
* Renamed to `ExposedKeyValueRepo`
|
||||
* Changed incoming arguments order
|
||||
* `open` instead of `abstract`
|
||||
* Release for every `Flow` in parent interfaces
|
||||
|
||||
### 0.1.1
|
||||
## 0.1.1
|
||||
|
||||
* `Versions`:
|
||||
* `kotlinx.serialization`: `1.0.0-RC2` -> `1.0.0`
|
||||
@ -39,3 +65,8 @@ Inited :)
|
||||
* `MapCRUDRepo` class as implementation of `StandardCRUDRepo` on top of `MutableMap` has been added
|
||||
* `MapKeyValueRepo` class as implementation of `StandardKeyValueRepo` on top of `MutableMap` has been added
|
||||
* `MapOneToManyKeyValueRepo` class as implementation of `OneToManyKeyValueRepo` on top of `MutableMap` has been added
|
||||
|
||||
|
||||
## 0.1.0
|
||||
|
||||
Inited :)
|
@ -19,4 +19,4 @@ github_release_plugin_version=2.2.12
|
||||
uuidVersion=0.2.2
|
||||
|
||||
group=dev.inmo
|
||||
version=0.1.1
|
||||
version=0.2.0
|
||||
|
@ -9,6 +9,7 @@ kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api internalProject("micro_utils.coroutines")
|
||||
api internalProject("micro_utils.repos.common")
|
||||
api internalProject("micro_utils.pagination.exposed")
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package dev.inmo.micro_utils.repos.exposed
|
||||
|
||||
import org.jetbrains.exposed.sql.Column
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
|
||||
typealias ColumnAllocator<T> = Table.() -> Column<T>
|
@ -3,9 +3,7 @@ package dev.inmo.micro_utils.repos.exposed
|
||||
import dev.inmo.micro_utils.repos.Repo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
|
||||
interface ExposedCRUDRepo<ObjectType, IdType> : Repo {
|
||||
val database: Database
|
||||
|
||||
interface ExposedCRUDRepo<ObjectType, IdType> : ExposedRepo {
|
||||
val ResultRow.asObject: ObjectType
|
||||
val selectById: SqlExpressionBuilder.(IdType) -> Op<Boolean>
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package dev.inmo.micro_utils.repos.exposed
|
||||
|
||||
import dev.inmo.micro_utils.repos.Repo
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
|
||||
interface ExposedRepo : Repo {
|
||||
val database: Database
|
||||
}
|
@ -6,3 +6,5 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
||||
fun Table.initTable(database: Database) {
|
||||
transaction(database) { SchemaUtils.createMissingTablesAndColumns(this@initTable) }
|
||||
}
|
||||
|
||||
fun <T> T.initTable() where T: ExposedRepo, T: Table = initTable(database)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.keyvalue
|
||||
|
||||
import dev.inmo.micro_utils.repos.StandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.*
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@ -8,14 +9,14 @@ import kotlinx.coroutines.flow.asFlow
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
||||
open class ExposedKeyValueRepo<Key, Value>(
|
||||
database: Database,
|
||||
keyColumn: Column<Key>,
|
||||
valueColumn: Column<Value>
|
||||
) : StandardKeyValueRepo<Key, Value>, AbstractExposedReadKeyValueRepo<Key, Value>(
|
||||
keyColumnAllocator: ColumnAllocator<Key>,
|
||||
valueColumnAllocator: ColumnAllocator<Value>
|
||||
) : StandardKeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>(
|
||||
database,
|
||||
keyColumn,
|
||||
valueColumn
|
||||
keyColumnAllocator,
|
||||
valueColumnAllocator
|
||||
) {
|
||||
private val onNewValueChannel = BroadcastChannel<Pair<Key, Value>>(Channel.BUFFERED)
|
||||
private val onValueRemovedChannel = BroadcastChannel<Key>(Channel.BUFFERED)
|
||||
@ -23,6 +24,8 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
||||
override val onNewValue: Flow<Pair<Key, Value>> = onNewValueChannel.asFlow()
|
||||
override val onValueRemoved: Flow<Key> = onValueRemovedChannel.asFlow()
|
||||
|
||||
init { initTable() }
|
||||
|
||||
override suspend fun set(k: Key, v: Value) {
|
||||
transaction(database) {
|
||||
if (select { keyColumn.eq(k) }.limit(1).any()) {
|
||||
@ -46,3 +49,6 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
||||
onValueRemovedChannel.send(k)
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("ExposedKeyValueRepo", "dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo"))
|
||||
typealias AbstractExposedKeyValueRepo<Key, Value> = ExposedKeyValueRepo<Key, Value>
|
@ -2,16 +2,21 @@ package dev.inmo.micro_utils.repos.exposed.keyvalue
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.ReadStandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
|
||||
protected val database: Database,
|
||||
protected val keyColumn: Column<Key>,
|
||||
protected val valueColumn: Column<Value>
|
||||
) : ReadStandardKeyValueRepo<Key, Value>, Table() {
|
||||
open class ExposedReadKeyValueRepo<Key, Value>(
|
||||
override val database: Database,
|
||||
keyColumnAllocator: ColumnAllocator<Key>,
|
||||
valueColumnAllocator: ColumnAllocator<Value>,
|
||||
) : ReadStandardKeyValueRepo<Key, Value>, ExposedRepo, Table() {
|
||||
protected val keyColumn: Column<Key> = keyColumnAllocator()
|
||||
protected val valueColumn: Column<Value> = valueColumnAllocator()
|
||||
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
|
||||
|
||||
init { initTable() }
|
||||
|
||||
override suspend fun get(k: Key): Value? = transaction(database) {
|
||||
select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn)
|
||||
}
|
||||
@ -34,3 +39,6 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
|
||||
}
|
||||
}.createPaginationResult(pagination, count())
|
||||
}
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("ExposedReadKeyValueRepo", "dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedReadKeyValueRepo"))
|
||||
typealias AbstractExposedReadKeyValueRepo<Key, Value> = ExposedReadKeyValueRepo<Key, Value>
|
@ -1,35 +0,0 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||
|
||||
import dev.inmo.micro_utils.repos.OneToManyKeyValueRepo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
abstract class AbstractExposedOneToManyKeyValueRepo<Key, Value>(
|
||||
keyColumnAllocator: ColumnAllocator<Key>,
|
||||
valueColumnAllocator: ColumnAllocator<Value>,
|
||||
database: Database
|
||||
) : OneToManyKeyValueRepo<Key, Value>, AbstractExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||
keyColumnAllocator,
|
||||
valueColumnAllocator,
|
||||
database
|
||||
) {
|
||||
override suspend fun add(k: Key, v: Value) {
|
||||
transaction(database) {
|
||||
insert {
|
||||
it[keyColumn] = k
|
||||
it[valueColumn] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun remove(k: Key, v: Value) {
|
||||
transaction(database) { deleteWhere { keyColumn.eq(k).and(valueColumn.eq(v)) } }
|
||||
}
|
||||
|
||||
override suspend fun clear(k: Key) {
|
||||
transaction(database) { deleteWhere { keyColumn.eq(k) } }
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("AbstractExposedOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.exposed.onetomany.AbstractExposedOneToManyKeyValueRepo"))
|
||||
typealias AbstractOneToManyExposedKeyValueRepo<Key, Value> = AbstractExposedOneToManyKeyValueRepo<Key, Value>
|
@ -0,0 +1,58 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.BroadcastFlow
|
||||
import dev.inmo.micro_utils.repos.OneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||
import dev.inmo.micro_utils.repos.exposed.initTable
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
open class ExposedOneToManyKeyValueRepo<Key, Value>(
|
||||
database: Database,
|
||||
keyColumnAllocator: ColumnAllocator<Key>,
|
||||
valueColumnAllocator: ColumnAllocator<Value>
|
||||
) : OneToManyKeyValueRepo<Key, Value>, ExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||
database,
|
||||
keyColumnAllocator,
|
||||
valueColumnAllocator
|
||||
) {
|
||||
protected val _onNewValue: BroadcastFlow<Pair<Key, Value>> = BroadcastFlow()
|
||||
override val onNewValue: Flow<Pair<Key, Value>>
|
||||
get() = _onNewValue
|
||||
protected val _onValueRemoved: BroadcastFlow<Pair<Key, Value>> = BroadcastFlow()
|
||||
override val onValueRemoved: Flow<Pair<Key, Value>>
|
||||
get() = _onValueRemoved
|
||||
protected val _onDataCleared: BroadcastFlow<Key> = BroadcastFlow()
|
||||
override val onDataCleared: Flow<Key>
|
||||
get() = _onDataCleared
|
||||
|
||||
init { initTable() }
|
||||
|
||||
override suspend fun add(k: Key, v: Value) {
|
||||
transaction(database) {
|
||||
insert {
|
||||
it[keyColumn] = k
|
||||
it[valueColumn] = v
|
||||
}
|
||||
}.also { _onNewValue.send(k to v) }
|
||||
}
|
||||
|
||||
override suspend fun remove(k: Key, v: Value) {
|
||||
transaction(database) {
|
||||
deleteWhere { keyColumn.eq(k).and(valueColumn.eq(v)) }
|
||||
}.also { _onValueRemoved.send(k to v) }
|
||||
}
|
||||
|
||||
override suspend fun clear(k: Key) {
|
||||
transaction(database) {
|
||||
deleteWhere { keyColumn.eq(k) }
|
||||
}.also { _onDataCleared.send(k) }
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("ExposedOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.exposed.onetomany.ExposedOneToManyKeyValueRepo"))
|
||||
typealias AbstractOneToManyExposedKeyValueRepo<Key, Value> = ExposedOneToManyKeyValueRepo<Key, Value>
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("ExposedOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.exposed.onetomany.ExposedOneToManyKeyValueRepo"))
|
||||
typealias AbstractExposedOneToManyKeyValueRepo<Key, Value> = ExposedOneToManyKeyValueRepo<Key, Value>
|
@ -2,19 +2,20 @@ package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.repos.ReadOneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.exposed.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
typealias ColumnAllocator<T> = Table.() -> Column<T>
|
||||
|
||||
abstract class AbstractExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||
open class ExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||
override val database: Database,
|
||||
keyColumnAllocator: ColumnAllocator<Key>,
|
||||
valueColumnAllocator: ColumnAllocator<Value>,
|
||||
protected val database: Database
|
||||
) : ReadOneToManyKeyValueRepo<Key, Value>, Table() {
|
||||
valueColumnAllocator: ColumnAllocator<Value>
|
||||
) : ReadOneToManyKeyValueRepo<Key, Value>, ExposedRepo, Table() {
|
||||
protected val keyColumn: Column<Key> = keyColumnAllocator()
|
||||
protected val valueColumn: Column<Value> = valueColumnAllocator()
|
||||
|
||||
init { initTable() }
|
||||
|
||||
override suspend fun count(k: Key): Long = transaction(database) { select { keyColumn.eq(k) }.count() }
|
||||
|
||||
override suspend fun count(): Long = transaction(database) { selectAll().count() }
|
||||
@ -46,5 +47,8 @@ abstract class AbstractExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("AbstractExposedReadOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.exposed.onetomany.AbstractExposedReadOneToManyKeyValueRepo"))
|
||||
typealias AbstractOneToManyExposedReadKeyValueRepo<Key, Value> = AbstractExposedReadOneToManyKeyValueRepo<Key, Value>
|
||||
@Deprecated("Renamed", ReplaceWith("ExposedReadOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.exposed.onetomany.ExposedReadOneToManyKeyValueRepo"))
|
||||
typealias AbstractOneToManyExposedReadKeyValueRepo<Key, Value> = ExposedReadOneToManyKeyValueRepo<Key, Value>
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("ExposedReadOneToManyKeyValueRepo", "dev.inmo.micro_utils.repos.exposed.onetomany.ExposedReadOneToManyKeyValueRepo"))
|
||||
typealias AbstractExposedReadOneToManyKeyValueRepo<Key, Value> = ExposedReadOneToManyKeyValueRepo<Key, Value>
|
Loading…
Reference in New Issue
Block a user