Use read replica for raw queries
See original GitHub issueIssue Description
Is your feature request related to a problem? Please describe.
When executing raw SQL queries, sequelize always uses the write
host.
Describe the solution you’d like
When you know that your raw SQL query is a read-only query, it would be great to be able to delegate to the read replica.
Why should this be in Sequelize
Seems like a pretty common usecase that could benefit a lot of people. Limiting the read replica use to only queries generated from models is not ideal.
Describe alternatives/workarounds you’ve considered
Can’t think of any.
Additional context
I tried to pass { type: QueryTypes.SELECT }
to the .query
method thinking that might use the read replica but no luck.
Issue Template Checklist
Is this issue dialect-specific?
- No. This issue is relevant to Sequelize as a whole.
- Yes. This issue only applies to the following dialect(s): XXX, YYY, ZZZ
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don’t know how to start, I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Read Replication - Sequelize
Each write or useMaster: true query will use write pool. For SELECT read pool will be used. Read replica are switched using a...
Read more >Working with read replicas - AWS Documentation - Amazon.com
When you create a read replica, you first specify an existing DB instance as the source. Then Amazon RDS takes a snapshot of...
Read more >Proper way of implementing the DB queries to read and write ...
So, eventually, I have solved it in a rather straightforward way: created separate connection pools for read and write DB replicas and used...
Read more >Basic usage - Manual | Sequelize
When you do read replication, you specify one or more servers to act as read replicas, and one server to act as the...
Read more >Database Read Replicas vs PolyScale Database Edge Caching
Read replicas are commonly used to reduce load on the primary database; frequent or complex queries can be run against the replicas without ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mellogarrett FYI you can use
type: 'SELECT', useMaster: false
in the options as a workaroundTried this and Worked, thank you very much.
“sequelize”: “^5.21.12”,