sbx_cloud

Crates.iosbx_cloud
lib.rssbx_cloud
version0.1.16
sourcesrc
created_at2023-04-24 20:59:25.825008
updated_at2023-05-30 03:36:10.023269
descriptionSBXCloud SDK for Rust
homepagehttps://github.com/socobox/sbx-sdk-rs
repositoryhttps://github.com/socobox/sbx-sdk-rs
max_upload_size
id847945
size29,989
Hans Ospina (HansOspina)

documentation

README

SBXCloud Rust SDK

This is the Rust SDK for SBXCloud. It is a work in progress and is not yet ready for production use.

Required environment variables:

SBX_HOST: The host of the SBXCloud instance, this will default to https://sbxcloud.com SBX_TOKEN: The token to use for authentication (Required) SBX_APP_KEY: The app key to use for authentication (Optional) SBX_DOMAIN: The domain context from SBXCloud where the data is stored (Required), this must be a positive number

Implemented features:

  • Authentication
  • QueryBuilder
  • load_all (QueryBuilder) that will load all the results from the query
  • Fetch related records via fetch

Code examples

The library requires you to use an async runtime, so you will need to use an async runtime to use this library. The examples below use tokio.

use sbx_cloud::models::{QueryBuilder, SBXClient};
use sbx_cloud::services::load_all;


#[derive(Serialize, Deserialize, Debug, Clone)]
struct Purchase {
    #[serde(rename(serialize = "_KET", deserialize = "_KEY"))]
    key: String,
    consecutive: u32,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // use the default SBXClient
    let sbx = SBXClient::default();

    // Search for for all the items on the purchase table
    let q = QueryBuilder::new("purchase", sbx.domain)
        // fetch the associated customer
        .fetch(vec![String::from("customer")])
        // where the packing date of the order is equal to a given date
        .and_equals("packing_date", date)
        // and the checkout is not null
        .and_is_not_null("checkout")
        // compile the query
        .build();

    // perform the query and load all the results
    match load_all::<Purchase>(&sbx, &q).await {
        Ok((purchases, fetch)) => {
            println!("Found {} purchases", purchases.len());

            // print out the purchases
            for purchase in purchases.iter() {
                println!("Purchase: {}", purchase.key);
            }
            
            println!("Found {} fetches", fetch.len());

            Ok(())
        }
        Err(e) => {
            println!("Error: {}", e);
            Err(e)
        }
    }
}
Commit count: 0

cargo fmt