Crates.io | sbx_cloud |
lib.rs | sbx_cloud |
version | 0.1.16 |
source | src |
created_at | 2023-04-24 20:59:25.825008 |
updated_at | 2023-05-30 03:36:10.023269 |
description | SBXCloud SDK for Rust |
homepage | https://github.com/socobox/sbx-sdk-rs |
repository | https://github.com/socobox/sbx-sdk-rs |
max_upload_size | |
id | 847945 |
size | 29,989 |
This is the Rust SDK for SBXCloud. It is a work in progress and is not yet ready for production use.
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
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)
}
}
}