Skip to content

Commit ada630e

Browse files
committed
refactor: Add Query::sql_display instead.
`Debug` for `Query` isn't a good idea.
1 parent bfaf39c commit ada630e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/query.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use hyper::{header::CONTENT_LENGTH, Method, Request};
22
use serde::Deserialize;
3-
use std::fmt;
3+
use std::fmt::Display;
44
use url::Url;
55

66
use crate::headers::with_request_headers;
@@ -23,12 +23,6 @@ pub struct Query {
2323
sql: SqlBuilder,
2424
}
2525

26-
impl fmt::Debug for Query {
27-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28-
write!(f, "{sql}", sql = self.sql)
29-
}
30-
}
31-
3226
impl Query {
3327
pub(crate) fn new(client: &Client, template: &str) -> Self {
3428
Self {
@@ -37,6 +31,11 @@ impl Query {
3731
}
3832
}
3933

34+
/// Display SQL query as string.
35+
pub fn sql_display(&self) -> &impl Display {
36+
&self.sql
37+
}
38+
4039
/// Binds `value` to the next `?` in the query.
4140
///
4241
/// The `value`, which must either implement [`Serialize`] or be an

tests/it/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ async fn prints_query() {
221221

222222
let q = client.query("SELECT ?fields FROM test WHERE a = ? AND b < ?");
223223
assert_eq!(
224-
format!("{q:?}"),
224+
format!("{}", q.sql_display()),
225225
"SELECT ?fields FROM test WHERE a = ? AND b < ?"
226226
);
227227
}

0 commit comments

Comments
 (0)