Play Scala: How to Access Multiple Databases with Anorms and Magic [T]

I want to access two databases in Play Scala with anom and Magic [T] (one of them is H2, and the other is PostgreSQL). I just don’t know how to configure it ...

I noticed that we can establish another database connection in conf / application.conf

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

However, how can I use it with Magic? (I read the source code for Magic, but I don’t understand it ... my new to Scala)

In any case, if it is impossible to access several databases with Magic [T], I want to do this with the help of anorm, then how to configure it?

var sqlQuery = SQL(          //I guess some config params should be set here, but how?
    """
      select * from Country
    """
)
+5
source share
1 answer

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 */ }
+2

All Articles