postgresql - 使用 Postgresql 的 Slick 3.2?

标签 postgresql scala slick

官方 Slick 3.2 文档 ( http://slick.lightbend.com/doc/3.2.0/database.html ) 说 Slick 可以用普通的 javax.sql.DataSource 配置,例如 PGSimpleDataSourcePPGoolingDataSource :

val db = Database.forDataSource(dataSource: javax.sql.DataSource, Some(size: Int))

我找不到要导入的数据库对象。

该数据库单例对象甚至不存在于官方 ScalaDoc 中: http://slick.lightbend.com/doc/3.2.0/api/index.html

我在我的 build.sbt 中包含以下依赖项。我是否缺少 slick-postgresql 绑定(bind)或某些其他依赖项,这些依赖项具有文档中指定的缺少 Database 对象?

"com.typesafe.slick" %% "slick" % "3.2.0"
"org.postgresql" % "postgresql" % "42.0.0"

最佳答案

Quick Intro部分说

// Use H2Profile to connect to an H2 database
import slick.jdbc.H2Profile.api._

Since we are using H2 as our database system, we need to import features from Slick’s H2Profile. A profile’s api object contains all commonly needed imports from the profile and other parts of Slick such as database handling.

所以我相信你想导入 PostgresProfile接口(interface):

import slick.jdbc.PostgresProfile.api._

关于postgresql - 使用 Postgresql 的 Slick 3.2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42495387/

相关文章:

scala - 如何使用光滑的 tomcat jdbc 池?

sql - 在 PostgreSQL 中获取两个日期之间的结果

postgresql - 将 Date.now() 保存到时间戳列但获取超出范围的日期/时间字段值

sql - 如何计算时差(HH :MM:SS) from date_time (ISO format) in Postgres

scala - 在 Spark 中过滤停用词

scala - Scala 中的运算符优先级

scala - Oracle Slick 驱动程序支持流吗?

mysql - 每个数据库提供程序类型允许的最大参数数是多少?

scala - 初始化顺序在延迟 val 访问时抛出空指针

scala - 使用 Scala + Slick + MySQL + Akka + Stream 面临的问题