eoin-obrien / prisma-extension-kysely

Drop down to raw SQL in Prisma without sacrificing type safety!
https://www.npmjs.com/package/prisma-extension-kysely
MIT License
207 stars 5 forks source link

feat(reader): add support for read replica #137

Open johannsonic opened 2 months ago

johannsonic commented 2 months ago

Hey!

We had a big problem in our production setup where all raw prisma-kysely queries hit our writer db, even for read-only operations. With this proposed solution, one can pass a configuration object to the extension and opt-in to use the replica instance for read queries.

I already used this implementation in our prod setup and our writer instance immediately cooled down :)

Johann

tylerjbainbridge commented 1 month ago

Would love to see this landed :)

eoin-obrien commented 3 weeks ago

Hi, and thanks for using prisma-extension-kysely!

The extension should work with read replicas as-is, but the order the extensions are applied in (and the way the read replicas are created) can result in the primary Kysely instance being shared across the .$primary().$kysely and .$replica().$kysely.

I've added some documentation on it to the readme if you'd like to check it out and see if it works properly when run like that.