Open janpio opened 1 year ago
Hey @janpio! I was wanting to test it out with option 2 and was trying to think what might be the recommended way of doing it. The developer would need to tell pass what region read replica to go to when they are querying.
To choose the correct read-only region (which are different from your default region), yes - we would probably want to have some "selection criteria". The extension does not support that yet.
We should probably have an independent issue for that. I could imagine that queries somehow get information about where the application is running, and then some logic/function decides the correct read replica based on that data (instead of randomly selecting a replica from the list).
We usually would expect the user to define the code that selects the correct read-only region (for now).
But I am not even sure how to direct it to a specific read-only region if there were multiple ones. I can't use the multiple replicas example from the docs because it is an array where it picks one randomly. Maybe I missed something in the code.
Yes, that is not implemented yet. Right now it is dumb, and there is no way for it to take any logic (e.g. by location) into account. That is why I think we need a new issue.
Then we can make this one about figuring out a way to tell it that there is a same region replica that needs USE @replica
executed once to enable it. And the other issue is about the global read-only replicas, where logic is helpful.
I split the "read-only regions" off into its own issue: https://github.com/prisma/extension-read-replicas/issues/15
PlanetScale does read replicas a bit differently. They have two separate concepts:
This issue is about 1), use case 2) is covered in https://github.com/prisma/extension-read-replicas/issues/15
The "Database replicas" from 1) are not selected via connections strings, but instead you have to run a command on a connection to make it use read replicas:
USE @replica
https://planetscale.com/docs/concepts/replicas#how-to-use-replicas-in-your-planetscale-databaseWe would need a way to "identify" these replicas (maybe a different extension "function"), and then a mechanism to make sure that the SQL command is run on each connection that is used in the "replica clients". Currently Prisma Client does not have the functionality to enforce that as far as I know.