5

我想用 anorm 和 Magic[T] 访问 Play Scala 中的两个数据库(一个是 H2,另一个是 PostgreSQL)。就是不知道怎么配置。。。

我注意到我们可以在 conf/application.conf 中设置另一个数据库连接

db_other.url=jdbc:mysql://localhost/test
db_other.driver=com.mysql.jdbc.Driver
db_other.user=root
db_other.pass=

但是,我如何将它与 Magic 一起使用?(我看了Magic的源代码但是看不懂……我是Scala的大一新生)

无论如何,如果使用 Magic[T] 无法访问多个数据库,我希望使用 anorm 来完成,那么我该如何配置呢?

var sqlQuery = SQL(          //I guess some config params should be set here, but how?
    """
      select * from Country
    """
)
4

1 回答 1

2

play.api.db.DB它看来,您可以传入您在中定义的名称的字符串application.conf

然后使用此处指定的方法之一:http ://www.playframework.org/documentation/2.0/ScalaDatabase

# play.api.db.DB.class

def withConnection[A](name : scala.Predef.String)(block : scala.Function1[java.sql.Connection, A])(implicit app : play.api.Application) : A = { /* compiled code */ }
于 2012-04-01T22:26:27.970 回答