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

Allow to set fields to Default when constructing struct from query #1582

Closed

Conversation

weiznich
Copy link
Member

@weiznich weiznich commented Mar 2, 2018

This commit adds a #[diesel(default)] field attribute to
#[derive(Queryable)], that allows a user to set a field to a default
value instead of loading it from the database. This is usefull if the
same struct is used to serve some API that requires additional
information to be added.

This commit adds a `#[diesel(default)]` field attribute to
`#[derive(Queryable)]`, that allows a user to set a field to a default
value instead of loading it from the database. This is usefull if the
same struct is used to serve some API that requires additional
information to be added.
@weiznich weiznich requested a review from a team March 2, 2018 14:25
@sgrif
Copy link
Member

sgrif commented Mar 2, 2018

👎 from me on this idea. It's too unclear what this does, and I don't think there's an easy way to make it obvious. I don't think it's obvious whether this ignores a database column, populates it on null, or changes the expected SQL type.

@weiznich
Copy link
Member Author

weiznich commented Mar 2, 2018

Do you see a problem with this feature in general, or with the naming?
In the second case we could do something similar to serde and use #[diesel(skip)].

@weiznich
Copy link
Member Author

@sgrif To point to a practical use of this, see this example from my wundergraph crate.
If there is any other way to do something similar that does not involve manually implementing Queryable I'm fine with using it.

@sgrif
Copy link
Member

sgrif commented Mar 26, 2018

With the feature in general. I think this affects more things in non-obvious ways than #[serde(skip)] does.

@weiznich
Copy link
Member Author

So is there any other way to solve this without manually implementing Queryable on each struct needing this?

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

Successfully merging this pull request may close these issues.

2 participants