question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use read replica for raw queries

See original GitHub issue

Issue 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:open
  • Created 4 years ago
  • Reactions:10
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
yocontracommented, Nov 12, 2021

@mellogarrett FYI you can use type: 'SELECT', useMaster: false in the options as a workaround

0reactions
ErickValcommented, Mar 31, 2022

@mellogarrett FYI you can use type: 'SELECT', useMaster: false in the options as a workaround

Tried this and Worked, thank you very much.

“sequelize”: “^5.21.12”,

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found