Crates.io | jsonbox |
lib.rs | jsonbox |
version | 0.2.0 |
source | src |
created_at | 2019-09-22 14:14:18.067731 |
updated_at | 2019-09-28 12:09:49.619921 |
description | Rust wrapper for jsonbox.io |
homepage | https://github.com/kuy/jsonbox-rs |
repository | https://github.com/kuy/jsonbox-rs |
max_upload_size | |
id | 166811 |
size | 118,545 |
⚙️ Rust wrapper for 📦 jsonbox.io.
// Declaration
use jsonbox::{Client, Error};
use serde::{Deserialize, Serialize};
// Define struct
#[derive(Serialize, Deserialize)]
pub struct Data {
pub name: String,
pub message: String,
}
fn main() -> Result<(), Error> {
// Create client with <BOX_ID>
let client = Client::new("enjoy_your_first_jsonbox_rs");
// Insert data
let data = Data {
name: "kuy".into(),
message: "Hello, Jsonbox!".into(),
};
let (record, meta) = client.create(&data)?;
println!("CREATE: data={:?}, id={} @{}", record, meta.id, meta.created_on);
Ok(())
}
let data = Data {
name: "kuy".into(),
message: "Hello, Jsonbox!".into(),
};
let (record, meta) = client.create(&data)?;
println!("CREATE: data={:?}, meta={:?}", record, meta);
let all = client.read().all::<Data>()?;
println!("READ: len={}, all={:?}", all.len(), all);
let (record, meta) = client.read().id("5d876d852a780700177c0557")?;
println!("READ: data={:?}, meta={:?}", record, meta);
let few = client.read().limit(10).run::<Data>()?;
println!("READ: len={}, few={:?}", few.len(), few);
let rest = client.read().skip(5).run::<Data>()?;
println!("READ: len={}, rest={:?}", rest.len(), rest);
let asc = client.read().order_by("name").run::<Data>()?;
println!("READ: len={}, asc={:?}", asc.len(), asc);
let desc = client.read().order_by("count").desc().run::<Data>()?;
println!("READ: len={}, desc={:?}", desc.len(), desc);
let filtered = client
.read()
.filter_by("name:{}", "Json Box")
.run::<Data>()?;
println!("READ: len={}, filtered={:?}", filtered.len(), filtered);
See baisc example or official documentation for more about filters.
let data = Data::new("kuy", "Hello, Jsonbox!");
client.update("5d876d852a780700177c0557", &data)?;
println!("UPDATE: OK");
client.delete("5d876d852a780700177c0557")?;
println!("DELETE: OK");
cargo run --example hello
cargo run --example basic
cargo run --example errors
MIT
Yuki Kodama / @kuy