mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Simplify Sql.query_row_col function
Function `query_row` executes query and calls callback function to process row returned. Function query_row_col() is special case, that provides callback function, which returns value of one particular column of row, ignoring others. In all cases, that particular column was 0 (first and only column of query result), since there is no point to select more than one column with this function -- they are discarded anyway. This commit removes that redundancy, removing column number argument of query_row_col() function and adjusting call sites accordingly.
This commit is contained in:
11
src/sql.rs
11
src/sql.rs
@@ -155,19 +155,13 @@ impl Sql {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn query_row_col<P, T>(
|
||||
&self,
|
||||
context: &Context,
|
||||
query: &str,
|
||||
params: P,
|
||||
column: usize,
|
||||
) -> Option<T>
|
||||
pub fn query_row_col<P, T>(&self, context: &Context, query: &str, params: P) -> Option<T>
|
||||
where
|
||||
P: IntoIterator,
|
||||
P::Item: rusqlite::ToSql,
|
||||
T: rusqlite::types::FromSql,
|
||||
{
|
||||
match self.query_row(query, params, |row| row.get::<_, T>(column)) {
|
||||
match self.query_row(query, params, |row| row.get::<_, T>(0)) {
|
||||
Ok(res) => Some(res),
|
||||
Err(Error::Sql(rusqlite::Error::QueryReturnedNoRows)) => None,
|
||||
Err(Error::Sql(rusqlite::Error::InvalidColumnType(
|
||||
@@ -242,7 +236,6 @@ impl Sql {
|
||||
context,
|
||||
"SELECT value FROM config WHERE keyname=?;",
|
||||
params![key.as_ref()],
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user