Using Multiple DBs with Drizzle
Hey all, I'm using T3 for a proof of concept at the startup I work at. I'm really really digging this stack and want to pitch it to our team to replace our current stack.
I've chosen to work with Drizzle, can explain more why if necessary but will wave my hands at that for a moment.
One key thing I need to demonstrate in the POC is that I can run queries on multiple DBs that live on different hosts. I did not think I'd get stuck on this bit! But I'm stumped. Here's what I've done:
I have config and schema defined for two DBs. I'll call them DB1 and DB1. I'm able to connect to them separately with Drizzle Studio, so I know I have the connections working.
I assumed I could just put DB2 into the TRPC context here (
Then in an rpc when I use db2 like so:
I get the error
One more weirdsie!
Let's say there's a table called
I can call this successfully:
Clearly I'm doing something wrong and it isn't obvious to me how I get the second DB into context! Thanks in advance!
I've chosen to work with Drizzle, can explain more why if necessary but will wave my hands at that for a moment.
One key thing I need to demonstrate in the POC is that I can run queries on multiple DBs that live on different hosts. I did not think I'd get stuck on this bit! But I'm stumped. Here's what I've done:
I have config and schema defined for two DBs. I'll call them DB1 and DB1. I'm able to connect to them separately with Drizzle Studio, so I know I have the connections working.
I assumed I could just put DB2 into the TRPC context here (
src/server/api) :Then in an rpc when I use db2 like so:
I get the error
relation "foo" does not exist. foo does exist on the schema for db2. Code completion knows about it and like I mentioned Drizzle Studio connects to db2 and I can see the foo table.One more weirdsie!
Let's say there's a table called
bar in db1.I can call this successfully:
Clearly I'm doing something wrong and it isn't obvious to me how I get the second DB into context! Thanks in advance!