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

Consider #[derive(QueryAll)] #1435

Closed
sgrif opened this issue Dec 23, 2017 · 1 comment · Fixed by #2741
Closed

Consider #[derive(QueryAll)] #1435

sgrif opened this issue Dec 23, 2017 · 1 comment · Fixed by #2741

Comments

@sgrif
Copy link
Member

sgrif commented Dec 23, 2017

Not sold on the name. We should come up with a better one.

A question that periodically comes up is "my Queryable struct uses all but one column from my table. How do I do this?"

In crates.io we have the following:

/// We literally never want to select `textsearchable_index_col`
/// so we provide this type and constant to pass to `.select`
type AllColumns = (
    crates::id,
    crates::name,
    crates::updated_at,
    crates::created_at,
    crates::downloads,
    crates::description,
    crates::homepage,
    crates::documentation,
    crates::readme,
    crates::readme_file,
    crates::license,
    crates::repository,
    crates::max_upload_size,
);

pub const ALL_COLUMNS: AllColumns = (
    crates::id,
    crates::name,
    crates::updated_at,
    crates::created_at,
    crates::downloads,
    crates::description,
    crates::homepage,
    crates::documentation,
    crates::readme,
    crates::readme_file,
    crates::license,
    crates::repository,
    crates::max_upload_size,
);

impl Crate {
    pub fn all() -> diesel::dsl::Select<crates::table, AllColumns> {
        crates::table.select(ALL_COLUMNS)
    }
}

This seems like a reasonable pattern to derive in Diesel. I'd want to pull this into a trait though so the type and constant can become an associated type and associated constant. I think I'd also want to call them UsedColumns.

@weiznich
Copy link
Member

That's basically #2367?

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

Successfully merging a pull request may close this issue.

3 participants