加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 在Slick中导入不同的数据库驱动程序

发布时间:2020-12-16 18:55:07 所属栏目:安全 来源:网络整理
导读:Slick 3有“import api”来使用特定的数据库驱动程序.例如 import slick.driver.H2Driver.api._...DAO implementation... 要么 import slick.driver.PostgresDriver.api._...DAO implementation... 如何在生产中使用postgresql,在单元测试中使用h2? 解决方
Slick 3有“import api”来使用特定的数据库驱动程序.例如

import slick.driver.H2Driver.api._
...DAO implementation...

要么

import slick.driver.PostgresDriver.api._
...DAO implementation...

如何在生产中使用postgresql,在单元测试中使用h2?

解决方法

请改用 DatabaseConfig.正如 Slick documentation所述:

On top of the configuration syntax for Database,there is another
layer in the form of DatabaseConfig which allows you to configure a
Slick driver plus a matching Database together. This makes it easy to
abstract over different kinds of database systems by simply changing a
configuration file.

首先获取DatabaseConfig,而不是导入特定于数据库的驱动程序:

val dbConfig = DatabaseConfig.forConfig[JdbcProfile]("<db_name>")

然后从中导入api:

import dbConfig.driver.api._

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读