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

Tables with a single column aren't queryable #261

Closed
sgrif opened this Issue Apr 9, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@sgrif
Member

sgrif commented Apr 9, 2016

Reported via gitter

table! {
    users {
        id -> Integer,
    }
}

#[derive(Queryable)]
pub struct User {
    pub id: i32,
}

users.load::<User>(&connection).expect("Error loading users");
@sgrif

This comment has been minimized.

Member

sgrif commented Apr 9, 2016

Two issues here. The first is that table! is generating all_columns = (id) instead of all_columns = (id,). This is the actual bug. However, I think it probably makes sense for us to generate a queryable impl for T as well as (T,) when a struct has only one field. That's a separate addition.

sgrif added a commit that referenced this issue Apr 9, 2016

Properly generate a single element tuple for 1 column tables
Our code was generating `(id)` and not `(id,)`. Without the trailing
comma, the parenthesis are meaningless. This meant that you couldn't
actually load the query into a struct without manually selecting the
tuple.

While this fixes the bug, I think it probably also makes sense for us to
have a `FromSqlRow` and `Queryable` impl for the non-tuple type into a
single element tuple/struct.

Fixes #261

@sgrif sgrif closed this in #262 Apr 10, 2016

sgrif added a commit that referenced this issue Apr 10, 2016

Properly generate a single element tuple for 1 column tables (#262)
Our code was generating `(id)` and not `(id,)`. Without the trailing
comma, the parenthesis are meaningless. This meant that you couldn't
actually load the query into a struct without manually selecting the
tuple.

While this fixes the bug, I think it probably also makes sense for us to
have a `FromSqlRow` and `Queryable` impl for the non-tuple type into a
single element tuple/struct.

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