File tree Expand file tree Collapse file tree
core/src/main/kotlin/org/sinytra/probe/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import org.jetbrains.exposed.dao.id.LongIdTable
77import org.sinytra.probe.core.model.Mod
88
99object ModTable : LongIdTable(" mod" ) {
10- val modid = varchar(" modid" , 255 ).nullable().uniqueIndex()
10+ val modid = varchar(" modid" , 255 ).nullable()
1111}
1212
1313class ModDAO (id : EntityID <Long >) : LongEntity(id) {
Original file line number Diff line number Diff line change 11package org.sinytra.probe.core.model
22
3- import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
4- import org.jetbrains.exposed.sql.deleteWhere
53import org.sinytra.probe.core.db.ModDAO
6- import org.sinytra.probe.core.db.ModTable
74import org.sinytra.probe.core.db.daoToModel
85import org.sinytra.probe.core.db.suspendTransaction
96
107interface ModRepository {
118 suspend fun allMods (): List <Mod >
129 suspend fun modById (id : Long ): Mod ?
13- suspend fun modByModid (modid : String ): Mod ?
1410 suspend fun addMod (mod : Mod ): Mod
15- suspend fun removeMod (modid : String ): Boolean
1611}
1712
1813class PostgresModRepository : ModRepository {
@@ -24,24 +19,9 @@ class PostgresModRepository : ModRepository {
2419 ModDAO .findById(id)?.let (::daoToModel)
2520 }
2621
27- override suspend fun modByModid (modid : String ): Mod ? = suspendTransaction {
28- ModDAO
29- .find { (ModTable .modid eq modid) }
30- .limit(1 )
31- .map(::daoToModel)
32- .firstOrNull()
33- }
34-
3522 override suspend fun addMod (mod : Mod ): Mod = suspendTransaction {
3623 ModDAO .new {
3724 modid = mod.modid
3825 }.let (::daoToModel)
3926 }
40-
41- override suspend fun removeMod (modid : String ): Boolean = suspendTransaction {
42- val rowsDeleted = ModTable .deleteWhere {
43- ModTable .modid eq modid
44- }
45- rowsDeleted == 1
46- }
4727}
You can’t perform that action at this time.
0 commit comments