add: apps rust sdk
This commit is contained in:
parent
f05074ffc5
commit
fe1e53c47a
11 changed files with 461 additions and 11 deletions
65
crates/core/examples/sdk_db.rs
Normal file
65
crates/core/examples/sdk_db.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
extern crate tetratto_core;
|
||||
use tetratto_core::{
|
||||
model::apps::{AppDataSelectMode, AppDataSelectQuery, AppDataQueryResult},
|
||||
sdk::{DataClient, SimplifiedQuery},
|
||||
};
|
||||
use std::env::var;
|
||||
|
||||
// mirror of https://trisua.com/t/tetratto/src/branch/master/example/app_sdk_test.js ... but in rust
|
||||
#[tokio::main]
|
||||
pub async fn main() {
|
||||
let client = DataClient::new(
|
||||
Some("http://localhost:4118".to_string()),
|
||||
var("APP_API_KEY").unwrap(),
|
||||
);
|
||||
|
||||
println!("data used: {}", client.get_app().await.unwrap().data_used);
|
||||
|
||||
// record insert
|
||||
client
|
||||
.insert("rust_test".to_string(), "Hello, world!".to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
println!("record created");
|
||||
println!("data used: {}", client.get_app().await.unwrap().data_used);
|
||||
|
||||
// testing record query then delete
|
||||
let record = match client
|
||||
.query(&SimplifiedQuery {
|
||||
query: AppDataSelectQuery::KeyIs("rust_test".to_string()),
|
||||
mode: AppDataSelectMode::One(0),
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
AppDataQueryResult::One(x) => x,
|
||||
AppDataQueryResult::Many(_) => unreachable!(),
|
||||
};
|
||||
|
||||
println!("{:?}", record);
|
||||
|
||||
client
|
||||
.update(record.id, "Hello, world! 1".to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
println!("record updated");
|
||||
println!("data used: {}", client.get_app().await.unwrap().data_used);
|
||||
|
||||
let record = match client
|
||||
.query(&SimplifiedQuery {
|
||||
query: AppDataSelectQuery::KeyIs("rust_test".to_string()),
|
||||
mode: AppDataSelectMode::One(0),
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
AppDataQueryResult::One(x) => x,
|
||||
AppDataQueryResult::Many(_) => unreachable!(),
|
||||
};
|
||||
|
||||
println!("{:?}", record);
|
||||
|
||||
client.remove(record.id).await.unwrap();
|
||||
println!("record deleted");
|
||||
println!("data used: {}", client.get_app().await.unwrap().data_used);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue