Merge branch 'feature/note-table'
This commit is contained in:
commit
25ef4d7197
11
api/resources/db/migration/V2__Create_note_table.sql
Normal file
11
api/resources/db/migration/V2__Create_note_table.sql
Normal file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE `Notes`
|
||||
(
|
||||
`id` int PRIMARY KEY AUTO_INCREMENT,
|
||||
`title` varchar(50) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`user_id` int NOT NULL,
|
||||
`last_viewed` datetime
|
||||
);
|
||||
|
||||
ALTER TABLE `Notes`
|
||||
ADD FOREIGN KEY (`user_id`) REFERENCES `Users` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
|
||||
14
api/src/entities/Note.kt
Normal file
14
api/src/entities/Note.kt
Normal file
@ -0,0 +1,14 @@
|
||||
package be.vandewalleh.entities
|
||||
|
||||
import me.liuwj.ktorm.entity.Entity
|
||||
import java.time.LocalDateTime
|
||||
|
||||
interface Note : Entity<Note> {
|
||||
companion object : Entity.Factory<Note>()
|
||||
|
||||
val id: Int
|
||||
var title: String
|
||||
var content: String
|
||||
var user: User
|
||||
var lastViewed: LocalDateTime?
|
||||
}
|
||||
12
api/src/tables/Notes.kt
Normal file
12
api/src/tables/Notes.kt
Normal file
@ -0,0 +1,12 @@
|
||||
package be.vandewalleh.tables
|
||||
|
||||
import be.vandewalleh.entities.Note
|
||||
import me.liuwj.ktorm.schema.*
|
||||
|
||||
object Notes : Table<Note>("Notes") {
|
||||
val id by int("id").primaryKey().bindTo { it.id }
|
||||
val title by varchar("title").bindTo { it.title }
|
||||
val content by text("content").bindTo { it.content }
|
||||
val user by int("user_id").references(Users) { it.user }
|
||||
val lastViewed by datetime("last_viewed").bindTo { it.lastViewed }
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user