【问题标题】:MySQL in Slick 3.1Slick 3.1 中的 MySQL
【发布时间】:2016-08-27 00:17:24
【问题描述】:

我一直在浏览 Slick 示例并尝试使用它们连接到 MySQL 数据库。但是 sbt 控制台抱怨它找不到值列:

class MySQLCatalogue(tag: Tag) extends Table[(Long, String, String)](tag, "COLUMNS") {
  def pos: Column[Long] = column[Long]("ORDINAL_POSITION")
  def id: Column[String] = column[String]("COLUMN_NAME")
  def dtype: Column[String] = column[String]("DATA_TYPE")

  def * = (pos, id, dtype)
}

我在网上找到的例子 import scala.slick.driver.MySQLDriver.simple._ 但那个 import 没有做到。有人知道我在这里缺少什么吗?

【问题讨论】:

  • 能否提供编译器输出?
  • 和你正在使用的导入

标签: scala slick


【解决方案1】:

试试这些导入:

import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._

import play.api.db.slick.DatabaseConfigProvider // if you are using play-slick

【讨论】:

    【解决方案2】:

    如果你使用带有 Guice 依赖注入的 play 2.5.x。

    你必须导入dbConfig.driver.api._

    @Singleton 
    class UsersRepo @Inject()(protected val dbConfigProvider:DatabaseConfigProvider) {
     val dbConfig = dbConfigProvider.get[JdbcProfile]
     import dbConfig.driver.api._
     val users = TableQuery[Users]
    
     class Users(tag: Tag) extends Table[User](tag, UsersTable.name) {
       def id = column[UserId]("user_id", O.PrimaryKey)
       def email = column[Email]("email")
       def * = (email, id) <> (User.tupled, User.unapply)
       def emailIndex = index("users_email_index", email, true)
     }
    }
    

    【讨论】:

      【解决方案3】:
      import slick.driver.MySQLDriver.api._
      case class Keyword(keyword: String, active: Int, id: Long = 0L)
      class KeywordTable(tag : Tag) extends Table[Keyword](tag, "COLUMNS") {
        def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
        def keyword = column[String]("keyword")
        def active = column[Int]("active")
        def * = (keyword,active,id) <> (Keyword.tupled, Keyword.unapply)
      }
      

      此示例有效(Playframework 2.5.4 和 Slick 3.1)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多