Feature: Enable query state API
The query state API is an existing API that is currently in the Alpha stage. Currently, this capability is available in some other SDKs, e.g. the JavaScript SDK. In the Rust SDK, we cannot utilize the query API to fetch specific states in the Client Struct.
This PR utilizes the existing proto messages QueryStateRequest and QueryStateResponse to enable state querying. I have added a new function called query_state_alpha1() that takes in two parameters: store_name and query and an optional parameter: metadata.
The query can be defined using serde_json::json
Example:
let mut client = dapr::Client::<dapr::client::TonicClient>::connect(addr).await?;
let query_condition = json!({
"filter": {
"EQ": { "state": "CA" }
},
"sort": [
{
"key": "person.id",
"order": "DESC"
}
]
});
let response_result = match client.query_state_alpha1("statestore", query_condition, None).await {
Ok(response) => response.results,
Err(e) => {
println!("Error: {:?}", e);
return Ok(());
}
};
Issue #115
Looks good, I have two questions:
- Does this work with redis-stack? If simple enough, this could be a good way to stand up a test env (as an alternative to mongodb)
- Could/should the two queries be combined into one app?
Hi @mikeee, thanks for the comments and sorry for my late response. I'll take a look into this and update the PR
No worries, I can update and get this pushed through if you'd prefer 👍
That would be great! Thanks :)
Thanks for the contribution @ruokun-niu, much appreciated 😄
Thanks for the review and help!
@holopin-bot @ruokun-niu Thank you!
Congratulations @ruokun-niu, you just earned a badge! Here it is: https://holopin.io/claim/clvwgjwuk38440fme3ecbo1pv
This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!