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

Can we emit compile-error on `.select(fieldname1)` for `struct{fieldname2)`? #1216

Closed
limira opened this Issue Sep 28, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@limira

limira commented Sep 28, 2017

  • Diesel: 0.15
  • Database: sqlite

What I have

CREATE TABLE tablename(
    id INTEGER NOT NULL PRIMARY KEY,
    minx INTEGER,
    miny INTEGER,
    maxx INTEGER,
    maxy INTEGER
);

#[derive(Serialize, Queryable)]
struct River{
    id: i64,
    minx: Option<i32>,
    miny: Option<i32>,
    maxx: Option<i32>,
    maxy: Option<i32>
}

What I did

Note that there is a typo in it. I mistyped: maxy instead of maxx.

tablename.select((id, minx, miny, **maxy**, maxy)).filter(...).load(&con);

The rust program compiled and ran without any issue, but obviously gave me a wrong result that mismatched to my intention.

Can diesel help prevent this type of error?

@sgrif

This comment has been minimized.

Member

sgrif commented Sep 28, 2017

By design, no. Queryable does not correspond to field names, it corresponds to the type. That said, this is on the list of things I'd like to lint for in #573

@sgrif sgrif closed this Sep 28, 2017

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