Reputation: 22596
I'm building a website using Yesod and Persistent (I'm using the basic yesod mysql scaffolding).
I need to access a different database that the main one, but runDB
uses
the default connection parameter and connection. Is there a simple way to use Persistent with two different connection parameters ?
Upvotes: 1
Views: 186
Reputation: 22596
Looking at the scaffolded code, it should be easy to define another rundDB
accessing another pool created with different connection parameters. This implies to also modify the Settings
to read and stote the extra connection info.
However, one of the main issue is, one needs to remember which connection (or wich runDB
) to use depending on the data type to load. Another solution is to use federated tables.
MySql (or MariaDB) allows to create a proxy table connected to a remote database. Even though it needs a some setup, this as the advantage to be safe and easier to use on the client side.
Upvotes: 0
Reputation: 322
The function that creates a connection (like runSqlite
) is in the IO
monad. That means that you can call it in a Handler
function in your Yesod application with liftIO
. You can also immediately run queries on the database, so that's pretty neat.
Upvotes: 1