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

Improve derive functionality (skip and defaults) #1574

Closed
theduke opened this issue Feb 25, 2018 · 1 comment
Closed

Improve derive functionality (skip and defaults) #1574

theduke opened this issue Feb 25, 2018 · 1 comment

Comments

@theduke
Copy link
Contributor

theduke commented Feb 25, 2018

I often want a few tweaks to the various derivable traits that would improve quality of life quite a bit.

They are mostly inspired by serde_derive, which has similar features.

If this is ok with the maintainers, I'd start working on a PR for this.

Skip

Allow skipping of fields for AsChangeset and Insertable.
A plain skip would already be useful.
What would be even more useful is selective skipping eg only for updates.

#[derive(Insertable, AsChangeset)]
#[table_name....]
struct User {
    id: Uuid,
    username: String,
    #[diesel(skip_on = "update")]
    created_at: DateTime<Utc>,
    
    #[diesel(skip)]
    extra_non_db_field: Vec<_>,
}

Default

#[derive(Queryable)]
...
struct User {
    ....
     // Will use Default::default()
     #[diesel(default)]
    extra_value: Option<_>,
    // Will use custom function
     #[diesel(default = "::user::whatever_default")]
    extra_value: Whatever,
}

Attribute names

It seems to be an established practice to wrap attributes with the crate name to be more specific, a la serde(...), ...
It's somewhat ok for things like table_name and primary_key, but
not really for default and skip, since they are so generic.
So i'd propose wrapping for those.

Actually, I'd also propose adding new variants for the existing attributes, and maybe at some point deprecating the old ones, but that's another discussion.

@theduke theduke changed the title Improve derive functionality Improve derive functionality (skip and defaults) Feb 25, 2018
@sgrif
Copy link
Member

sgrif commented Feb 26, 2018

Duplicate of #860.

@sgrif sgrif closed this as completed Feb 26, 2018
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