add iterator wrapper for named query parameters#1638
Conversation
This is like ParamsFromIter but with named parameters. This is useful for the same reasons as ParamsFromIter. Sometimes you cannot use the macro and the Params implementations for arrays and tuples don't work either.
|
And you don't want to use raw_bind_parameter ? |
| #[inline] | ||
| fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> { | ||
| stmt.bind_parameters_named(self) | ||
| stmt.bind_parameters_named(self.iter().copied()) |
No. I don't like the caveats that this method comes with. |
|
That comment is basically this PR. I wasn't aware of it. I added a change to make this PR allow string values too. |
| /// This struct is similar to [`ParamsFromIter`]. See its documentation for more | ||
| /// details. The difference is that this struct works on named parameters. The | ||
| /// iterator yields the `ToSql` parameter and its name. | ||
| pub struct ParamsNamedFromIter<I>(I); |
There was a problem hiding this comment.
Do you prefer the name ParamsNamedFromIter or NamedParamsFromIter?
Which caveats ? |
|
With raw_bind_parameters you cannot pass the parameters as their name. And you have to use raw_query and raw_execute. Isn't it the same reasons as ParamsFromIter? If it makes sense to provide params as an iterator for index based params then it also makes sense for named params with the same reasons. |
This is like ParamsFromIter but with named parameters.
This is useful for the same reasons as ParamsFromIter. Sometimes you cannot use the macro and the Params implementations for arrays and tuples don't work either.