使用新的列转换方式

This commit is contained in:
05412 2024-08-05 15:10:43 +08:00
parent 273a791fdf
commit dcbccaabca
2 changed files with 7 additions and 7 deletions

View File

@ -1,6 +1,5 @@
package dev.surl.surl.dao package dev.surl.surl.dao
import dev.surl.surl.common.Access
import dev.surl.surl.dsl.UserAccesses import dev.surl.surl.dsl.UserAccesses
import org.jetbrains.exposed.dao.LongEntity import org.jetbrains.exposed.dao.LongEntity
import org.jetbrains.exposed.dao.LongEntityClass import org.jetbrains.exposed.dao.LongEntityClass
@ -19,11 +18,7 @@ class UserAccess(id: EntityID<Long>): LongEntity(id) {
/** /**
* 权限枚举类型自动转换为数据库存储的整数 * 权限枚举类型自动转换为数据库存储的整数
*/ */
var access by UserAccesses.access.transform(toColumn = { var access by UserAccesses.access
it.ordinal.toShort()
}, toReal = {
Access.entries[it.toInt()]
})
/** /**
* 用户 * 用户

View File

@ -1,5 +1,6 @@
package dev.surl.surl.dsl package dev.surl.surl.dsl
import dev.surl.surl.common.Access
import org.jetbrains.exposed.dao.id.IdTable import org.jetbrains.exposed.dao.id.IdTable
/** /**
@ -8,5 +9,9 @@ import org.jetbrains.exposed.dao.id.IdTable
object UserAccesses: IdTable<Long>("user_access") { object UserAccesses: IdTable<Long>("user_access") {
override val id = long("id").entityId() override val id = long("id").entityId()
val user = reference("user", Users).index() val user = reference("user", Users).index()
val access = short("access") val access = short("access").transform(unwrap = {
it.ordinal.toShort()
}, wrap = {
Access.entries[it.toInt()]
})
} }