I have a Scala/Play application and I need to join tables from 2 different PostgreSQL databases on the same server using Slick 2. The databases are massive so I don't create classes for my tables manually, I use Slick 2 schema code generator, so if there need to be changes made it has to work with the code generator.
Instead of defining my db url in the conf like this
db.pg1.url="jdbc:postgresql://localhost:5432/db1"
db.pg2.url="jdbc:postgresql://localhost:5432/db2"
...
I'd like to do it like this:
db.pg.url="jdbc:postgresql://localhost:5432"
and then my method would look something like this:
def test = DB("pg").withDynSession { //not sure if this is 100% correct
//query joining two tables from different databases here
}
As in, connect to the server, but not a particular database, so that I could work with multiple databases using the same connection. Is this possible? I use this approach already with Slick Plain SQL and it works just fine. Side question: would this have some negative impact on performance?
If what I want to accomplish is possible, can you please provide me with a simple example. If this is not possible, what are my alternatives? Thanks.
My stack:
- Scala 2.10.3
- Play 2.2.2
- Slick 2.0
- PostgreSQL 9.3.3
- Java 8