Skip to content
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

TryGetable for Option<T> Should Handle Errors #63

Closed
billy1624 opened this issue Aug 6, 2021 · 2 comments
Closed

TryGetable for Option<T> Should Handle Errors #63

billy1624 opened this issue Aug 6, 2021 · 2 comments
Assignees

Comments

@billy1624
Copy link
Member

We should not ignore any errors when decoding db result.

match row.try_get(column.as_str()) { 
    Ok(v) => Ok(Some(v)), 
    // Error ignored
    Err(_) => Ok(None), 
} 

For example:

impl TryGetable for Option<$type> {
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr> {
let column = format!("{}{}", pre, col);
match &res.row {
#[cfg(feature = "sqlx-mysql")]
QueryResultRow::SqlxMySql(row) => {
use sqlx::Row;
match row.try_get(column.as_str()) {
Ok(v) => Ok(Some(v)),
Err(_) => Ok(None),
}
}
#[cfg(feature = "sqlx-postgres")]
QueryResultRow::SqlxPostgres(row) => {
use sqlx::Row;
match row.try_get(column.as_str()) {
Ok(v) => Ok(Some(v)),
Err(_) => Ok(None),
}
}
#[cfg(feature = "sqlx-sqlite")]
QueryResultRow::SqlxSqlite(row) => {
use sqlx::Row;
match row.try_get(column.as_str()) {
Ok(v) => Ok(Some(v)),
Err(_) => Ok(None),
}
}
#[cfg(feature = "mock")]
QueryResultRow::Mock(row) => match row.try_get(column.as_str()) {
Ok(v) => Ok(Some(v)),
Err(_) => Ok(None),
},
}
}
}

@billy1624
Copy link
Member Author

Encountered this issue on #60, where most of the errors silenced whentry_get() an Option<T> in Postgres.

@billy1624
Copy link
Member Author

Probably fixed at 1eb4900.

@billy1624 billy1624 self-assigned this Aug 6, 2021
@tyt2y3 tyt2y3 closed this as completed Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants