rust-sdk icon indicating copy to clipboard operation
rust-sdk copied to clipboard

Feature: Enable query state API

Open ruokun-niu opened this issue 1 year ago • 1 comments

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

ruokun-niu avatar Jan 31 '24 00:01 ruokun-niu

Looks good, I have two questions:

  1. 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)
  2. Could/should the two queries be combined into one app?

mikeee avatar Feb 13 '24 15:02 mikeee

Hi @mikeee, thanks for the comments and sorry for my late response. I'll take a look into this and update the PR

ruokun-niu avatar Apr 08 '24 14:04 ruokun-niu

No worries, I can update and get this pushed through if you'd prefer 👍

mikeee avatar Apr 08 '24 15:04 mikeee

That would be great! Thanks :)

ruokun-niu avatar Apr 08 '24 17:04 ruokun-niu

Thanks for the contribution @ruokun-niu, much appreciated 😄

mikeee avatar Apr 09 '24 21:04 mikeee

Thanks for the review and help!

ruokun-niu avatar Apr 09 '24 21:04 ruokun-niu

@holopin-bot @ruokun-niu Thank you!

marcduiker avatar May 07 '24 14:05 marcduiker

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!

holopin-bot[bot] avatar May 07 '24 14:05 holopin-bot[bot]