In the Users object definition, you need to change this:
object Users extends Table[(Int, String, Option[String], String, Option[Timestamp], Timestamp, Option[Int])]("APUsers") {
to this:
object Users extends Table[(Option[Int], String, Option[String], String, Option[Timestamp], Timestamp, Option[Int])]("APUsers") {
because the id
is assigned by the DBMS (O.AutoInc
). See the example here: http://slick.typesafe.com/doc/1.0.1/lifted-embedding.html#mapped-tables
Then you need to change this:
def * = userId ~ userName ~ email ~ userPassword ~ creationDate ~
lastLoginDate ~ removed
to this:
def * = userId.? ~ userName ~ email.? ~ userPassword ~ creationDate.? ~
lastLoginDate ~ removed.?
because they are defined as Option
. See here: http://slick.typesafe.com/doc/1.0.1/lifted-embedding.html#mapped-tables
In the newUser
the insert line should be, from this:
(Users.userId ~ Users.userName ~ Users.email ~ Users.userPassword ~
Users.creationDate ~ Users.lastLoginDate ~ Users.removed)
to
(Users.userName ~ Users.email.? ~ Users.userPassword ~ Users.creationDate.? ~
Users.lastLoginDate ~ Users.removed.?)
.insert(userName, email, password, creation, last, removed)
without userId
, because it'll be assigned by the DBMS. See the example here: http://slick.typesafe.com/doc/1.0.1/lifted-embedding.html#inserting
Since you do not accept Null in the database, I would suggest to change this:
def newUser(userName: String, email: Option[String], password: String = null, removed: Option[Int] = null)
to this:
def newUser(userName: String, email: Option[String], password: String, removed: Option[Int] = null)
and check that the password is not null.
As per pedrofurla suggestion you can add the following to the Users
object:
def forInsert = Users.userName ~ Users.email.? ~ Users.userPassword ~
Users.creationDate.? ~ Users.lastLoginDate ~ Users.removed.?
and make the line more readable:
Users.forInsert.insert(userName, email, password, creation, last, removed)
See http://slick.typesafe.com/doc/1.0.1/lifted-embedding.html#inserting