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

Problems with `insertable_into` for table with underscore in name #285

Closed
freiguy1 opened this Issue Apr 20, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@freiguy1

freiguy1 commented Apr 20, 2016

I've a table called game_location. I've some rust code looking like this:

 #[insertable_into(game_location)]
 pub struct NewGameLocation {
     pub name: String,
     pub league_id: i32
 }

Here's my up.sql migration:

CREATE TABLE game_location (
    id SERIAL PRIMARY KEY,
    name INTEGER NOT NULL,
    league_id INTEGER NOT NULL REFERENCES league(id)
);

I'm using insertable_into and diesel for 3 other tables and all went swimmingly. Now I'm having issues with this particular one, but it's the first table with an underscore in the name.

Here is the error output:

/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14:1: 14:34 error: the trait `diesel::expression::Expression` is not implemented for the type `collections::string::String` [E0277]
/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14 #[insertable_into(game_location)]
                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14:1: 14:34 note: in this expansion of #[insertable_into] (defined in /home/freied/dev/git/league-api/db/src/repo/game_location.rs)
/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14:1: 14:34 help: run `rustc --explain E0277` to see a detailed explanation
/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14:1: 14:34 note: required by `diesel::expression::AsExpression::as_expression`
/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14:1: 14:34 error: mismatched types:
 expected `diesel::expression::bound::Bound<diesel::types::Integer, &collections::string::String>`,
    found `&collections::string::String`
(expected struct `diesel::expression::bound::Bound`,
    found &-ptr) [E0308]
/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14 #[insertable_into(game_location)]
                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14:1: 14:34 note: in this expansion of #[insertable_into] (defined in /home/freied/dev/git/league-api/db/src/repo/game_location.rs)
/home/freied/dev/git/league-api/db/src/repo/game_location.rs:14:1: 14:34 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to 2 previous errors
error: Could not compile `league_db`.

Am I doing something incorrectly? Thanks!

@freiguy1

This comment has been minimized.

freiguy1 commented Apr 20, 2016

Ugh figured it out. INTEGER in sql code...

@freiguy1 freiguy1 closed this Apr 20, 2016

@sgrif

This comment has been minimized.

Member

sgrif commented Apr 20, 2016

There actually is something I'd like to address here. That error message isn't as helpful as it could be. It should be something along the lines of ToSql<Integer, _> is not implemented for String

@sgrif

This comment has been minimized.

Member

sgrif commented Apr 20, 2016

(Unsure if we can actually make that happen in this context though)

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