Add User table

This commit is contained in:
Hubert Van De Walle 2020-04-12 00:12:16 +02:00
parent 8a6d93c51a
commit ca2bf4d24c
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,9 @@
CREATE TABLE `Users`
(
`id` int PRIMARY KEY AUTO_INCREMENT,
`username` varchar(50) UNIQUE NOT NULL,
`email` varchar(255) UNIQUE NOT NULL,
`password` varchar(255) NOT NULL,
`created_at` datetime NOT NULL,
`last_login` datetime
);

15
api/src/entities/User.kt Normal file
View File

@ -0,0 +1,15 @@
package be.vandewalleh.entities
import me.liuwj.ktorm.entity.Entity
import java.time.LocalDateTime
interface User : Entity<User> {
companion object : Entity.Factory<User>()
val id: Int
var username: String
var email: String
var password: String
var createdAt: LocalDateTime
var lastLogin: LocalDateTime?
}

16
api/src/tables/Users.kt Normal file
View File

@ -0,0 +1,16 @@
package be.vandewalleh.tables
import be.vandewalleh.entities.User
import me.liuwj.ktorm.schema.Table
import me.liuwj.ktorm.schema.datetime
import me.liuwj.ktorm.schema.int
import me.liuwj.ktorm.schema.varchar
object Users : Table<User>("Users") {
val id by int("id").primaryKey().bindTo { it.id }
val username by varchar("username").bindTo { it.username }
val email by varchar("email").bindTo { it.email }
val password by varchar("password").bindTo { it.password }
val createdAt by datetime("created_at").bindTo { it.createdAt }
val lastLogin by datetime("last_login").bindTo { it.lastLogin }
}