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

derive(Table) functionality #1668

Closed
theduke opened this Issue Apr 29, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@theduke
Contributor

theduke commented Apr 29, 2018

Quite a while ago I wrote a small crate that allows deriving a Table implementation for a struct.

I never published it, but used it in multiple projects: https://github.com/theduke/diesel_derive_table
I think it's quite handy.
Especially with something like CockroachDB where print-schema does not work it helps to prevent quite a bit of duplication.

I talked with @sgrif a bit in Gitter before implementing this, and I remember him not being very enthused about it.

I still think it's really useful as an alternative workflow.

If the maintainers think this would be nice to have in core, I can whip up a PR.

Sample usage:

#[macro_use] extern crate diesel_derive_table

#[derive(Table, Queryable, AsChangeset, Insertable, Identifiable)]
#[table_name="reddit_posts"]
#[primary_key(uuid)]
pub struct RedditPost {
    #[column_type="Text"]
    #[column_name="my_uuid"]
    pub uuid: String,
    #[column_type="BigInt"]
    pub created_at: i64,
}
@sgrif

This comment has been minimized.

Member

sgrif commented Apr 29, 2018

I think you should publish this as a separate crate and see how it goes.

@sgrif sgrif closed this Apr 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment