# Interactions with multiple databases

**URL:** <https://discourse.diesel.rs/t/interactions-with-multiple-databases/147>\
**Category:** Uncategorized\
**Created:** [May 8, 2020, 6:41pm UTC](https://discourse.diesel.rs/t/interactions-with-multiple-databases/147 "2020-05-08T18:41:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![btv](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@btv](https://discourse.diesel.rs/u/btv)\
**Post date:** [May 8, 2020, 6:41pm UTC](https://discourse.diesel.rs/t/interactions-with-multiple-databases/147/1 "2020-05-08T18:41:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tema3210](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.diesel.rs/tema3210/32/77_2.png) [@tema3210](https://discourse.diesel.rs/u/tema3210)\
**Post date:** [May 9, 2020, 7:04pm UTC](https://discourse.diesel.rs/t/interactions-with-multiple-databases/147/2 "2020-05-09T19:04:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![btv](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@btv](https://discourse.diesel.rs/u/btv)\
**Post date:** [May 12, 2020, 6:49pm UTC](https://discourse.diesel.rs/t/interactions-with-multiple-databases/147/3 "2020-05-12T18:49:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tema3210](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.diesel.rs/tema3210/32/77_2.png) [@tema3210](https://discourse.diesel.rs/u/tema3210)\
**Post date:** [May 12, 2020, 7:20pm UTC](https://discourse.diesel.rs/t/interactions-with-multiple-databases/147/4 "2020-05-12T19:20:03Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![btv](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@btv](https://discourse.diesel.rs/u/btv)\
**Post date:** [May 12, 2020, 7:44pm UTC](https://discourse.diesel.rs/t/interactions-with-multiple-databases/147/5 "2020-05-12T19:44:52Z")

</div>

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/](https://actix.rs/docs/databases/))

---

<div class="post-metadata">

**Author:** ![tema3210](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.diesel.rs/tema3210/32/77_2.png) [@tema3210](https://discourse.diesel.rs/u/tema3210)\
**Post date:** [May 12, 2020, 8:45pm UTC](https://discourse.diesel.rs/t/interactions-with-multiple-databases/147/6 "2020-05-12T20:45:39Z")

</div>

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.
