简体   繁体   English

类型不匹配 Scala 灵活查询

[英]Type Mistmatch Scala Slick Query

I am having trouble to get username and password using slick in scala like basically similar to something like我在 scala 中使用 slick 获取用户名和密码时遇到问题,基本上类似于

var query = "SELECT * FROM  \"default\".users as A " + "WHERE " + " A.username LIKE \'" + email + "\' " + "AND" + " A.password LIKE \'" + password + "\' ";

Here is my case class for schema这是我的案例 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]

Below is my Query以下是我的查询

val users = Main.UserTable.filter(_.username == email)
      .filter(_.password  == password).take(1)
filter(_.username == email)

You probably meant === instead of == .您可能是指===而不是==

That is part of the Slick DSL to build query expressions (and they could not call it == because Scala's equality comparator cannot be replaced).这是构建查询表达式的 Slick DSL 的一部分(他们不能称之为==因为 Scala 的相等比较器无法替换)。

Warning : Most operators mimic the plain Scala equivalents, but you have to use === instead of == for comparing two values for equality and =.= instead of,= for inequality. 警告:大多数运算符模仿普通的 Scala 等效项,但您必须使用 === 而不是 == 来比较两个值是否相等,使用 =.= 而不是,= 来比较不等式。 This is necessary because these operators are already defined (with unsuitable types and semantics) on the base type Any, so they cannot be replaced by extension methods.这是必要的,因为这些运算符已经在基本类型 Any 上定义(具有不合适的类型和语义),因此它们不能被扩展方法替换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM