Typesafe Slick 2.0.1-RC插入数据库

时间:2014-03-18 10:43:46

标签: slick typesafe

插入数据库时​​遇到问题。我使用光滑的版本2.0.1-RC。我使用SourceCodeGenerator生成源代码。我有桌子MAIN_TC_USER:

case class MainTcUserRow(id: Int, name: Option[String], surname: Option[String], username:           Option[String], password: Option[String]) 
/** GetResult implicit for fetching MainTcUserRow objects using plain SQL queries */
implicit def GetResultMainTcUserRow(implicit e0: GR[Int], e1: GR[Option[String]]):      GR[MainTcUserRow] = GR{
   prs => import prs._
   MainTcUserRow.tupled((<<[Int], <<?[String], <<?[String], <<?[String], <<?[String]))
}
/** Table description of table main_tc_user. Objects of this class serve as prototypes for rows   in queries. */
class MainTcUser(tag: Tag) extends Table[MainTcUserRow](tag, "main_tc_user") {
def * = (id, name, surname, username, password) <> (MainTcUserRow.tupled, MainTcUserRow.unapply)
/** Maps whole row to an option. Useful for outer joins. */
def ? = (id.?, name, surname, username, password).shaped.<>({r=>import r._; _1.map(_=> MainTcUserRow.tupled((_1.get, _2, _3, _4, _5)))}, (_:Any) =>  throw new Exception("Inserting into ? projection not supported."))

/** Database column id PrimaryKey */
val id: Column[Int] = column[Int]("id", O.PrimaryKey)
/** Database column name  */
val name: Column[Option[String]] = column[Option[String]]("name")
/** Database column surname  */
val surname: Column[Option[String]] = column[Option[String]]("surname")
/** Database column username  */
val username: Column[Option[String]] = column[Option[String]]("username")
/** Database column password  */
val password: Column[Option[String]] = column[Option[String]]("password")
}
/** Collection-like TableQuery object for table MainTcUser */
lazy val MainTcUser = new TableQuery(tag => new MainTcUser(tag))

我试图插入MainTcUser表

new DBConnection(Tables.profile).connect.withSession{
  implicit session =>

    Tables.MainTcUser += user        
}    

new DBConnection(Tables.profile).connect.withSession{
  implicit session =>

    Tables.MainTcUser.map(s => s) += user        
}    

在这两种情况下我都有错误: 此行有多个标记      - 值+ =不是其成员      scala.slick.lifted.TableQuery [com.bsi.xpay.Tables.MainTcUser]      - 值+ =不是其成员      scala.slick.lifted.TableQuery [com.bsi.xpay.Tables.MainTcUser]

感谢您的帮助

1 个答案:

答案 0 :(得分:3)

您可能忘记从驱动程序导入.simple._

如果不是,那么它也会看到与Can't access delete method on Slick query相关的内容。