Interactions with multiple databases

Is it possible to use diesel to interact with multiple databases? I’m building an API that needs to forward data into two different databases. I don’t think that diesel can do that yet, but I don’t know and I thought I’d ask.

You just need to maintain connection pools and schemas yourself. Diesel buildsclearly separate query building and database tables from connections.

Thank you for the reply @tema3210. I realized by your answer that I might have asked the question incorrectly. So I’ll try again with different words.

Is if possible to to have diesel connect to two (or more) separate postgres instances? If so, can you maybe provide an example or at least a place to start looking?

Yea, sure create two schemas, two ORM modules and work with two connection pools, diesel has separated connections and query building: you can build the query against unexisting table and never execute it, so SQL code will never be sent to database and you will never get errors :slight_smile:

Thank you for your answer. I’m still new to Diesel (only used it for a personal project in relation to Actix). I’m not sure what you mean by an ORM module? Would that be similar to a model in Actix jargon? (https://actix.rs/docs/databases/)

Well, now I’m using these two together too. I would recomend manually specify versions of actix-web, actix-rt, use tokio-diesel crate (its alpha so you’d have to implement custom error types) for thread and connection pool all in one, diesel features will include “r2d2”. This is how to get easy working async interface for diesel.