mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
Add the slick
This commit is contained in:
39
src/main/scala/model/Account.scala
Normal file
39
src/main/scala/model/Account.scala
Normal file
@@ -0,0 +1,39 @@
|
||||
package model
|
||||
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
|
||||
object Accounts extends Table[Account]("ACCOUNT") {
|
||||
def userId = column[Long]("USER_ID", O AutoInc)
|
||||
def userName = column[String]("USER_NAME")
|
||||
def mailAddress = column[String]("MAIL_ADDRESS")
|
||||
def password = column[String]("PASSWORD")
|
||||
def userType = column[Int]("USER_TYPE")
|
||||
def url = column[String]("URL")
|
||||
def registeredDate = column[java.sql.Date]("REGISTERED_DATE") // TODO convert java.util.Date later
|
||||
def updatedDate = column[java.sql.Date]("UPDATED_DATE")
|
||||
def lastLoginDate = column[java.sql.Date]("LAST_LOGIN_DATE")
|
||||
def * = userId.? ~ userName ~ mailAddress ~ password ~ userType ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> (Account, Account.unapply _)
|
||||
def ins = userName ~ mailAddress ~ password ~ userType ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> ({ t => Account(None, t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8)}, { (o: Account) => Some((o.userName, o.mailAddress, o.password, o.userType, o.url, o.registeredDate, o.updatedDate, o.lastLoginDate))})
|
||||
}
|
||||
|
||||
case class Account(
|
||||
userId: Option[Long],
|
||||
userName: String,
|
||||
mailAddress: String,
|
||||
password: String,
|
||||
userType: Int,
|
||||
url: Option[String],
|
||||
registeredDate: java.sql.Date,
|
||||
updatedDate: java.sql.Date,
|
||||
lastLoginDate: Option[java.sql.Date]
|
||||
)
|
||||
|
||||
class AccountDao {
|
||||
import Database.threadLocalSession
|
||||
|
||||
// def insert(o: Account): Account = Accounts.ins returning Accounts.* insert o
|
||||
def insert(o: Account): Long = Accounts.ins returning Accounts.userId insert o
|
||||
|
||||
def select(key: Long): Option[Account] = Query(Accounts) filter(_.userId is key.bind) firstOption
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user