Does calling `drizzle()` multiple times on the same db client instance consume more resources?

related to a question from: https://github.com/drizzle-team/drizzle-orm/issues/594 Would using the same postgres(...) client instance and creating multiple Drizzle instances from it, e.g. one for each request in a middleware, consume additional database connection resources compared to creating one drizzle instance for the whole server process? @Angelelz this is related to the question you asked in the github issue. I believe my current implementation doesn't have this problem since it uses proxies, but I was about to refactor to call drizzle() once per request and want to make sure I'm not about to blow up my database!
GitHub
[FEATURE]: Support PostgreSQL's Row Level Security (RLS) · Issue #5...
Describe want to want Supabase is really nicely using Row Level Secruity for granular authorization rules. 🔗 Here's the link to their docs: https://supabase.com/docs/guides/auth/row-level-secur...
4 Replies
Angelelz
Angelelz11mo ago
I don't believe it does, because you'd be using the same underlying pool that comes from calling postgres(...) @Dan Kochetov
francis
francisOP11mo ago
I'll just test this locally, actually. Surely I can just use pg_stat_activity and see if creating 1 vs 10 drizzle instances with the same underlying client causes any changes @Angelelz answer: no. and the clients don't actually connect to the database at all until a query is run
Angelelz
Angelelz11mo ago
Excelent, your solution is pretty good
Dan
Dan11mo ago
yea, drizzle() call only wraps an existing connection, so you can create as many Drizzle instances as you need
Want results from more Discord servers?
Add your server