To access a database one has to specify the DB details in the conf file.
If the DB is up everything works fine.
If the DB is down Play throws an exception, which I cannot control.
I would like to conditionally connect to a DB. Lets say I only want to connect to a DB if a flag is set somewhere. Is there a more manual way to connect to a DB in Play?
Update: I guess I haven't been very clear.
I want the App to not fail if the DB is down and fetch data from other alternate sources. How can I accomplish this in PLAY?
I assume you want to start your app without a DB for development? You can pass an alternative config file on startup where you for example configure a in memory db:
start -Dconfig.resource=development.conf
edit:
You can configure several databases in your app config and get them with DB.getDataSource(name: String)
or get a connection to it with DB.getConnection(name: String)
or even run a transaction with DB.getConnection[A](name: String)(f: Connection => A)
see: http://www.playframework.org/documentation/api/2.0/scala/index.html#play.api.db.DB$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With