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

Implement From<MaybeUndefined<T>> for Option<Option<T>> #599

Closed
dbstratta opened this issue Aug 13, 2021 · 0 comments · Fixed by #600
Closed

Implement From<MaybeUndefined<T>> for Option<Option<T>> #599

dbstratta opened this issue Aug 13, 2021 · 0 comments · Fixed by #600
Labels
enhancement New feature or request

Comments

@dbstratta
Copy link
Contributor

dbstratta commented Aug 13, 2021

Hey @sunli829 ! Thanks for all the work you put into this crate. It's truly awesome.

Description of the feature

I think it would be useful to easily convert from MaybeUndefined<T> to Option<Option<T>>,
where Undefined => None, Null => Some(None) and Value(a) => Some(Some(a)).

I'm using the Option<Option<T>> pattern to tell in my SQL queries if I should set the value to null or to not update it at all (custom code in SQLx), and Diesel uses this pattern by default too.

Code example

This is the main type of use case I'm imagining:

struct UserChangeset {
  pub name: Option<Option<String>>,
}

#[Object]
impl Mutation {
  async fn change_name(&self, ctx: &Context<'_>, name: MaybeUndefined<String>) -> Result<()> {
    // ...
  
    user.update(UserChangeset { name: name.into() }).await
  }
}

What do you think? (I can implement the feature if you accept it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant