[英]Type Mistmatch Scala Slick Query
我在 scala 中使用 slick 獲取用戶名和密碼時遇到問題,基本上類似於
var query = "SELECT * FROM \"default\".users as A " + "WHERE " + " A.username LIKE \'" + email + "\' " + "AND" + " A.password LIKE \'" + password + "\' ";
這是我的案例 class 的架構
case class User(
id: Long = 0L,
username: String,
password: String,
author_id:Long,
created_on: DateTime,
updated_by: Long,
updated_on:Option[DateTime]
)
class UserTable(tag:Tag) extends Table[User](tag,"user"){
override def * = (id,username,password,author_id,created_on,updated_by,updated_on.?) <> (User.tupled,User.unapply)
def id = column[Long]("id",O.PrimaryKey,O.AutoInc)
def username = column[String]("username")
def password = column[String]("password")
def created_on = column[DateTime]("created_on")
def updated_on = column[DateTime]("dateupdated")
def author_id = column[Long]("author_id")
def updated_by = column[Long]("updated_by")
}
lazy val UserTable = TableQuery[UserTable]
以下是我的查詢
val users = Main.UserTable.filter(_.username == email)
.filter(_.password == password).take(1)
filter(_.username == email)
您可能是指===
而不是==
。
這是構建查詢表達式的 Slick DSL 的一部分(他們不能稱之為==
因為 Scala 的相等比較器無法替換)。
警告:大多數運算符模仿普通的 Scala 等效項,但您必須使用 === 而不是 == 來比較兩個值是否相等,使用 =.= 而不是,= 來比較不等式。 這是必要的,因為這些運算符已經在基本類型 Any 上定義(具有不合適的類型和語義),因此它們不能被擴展方法替換。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.