Postgres read slaves?

Is there a way to connect the orm to use a read slave for selects and master for writes?
11 Replies
Angelelz
Angelelz15mo ago
There is no config option or something like that But you could have 2 different instances of Drizzle, each one fed with the same schema, but a different connection string I don't see any issues with running that set up You would use one instance or the other depending on what you're doing
pandareaper
pandareaper15mo ago
It would be good to see Drizzle support this more natively like many other ORMs do. As an ORM it is well positioned to know read vs write queries and automatically route queries to the correct connection/pool
Angelelz
Angelelz15mo ago
Would you like to submit a feature request? You could also create a wrapper object that would handle it for you.
import dbRead from "...";
import dbWrite from "...";

export const db = {
select: dbRead.select,
update: dbWrite.select,
insert: dbWrite.insert,
delete: dbWrite.delete,
query: dbRead.query,
}
import dbRead from "...";
import dbWrite from "...";

export const db = {
select: dbRead.select,
update: dbWrite.select,
insert: dbWrite.insert,
delete: dbWrite.delete,
query: dbRead.query,
}
pandareaper
pandareaper15mo ago
True, I might consider something like that as well. I do have some more advanced read replica query patterns where I would route based on async context / environment configuration where this might be useful
Angelelz
Angelelz15mo ago
Are there ORMs that handle that for you?
pandareaper
pandareaper15mo ago
Not that specifically, it would be quite a niche pattern so I wouldn’t expect any to support it either
Andrii Sherman
Andrii Sherman15mo ago
give us a few days
Angelelz
Angelelz15mo ago
You guys might want to vote on drizzle's twitter pole on this
pandareaper
pandareaper15mo ago
repliwhat 😂
Matan Nahmani
Matan Nahmani14mo ago
any updates?
Want results from more Discord servers?
Add your server