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

feat: Add with_params_from method to clients query request builder #24927

Merged
merged 6 commits into from Apr 29, 2024

Conversation

jbajic
Copy link
Contributor

@jbajic jbajic commented Apr 18, 2024

Closes #24812

Changes

Added method with_params_from to the QueryRequestBuilder.

  • I've read the contributing section of the project README.
  • Signed CLA (if not already signed).

Copy link
Contributor

@mgattozzi mgattozzi left a comment

Choose a reason for hiding this comment

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

Hey @jbajic! Thanks for tackling this issue. One thing before I approve the change. Can you add a test to this same file to test that the functionality works? There should be tests you can use as an example in the file. If you need any help let me know!

@jbajic
Copy link
Contributor Author

jbajic commented Apr 23, 2024

Hey @jbajic! Thanks for tackling this issue. One thing before I approve the change. Can you add a test to this same file to test that the functionality works? There should be tests you can use as an example in the file. If you need any help let me know!

Done

@jbajic jbajic requested a review from mgattozzi April 24, 2024 07:46
@mgattozzi
Copy link
Contributor

@jbajic Two changes so I can actually merge this that has nothing to do with your code: can you run cargo update to get rid of the CI failure since cargo-deny is what's tripping up here and can you rebase and force push to rewrite your commits to also use the conventional commit style like with the PR title?

Copy link
Contributor

@hiltontj hiltontj left a comment

Choose a reason for hiding this comment

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

Thank you @jbajic for picking this up! I have a couple of comments below.

/// let client = Client::new("http://localhost:8181")?;
/// let response_bytes = client
/// .api_v3_query_sql("db_name", "SELECT * FROM foo WHERE bar = $bar AND foo > $fooz")
/// .with_params_from(HashMap::from([
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the HashMap necessary here? Or can you just pass in the array, i.e.,

.with_params_from([
    ("bar", json!(false)),
    ("foo", json!(10)),
])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can pass any iterable collection with pairs that fit the traits. I will replace it with array

/// ```
pub fn with_params_from<S, P, C>(mut self, params: C) -> Result<Self>
where
S: Into<String> + Clone,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can remove the Clone bound on this, since .clone() is only called on name after it has been converted to a String (which implements Clone). If it can be removed here it could also likely be removed on the with_try_params method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right it can be removed, and it will be.


let r = client
.api_v3_query_influxql(db, query)
.with_params_from(Vec::from([
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar here, is the Vec needed? or can you just use the array [...] directly.

@hiltontj hiltontj added the v3 label Apr 29, 2024
Copy link
Contributor

@hiltontj hiltontj left a comment

Choose a reason for hiding this comment

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

LGTM - thank you @jbajic for contributing. @mgattozzi may want to take another look before we merge.

Copy link
Contributor

@mgattozzi mgattozzi left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks again for your contribution @jbajic. It's greatly appreciated! 😄

@mgattozzi mgattozzi merged commit db8c8d5 into influxdata:main Apr 29, 2024
8 checks passed
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 this pull request may close these issues.

Set parameters for query request with influxdb3 Client using a collection
3 participants