在 Slick 中导入不同的数据库驱动程序
Import different db drivers in Slick
Slick 3 "import api" 可以使用特定的数据库驱动程序。例如
import slick.driver.H2Driver.api._
...DAO implementation...
或
import slick.driver.PostgresDriver.api._
...DAO implementation...
如何在生产中使用 postgresql 并在单元测试中使用 h2?
使用DatabaseConfig
instead. As 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._
Slick 3 "import api" 可以使用特定的数据库驱动程序。例如
import slick.driver.H2Driver.api._
...DAO implementation...
或
import slick.driver.PostgresDriver.api._
...DAO implementation...
如何在生产中使用 postgresql 并在单元测试中使用 h2?
使用DatabaseConfig
instead. As Slick documentation状态:
On top of the configuration syntax for
Database
, there is another layer in the form ofDatabaseConfig
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._