-
Notifications
You must be signed in to change notification settings - Fork 84
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
Debug Query as SQL string. #155
base: main
Are you sure you want to change the base?
Conversation
Allow to print the current SQL query, whether it's bound or not. Useful for logging and diagnostics.
Allow to print the current SQL query, whether it's bound or not. Useful for logging and diagnostics.
src/query.rs
Outdated
@@ -22,6 +23,12 @@ pub struct Query { | |||
sql: SqlBuilder, | |||
} | |||
|
|||
impl fmt::Debug for Query { | |||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |||
write!(f, "{sql}", sql = self.sql) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query
can easily include more than client
+ sql
in the future and Debug
(despite Display
) shouldn't be so restrictive.
I think, we should leave Query { client: Client, sql: "blabla" }
here and don't pretend it's a simple str-like struct.
Another way is to provide fn sql_display(&self) -> &impl Display
which also covers into_string()
but in more much reliable way for future changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way is to provide fn sql_display(&self) -> &impl Display
@loyd Do I understand it right, that we:
- keep the
impl Display for SqlBuilder
in this PR - remove
impl Debug for Query
- instead, add
fn Query::sql_display
Correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, sql_display
or as_sql
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only misleading Debug
impl, all other changes are fine
`Debug` for `Query` isn't a good idea.
f4da92b
to
ada630e
Compare
Summary
Allow to print the current SQL query, whether it's bound or not. Useful for logging and diagnostics.
Note: I chose
Debug
overDisplay
because the latter is too implicit and somebody might accidentally pass a query into a string.Albeit, something like
fn Query::into_string(self) -> String
can be useful on its own - as a poor man's query builder:closes #146
Checklist
Delete items not relevant to your PR: