Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add MySQL storage support #1003

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

feat: add MySQL storage support #1003

wants to merge 10 commits into from

Conversation

devhaozi
Copy link

Summary

Add MySQL storage support, close #283

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable.
  • Updated documentation in README.md, if applicable.

Comment on lines +419 to +424
var query string
if s.driver == "mysql" {
query = `SELECT resolve_key, number_of_successes_in_a_row FROM endpoint_alerts_triggered WHERE endpoint_id = (SELECT endpoint_id FROM endpoints WHERE endpoint_key = ? LIMIT 1) AND configuration_checksum = ?`
} else {
query = `SELECT resolve_key, number_of_successes_in_a_row FROM endpoint_alerts_triggered WHERE endpoint_id = (SELECT endpoint_id FROM endpoints WHERE endpoint_key = $1 LIMIT 1) AND configuration_checksum = $2`
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really a fan of having those if/else blocks for each SQL query. With just postgres and sqlite it was easy because they both have the same syntax, but now with mysql, I think we might need a different solution.

Does ? work with sqlite and postgres as well? Or does postgres/sqlite require $1/$2/$...? Because in most cases, the query is exactly the same, outside of how prepared parameters are passed

Copy link
Author

@devhaozi devhaozi Feb 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really a fan of having those if/else blocks for each SQL query. With just postgres and sqlite it was easy because they both have the same syntax, but now with mysql, I think we might need a different solution.

Does ? work with sqlite and postgres as well? Or does postgres/sqlite require $1/$2/$...? Because in most cases, the query is exactly the same, outside of how prepared parameters are passed

Unfortunately, ? is MySQL-specific, and $... is Postgres-specific. If necessary, I recommend using an ORM (e.g. gorm, xorm, ent) to smooth over these differences.

@devhaozi
Copy link
Author

Tested in my local environment and ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for MariaDB/MySQL
2 participants