7 releases
0.1.16 | May 30, 2023 |
---|---|
0.1.15 | May 29, 2023 |
0.1.13 | Apr 25, 2023 |
#1977 in Web programming
30KB
762 lines
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)
}
}
}
Dependencies
~4–19MB
~222K SLoC