-
-
Notifications
You must be signed in to change notification settings - Fork 521
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
Remove impl TryGetable for Option<T> #108
Conversation
Another solution that saves the APIs could be adding another Trait, like TryGetableInner with actual impl and custom error, and impl<T: TryGetableInner> TryGetable for T {
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr> {
Ok(<T as TryGetableInner>::try_get(res, pre, col)?)
}
} |
src/executor/query.rs
Outdated
@@ -163,16 +134,14 @@ macro_rules! try_getable_unsigned { | |||
QueryResultRow::SqlxSqlite(row) => { | |||
use sqlx::Row; | |||
row.try_get::<Option<$type>, _>(column.as_str()) | |||
.map_err(crate::sqlx_error_to_query_err) | |||
.map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) | |||
.and_then(|opt| opt.ok_or_else(|| TryGetError::Null)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR!
I just get a clippy warning saying this should be opt.ok_or(TryGetError::Null)
instead of the closure.
https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right, I've run clippy but I forgot to play with features to ensure every code path was covered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it can be easy to forget and difficult to test sometimes.. I'm still trying to figure out a good way to get past this.. for now I just change the default features in Cargo.toml temporarily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On some projects I ended up writing a bash script that launch several cargo test with all feature combinations, but it becomes quickly unmaintenable if you change the features on version bumps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we rely heavily on GitHub actions to remind us the 'buildability' of essential feature combinations.
We should add more to SeaORM too.
https://github.com/SeaQL/sea-query/blob/cfae4eab32fcd1a87103cffcf8760315f404656f/.github/workflows/rust.yml#L35-L38
Thank you. I am okay with breaking API, as we are still early. Saying so, we should release it as early as possible, perhaps in |
They should be independent, this one doesn't use Nullable trait introduced with the sea-query PR |
Remove impl TryGetable for Option<T>
Remove impl TryGetable for Option<T>
This PR continues what's I've begun with SeaQL/sea-query#112 and discussed in #107
This time I'm not really sure this is the best solution, but I haven't been able to come up with something better.
There are several concurring situations that made the problem worse:
What I've done:
Pros:
Con:
Let me know what do you think about it