我在 Playframework 2 中有这个 ScalaQuery 模型
object User {
implicit object UserFormat extends Format[User] {
def reads(json: JsValue) : User = User(
None,
(json \ "firstName").as[String],
(json \ "lastName").as[String],
(json \ "email").as[String]
)
def writes(user: User) : JsValue = JsObject(Seq(
"firstName" -> JsString(user.firstName),
"lastName" -> JsString(user.lastName),
"email" -> JsString(user.email))
)
}
}
object UsersTable extends Table[User]("users") {
def id = column[Long]("USER_ID", O.PrimaryKey, O.AutoInc)
def fName = column[String]("USER_FIRSTNAME", O.NotNull)
def lName= column[String]("USER_LASTNAME", O.NotNull)
def email = column[String]("USER_EMAIL", O.NotNull)
def user_email_idx = index("user_email_idx", email, unique = true)
def * = id.? ~ fName ~ lName ~ email <> (User.apply _, User.unapply _)
def forInsert = fName ~ lName ~ email <> ({ (f, l, e) => User(None, f, l, e) }, { u:User => Some((u.firstName, u.lastName, u.email)) })
}
我想执行 Select * 并返回UsersTable
. 是否可以使用 UsersTable 投影来做到这一点?我见过一些看起来像这样的例子
UsersTable.where(_.fName startsWith "H").list
选择符合条件的行。我如何在不传递任何内容的情况下做到这一点?
谢谢!