martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
405 stars 23 forks source link

Add #to_sql method to query sets #130

Closed ellmetha closed 3 months ago

ellmetha commented 9 months ago

Description

It should be possible to see the SQL queries generated for specific query sets. This is something that can be useful in order to debug or better understand complex query sets.

In this light, let's introduce a new #to_sql method at the query set level:

User.filter(username: "foo").to_sql
# => "SELECT auth_user.id, auth_user.email, auth_user.username FROM \"users\"  WHERE auth_user.username = \"foo\""