Something like sql_tracker for Crystal

Hi,

The problem:

  • I want to enable a “query counter” and a query threshold, so I can enable this on CI using an environment variable and the test just explodes if we pass the threshold.

This is good to avoid N+1 issues (and others) that pass unnoticed by code review or just to try to keep the number of SQL queries issued under a safe limit.

Do you guys know any solution for Crystal? Or do I need to write my own shard?

1 Like

I used this gem extensively in the past in my Rails projects: GitHub - civiccc/db-query-matchers: RSpec matchers for database queries. I haven’t seen one in Crystal though. But I’d think it should be relatively easy with crystal-db interface, right?

I’m not aware of any matchers. But they should be able to be built on top of Add logging for executing queries by bcardiff · Pull Request #134 · crystal-lang/crystal-db · GitHub probably

2 Likes

The project uses Avram as ORM, so initially I though about attach it to avram query log, but I was thinking more about something that attaches to crystal-db itself, so I can de-couple it from the ORM and the database driver at the same time… this PR on crystal-db will make everything possible. Thanks!

2 Likes