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

pg query! err #47

Closed
fanhaining opened this issue Jan 14, 2020 · 9 comments · Fixed by #51
Closed

pg query! err #47

fanhaining opened this issue Jan 14, 2020 · 9 comments · Fixed by #51
Labels

Comments

@fanhaining
Copy link

when parameters more than 10 I get a err

error[E0271]: type mismatch resolving <sqlx_core::postgres::database::Postgres as sqlx_core::database::Database>::Arguments == (&std::string::String, &std::string::String, &i32, &i32, &i32, &i32, &std::string::String, &std::string::String, &i64, &i32)

expected struct sqlx_core::postgres::arguments::PgArguments, found tuple

@mehcode
Copy link
Member

mehcode commented Jan 14, 2020

@243011068 Thank you for reporting the issue. We'll look into resolving this, nicely, if possible.


@abonander I think we can make this work without the tuple impls. Maybe we should just iterate over the bind arguments and run .bind with the macro.

@mehcode mehcode added the bug label Jan 14, 2020
@abonander
Copy link
Collaborator

abonander commented Jan 14, 2020

What I wanted to accomplish with using the tuple is having some sort of typestate that blocks the user from accidentally adding superfluous binds. Right now QueryAs won't let you call .bind() if the arguments type is a tuple.

I do see the limitation here, I'm just wondering how do we prevent the aforementioned or if we care.

@mehcode
Copy link
Member

mehcode commented Jan 14, 2020

@abonander What about an "anonymous" (scoped) tuple struct that you manually implement IntoArguments for?

@abonander
Copy link
Collaborator

That would certainly work, no one's complaining about metadata bloat yet so we can probably get away with it.

@mehcode
Copy link
Member

mehcode commented Jan 14, 2020

It's still a lot less than if we added x32 tuple impls.

@abonander
Copy link
Collaborator

Certainly.

@abonander
Copy link
Collaborator

Oh, no it won't work for MySQL because we can't know the types. I guess we could generate a struct where every field is generic over Encode.

@abonander
Copy link
Collaborator

Alternatively, what if we used &[&dyn Encode<DB>]?

@abonander
Copy link
Collaborator

We decided to build the actual PgArguments or MySqlArguments struct and then wrap it in a newtype that implements IntoArguments, this way the typestate on QueryAs that prevents extra .bind() calls is preserved.

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

Successfully merging a pull request may close this issue.

3 participants