Skip to content

Commit 4164aca

Browse files
committed
Simplify query_single_cell sql query parameter
By using a `AsRef<str>` instead of a `Into<String>`. This remove the need to locally allocate the string while keeping flexibility for the caller.
1 parent 88c92d5 commit 4164aca

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

internal/mithril-persistence/src/sqlite/connection_extensions.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ use crate::sqlite::SqliteConnection;
88
/// Extension trait for the [SqliteConnection] type.
99
pub trait ConnectionExtensions {
1010
/// Execute the given sql query and return the value of the first cell read.
11-
fn query_single_cell<Q: Into<String>, T: ReadableWithIndex>(
11+
fn query_single_cell<Q: AsRef<str>, T: ReadableWithIndex>(
1212
&self,
1313
sql: Q,
1414
params: &[Value],
1515
) -> StdResult<T>;
1616
}
1717

1818
impl ConnectionExtensions for SqliteConnection {
19-
fn query_single_cell<Q: Into<String>, T: ReadableWithIndex>(
19+
fn query_single_cell<Q: AsRef<str>, T: ReadableWithIndex>(
2020
&self,
2121
sql: Q,
2222
params: &[Value],
2323
) -> StdResult<T> {
24-
let sql = sql.into();
2524
let mut statement = self.prepare(&sql).with_context(|| {
2625
format!(
2726
"Prepare query error: SQL=`{}`",
28-
&sql.replace('\n', " ").trim()
27+
sql.as_ref().replace('\n', " ").trim()
2928
)
3029
})?;
3130
statement.bind(params)?;

0 commit comments

Comments
 (0)