有点圆滑的 n00b ...我正在尝试构建一个插入语句,但发现我没有插入任何东西。
def newUser(userName: String, email: Option[String], password: String = null, removed: Option[Int] = null) = SlickInit.dbMaster withSession {
val creation = Option(new java.sql.Timestamp(new java.util.Date().getTime()))
val last = new java.sql.Timestamp(new java.util.Date().getTime())
printf("REACHED 1. creation: " + creation + "\n last: " + last)
println("\nusername: " + userName + "\n email: " + email)
println("maxId: " + maxId)
val invoker = Users.insertInvoker
(Users.userId ~ Users.userName ~ Users.email ~ Users.userPassword ~ Users.creationDate ~ Users.lastLoginDate ~ Users.removed).insert(maxId, userName, email, password, creation, last, removed)
val statement = Users.insertStatement
println("REACHED 2. \n\nStatement: " + statement)
}
当发出 POST 请求时,REACHED 1 打印(使用所需的值),但不是 REACHED 2。我确定我的插入语句有问题,但我不确定是什么。(另外,显然,当我查询数据库时,插入的值不会返回。)有人对此有任何见解吗?
编辑,这是我的用户表定义:
object Users extends Table[(Int, String, Option[String], String, Option[Timestamp], Timestamp, Option[Int])]("APUsers") {
def userId = column[Int]("UserId", O.PrimaryKey, O.AutoInc)
def userName = column[String]("UserName")
def email = column[Option[String]]("Email", O.Nullable)
def userPassword = column[String]("UserPassword")
def creationDate = column[Option[Timestamp]]("CreationDate", O.Nullable)
def lastLoginDate = column[Timestamp]("LastLoginDate")
def removed = column[Option[Int]]("removed", O.Nullable)
def * = userId ~ userName ~ email ~ userPassword ~ creationDate ~ lastLoginDate ~ removed
}