Play 2 框架中的多个数据源与 slick
Several data source in Play 2 framework with slick
如何在 Play 2.5.x Framework
和 Slick
中配置和使用多个数据源?
例如,一个数据源应该是 MySQL
,另一个是 PostgreSQL
.
slick.dbs.default.driver = "utils.db.TetraoPostgresProfile$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = "jdbc:postgresql://localhost:5432/templatesite_db"
slick.dbs.default.db.user = "user"
slick.dbs.default.db.password = "pass"
slick.dbs.secondary.driver = "slick.jdbc.MySQLProfile$"
slick.dbs.secondary.db.driver = "com.mysql.jdbc.Driver"
slick.dbs.secondary.db.url = "jdbc:mysql://localhost:3306/dbName"
slick.dbs.secondary.db.user = "root"
slick.dbs.secondary.db.password = "pass"
这在 Scala 数据库文档页面中直接解决:
// inject "orders" database instead of "default"
class ScalaInjectNamed @Inject()(
@NamedDatabase("orders") db: Database) extends Controller {
// do whatever you need with the db
}
https://www.playframework.com/documentation/2.5.x/PlaySlick#usage
https://www.playframework.com/documentation/2.5.x/ScalaDatabase#obtaining-a-jdbc-connection
如何在 Play 2.5.x Framework
和 Slick
中配置和使用多个数据源?
例如,一个数据源应该是 MySQL
,另一个是 PostgreSQL
.
slick.dbs.default.driver = "utils.db.TetraoPostgresProfile$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = "jdbc:postgresql://localhost:5432/templatesite_db"
slick.dbs.default.db.user = "user"
slick.dbs.default.db.password = "pass"
slick.dbs.secondary.driver = "slick.jdbc.MySQLProfile$"
slick.dbs.secondary.db.driver = "com.mysql.jdbc.Driver"
slick.dbs.secondary.db.url = "jdbc:mysql://localhost:3306/dbName"
slick.dbs.secondary.db.user = "root"
slick.dbs.secondary.db.password = "pass"
这在 Scala 数据库文档页面中直接解决:
// inject "orders" database instead of "default"
class ScalaInjectNamed @Inject()(
@NamedDatabase("orders") db: Database) extends Controller {
// do whatever you need with the db
}
https://www.playframework.com/documentation/2.5.x/PlaySlick#usage
https://www.playframework.com/documentation/2.5.x/ScalaDatabase#obtaining-a-jdbc-connection