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

How to pass dynamic named parameters to rusqlite query/execute through params_from_iter function? #1342

Open
ethever opened this issue Jun 6, 2023 · 9 comments

Comments

@ethever
Copy link

ethever commented Jun 6, 2023

How to pass dynamic named parameters to rusqlite query/execute through params_from_iter function?
I saw the Sealed trait has been implemented to Params trait, but there is not such bind_parameters_named method for ParamsFromIter structure.

@ethever
Copy link
Author

ethever commented Jun 6, 2023

How to make the bind_parameters_named function to able to accept a Iterator?

pub(crate) fn bind_parameters_named<'a, T: 'a + ?Sized, I>(&mut self, params: I) -> Result<()>
    where
        T: ToSql,
        I: IntoIterator<Item = (&'a str, &'a T)>,

@gwenn
Copy link
Collaborator

gwenn commented Jun 6, 2023

There is no NamedParamsFromIter for named parameters.
As a workaround, you can use raw_bind_parameter

@bwo
Copy link

bwo commented Aug 24, 2023

are there any plans to introduce such functionality? It would be very useful.

@thomcc
Copy link
Member

thomcc commented Aug 24, 2023

@bwo
Copy link

bwo commented Aug 24, 2023

that doesn't mean that a more convenient API wouldn't be appreciated, and in fact I was stymied trying to do just that (I kept getting errors that the size of my slice wasn't known at compile time—obviously, if I knew that, I wouldn't need anything dynamic in the first place).

@thomcc
Copy link
Member

thomcc commented Aug 24, 2023

If you get errors that the size of your slice isn't known at compile time, it usually means you just need to pass it behind a reference.

@thomcc
Copy link
Member

thomcc commented Aug 24, 2023

Or perhaps collect into a vec and use vec.as_slice().

@bwo
Copy link

bwo commented Aug 24, 2023

Regardless—granted that there are workarounds, the question whether a simple API will be offered is reasonable. Indeed, the docs say:

As a slice of &[(&str, &dyn ToSql)]. This is what essentially all of these boil down to in the end, conceptually at least. In theory you can pass this as stmt.

But while "all of these" boil down to that in the end, that isn't the sole API provided. Other, more convenient ones are, too. I take it from your replies that the answer to my question (will a more convenient way to do this be introduced) is "no".

@thomcc
Copy link
Member

thomcc commented Aug 24, 2023

Yeah, I don't really have strong feelings.

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

No branches or pull requests

4 participants