mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-01-01 00:18:50 +00:00
Better anticipation of errors
This commit is contained in:
parent
f9a8cd4e82
commit
faa31f599a
@ -248,11 +248,14 @@ impl<'a> RowResult<'a> {
|
|||||||
/// Query a single row of the database
|
/// Query a single row of the database
|
||||||
pub fn query_row<E, F: Fn(&RowResult) -> ProcessRowResult<E>>(mut info: QueryInfo,
|
pub fn query_row<E, F: Fn(&RowResult) -> ProcessRowResult<E>>(mut info: QueryInfo,
|
||||||
process_function: F) -> Result<E, Box<dyn Error>> {
|
process_function: F) -> Result<E, Box<dyn Error>> {
|
||||||
|
let table = info.table.clone();
|
||||||
|
|
||||||
info.limit = 1;
|
info.limit = 1;
|
||||||
let mut list = query(info, process_function)?;
|
let mut list = query(info, process_function)?;
|
||||||
|
|
||||||
match list.len() {
|
match list.len() {
|
||||||
0 => Err(ExecError::boxed_new("Request did not return a result!")),
|
0 => Err(ExecError::boxed_string(
|
||||||
|
format!("Database query did not return a result: (table: {}) !", table))),
|
||||||
_ => Ok(list.remove(0))
|
_ => Ok(list.remove(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,7 +437,7 @@ pub fn delete(query: DeleteQuery) -> ResultBoxError<()> {
|
|||||||
|
|
||||||
get_connection()?.exec_drop(
|
get_connection()?.exec_drop(
|
||||||
query_sql,
|
query_sql,
|
||||||
query.conditions.values().collect::<Vec<&Value>>()
|
query.conditions.values().collect::<Vec<&Value>>(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user