Gunslingor
04/04/2020, 3:55 AMpackage com.newsworthy.db.tables
import org.jetbrains.exposed.dao.Entity
import org.jetbrains.exposed.dao.EntityClass
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Table
import org.joda.time.DateTime
val defaultCategories = mutableMapOf<EntityID<String>, String>(
EntityID("general", Categories) to "Useless and frowned upon",
EntityID("science", Categories) to "",
EntityID("technology", Categories) to "",
EntityID("world", Categories) to "",
EntityID("local", Categories) to "",
EntityID("top", Categories) to ""
)
class Category(category: EntityID<String>) : Entity<String>(category){
companion object : EntityClass<String, Category>(Categories)
var category by Categories.category
var description by Categories.description
}
object Categories : IdTable<String>("Categories") {
val category = varchar("category", 255).default("general").entityId().default(EntityID("unknown", Categories))
val description = varchar("description", 255).nullable()
override val primaryKey = PrimaryKey(category, name = "PK_Category_category")
override val id: Column<EntityID<String>> = category
}
tapac
04/06/2020, 7:50 AMdefaultCategories
map?
Maybe it's better to have a flag in a table which will show what category is default?
Also, I prefer to keep category simple varchar and make id - entityId like:
object Categories : IdTable<String>("Categories") {
val category = varchar("category", 255).default("general")
val description = varchar("description", 255).nullable()
override val primaryKey = PrimaryKey(category, name = "PK_Category_category")
override val id: Column<EntityID<String>> = category.entityId()
}
Gunslingor
04/07/2020, 3:15 AM/** Converts the @receiver column to an [EntityID] column. */
I'd enhance:
/** Uses the @receiver column to make an [EntityID] column when assigned to a tables Tid field such as... lol. */