46 lines
1.5 KiB
Kotlin
46 lines
1.5 KiB
Kotlin
@file:Suppress("unused")
|
|
|
|
package be.simplenotes.persistance.notes
|
|
|
|
import be.simplenotes.persistance.extensions.uuidBinary
|
|
import be.simplenotes.persistance.users.UserEntity
|
|
import be.simplenotes.persistance.users.Users
|
|
import me.liuwj.ktorm.database.Database
|
|
import me.liuwj.ktorm.entity.Entity
|
|
import me.liuwj.ktorm.entity.sequenceOf
|
|
import me.liuwj.ktorm.schema.*
|
|
import java.time.LocalDateTime
|
|
import java.util.*
|
|
|
|
internal open class Notes(alias: String?) : Table<NoteEntity>("Notes", alias) {
|
|
companion object : Notes(null)
|
|
|
|
override fun aliased(alias: String) = Notes(alias)
|
|
|
|
val uuid = uuidBinary("uuid").primaryKey().bindTo { it.uuid }
|
|
val title = varchar("title").bindTo { it.title }
|
|
val markdown = text("markdown").bindTo { it.markdown }
|
|
val html = text("html").bindTo { it.html }
|
|
val userId = int("user_id").references(Users) { it.user }
|
|
val updatedAt = datetime("updated_at").bindTo { it.updatedAt }
|
|
val deleted = boolean("deleted").bindTo { it.deleted }
|
|
val public = boolean("public").bindTo { it.public }
|
|
val user get() = userId.referenceTable as Users
|
|
}
|
|
|
|
internal val Database.notes get() = this.sequenceOf(Notes, withReferences = false)
|
|
|
|
internal interface NoteEntity : Entity<NoteEntity> {
|
|
companion object : Entity.Factory<NoteEntity>()
|
|
|
|
var uuid: UUID
|
|
var title: String
|
|
var markdown: String
|
|
var html: String
|
|
var updatedAt: LocalDateTime
|
|
var deleted: Boolean
|
|
var public: Boolean
|
|
|
|
var user: UserEntity
|
|
}
|