Skip to content

add iterator wrapper for named query parameters#1638

Open
e00E wants to merge 2 commits into
rusqlite:masterfrom
e00E:named_params_iter
Open

add iterator wrapper for named query parameters#1638
e00E wants to merge 2 commits into
rusqlite:masterfrom
e00E:named_params_iter

Conversation

@e00E

@e00E e00E commented Feb 3, 2025

Copy link
Copy Markdown

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.

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.
@gwenn

gwenn commented Feb 3, 2025

Copy link
Copy Markdown
Collaborator

And you don't want to use raw_bind_parameter ?

Comment thread src/params.rs
#[inline]
fn __bind_in(self, stmt: &mut Statement<'_>) -> Result<()> {
stmt.bind_parameters_named(self)
stmt.bind_parameters_named(self.iter().copied())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems bad to me

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

@gwenn

gwenn commented Feb 3, 2025

Copy link
Copy Markdown
Collaborator

#908 (comment)

@gwenn

gwenn commented Feb 3, 2025

Copy link
Copy Markdown
Collaborator

#1342

@e00E

e00E commented Feb 3, 2025

Copy link
Copy Markdown
Author

And you don't want to use raw_bind_parameter ?

No. I don't like the caveats that this method comes with.

@e00E

e00E commented Feb 3, 2025

Copy link
Copy Markdown
Author

#908 (comment)

That comment is basically this PR. I wasn't aware of it. I added a change to make this PR allow string values too.

Comment thread src/params.rs
/// 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);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you prefer the name ParamsNamedFromIter or NamedParamsFromIter?

@gwenn

gwenn commented Feb 3, 2025

Copy link
Copy Markdown
Collaborator

And you don't want to use raw_bind_parameter ?

No. I don't like the caveats that this method comes with.

Which caveats ?

@e00E

e00E commented Feb 3, 2025

Copy link
Copy Markdown
Author

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.

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

Successfully merging this pull request may close these issues.

2 participants