Skip to content

Instantly share code, notes, and snippets.

@Wonicon
Created October 4, 2017 17:45
Show Gist options
  • Save Wonicon/814dfa5a664231a3fd632117dd5ff14f to your computer and use it in GitHub Desktop.
Save Wonicon/814dfa5a664231a3fd632117dd5ff14f to your computer and use it in GitHub Desktop.
My Table Definition for Exposed
object <table-plural> : ... {
val <column> = ...
val <column> = reference(..., <another-table>)
...
}
=>
class User(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<User>(Users)
var name by Users.name
var city by City referencedOn Users.city
var age by Users.age
}
class <table-single> : IntEntity(id) {
companion object : IntEntityClass<table-singal)(<table-plural>)
var <column> by <table-plural>.<column>
var <foreign-key> by <another-table-single> referencedOn <table-plural>.<foreign-key>
val <back-link> by <another-table-single> referredOn <table-plural>.<foreign-key>
}
object Categories : IntIdTable() {
val name = varchar("name", 50)
val parent = reference("parent", Categories)
}
object Subjects : IntIdTable() {
val name = varchar("name", 256)
val description = text("description")
val coverURL = varchar("coverURL", 256)
val category = reference("category", Categories)
}
object Posts : IntIdTable() {
val title = varchar("title", 256)
val content = text("content")
val subject = reference("subject", Subjects)
}
object Journals : IntIdTable() {
val date = date("date")
val content = text("content")
val subject = reference("subject", Subjects)
}
object Tasks : IntIdTable() {
val createDate = date("createDate")
val title = varchar("title", 256)
val content = text("content")
val subject = reference("subject", Subjects)
}
object TaskItems : IntIdTable() {
val finishDate = date("finishDate")
val content = text("content")
val task = reference("task", Tasks)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment