https://github.com/kuy/jsonbox-rs
Rust wrapper for jsonbox.io
https://github.com/kuy/jsonbox-rs
binding json jsonbox rust wrapper
Last synced: about 1 year ago
JSON representation
Rust wrapper for jsonbox.io
- Host: GitHub
- URL: https://github.com/kuy/jsonbox-rs
- Owner: kuy
- License: mit
- Created: 2019-09-22T13:23:21.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-10-04T12:45:16.000Z (over 6 years ago)
- Last Synced: 2024-10-07T09:17:58.739Z (over 1 year ago)
- Topics: binding, json, jsonbox, rust, wrapper
- Language: Rust
- Size: 86.9 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonbox.rs
[](https://crates.io/crates/jsonbox)
[](https://docs.rs/jsonbox)
[](https://github.com/kuy/jsonbox-rs/actions)
⚙️ Rust wrapper for 📦 [jsonbox.io](https://jsonbox.io/).
## Usage
```rust
// 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
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(())
}
```
See [full documentation](https://docs.rs/jsonbox).
### CREATE
```rust
let data = Data {
name: "kuy".into(),
message: "Hello, Jsonbox!".into(),
};
let (record, meta) = client.create(&data)?;
println!("CREATE: data={:?}, meta={:?}", record, meta);
```
Use [`create_bulk()`](https://docs.rs/jsonbox/latest/jsonbox/struct.Client.html#method.create_bulk) for bulk creation.
### READ
#### all (default parameters)
```rust
let all = client.read().all::()?;
println!("READ: len={}, all={:?}", all.len(), all);
```
#### with specific id
```rust
let (record, meta) = client.read().id("5d876d852a780700177c0557")?;
println!("READ: data={:?}, meta={:?}", record, meta);
```
#### with limit
```rust
let few = client.read().limit(10).run::()?;
println!("READ: len={}, few={:?}", few.len(), few);
```
#### with skip
```rust
let rest = client.read().skip(5).run::()?;
println!("READ: len={}, rest={:?}", rest.len(), rest);
```
#### with order (asc/desc)
```rust
let asc = client.read().order_by("name").run::()?;
println!("READ: len={}, asc={:?}", asc.len(), asc);
let desc = client.read().order_by("count").desc().run::()?;
println!("READ: len={}, desc={:?}", desc.len(), desc);
```
#### with filter
```rust
let filtered = client
.read()
.filter_by("name:{}", "Json Box")
.run::()?;
println!("READ: len={}, filtered={:?}", filtered.len(), filtered);
```
See [QueryBuilder](https://docs.rs/jsonbox/latest/jsonbox/struct.QueryBuilder.html), [baisc example](https://github.com/kuy/jsonbox-rs/blob/master/examples/basic.rs), or [official documentation](https://github.com/vasanthv/jsonbox#filtering) for more about filters.
### UPDATE
```rust
let data = Data::new("kuy", "Hello, Jsonbox!");
client.update("5d876d852a780700177c0557", &data)?;
println!("UPDATE: OK");
```
### DELETE
```rust
client.delete("5d876d852a780700177c0557")?;
println!("DELETE: OK");
```
## Examples
- [jsonbox-todo-example](https://github.com/kuy/jsonbox-todo-example)
- [hello](https://github.com/kuy/jsonbox-rs/blob/master/examples/hello.rs)
- `cargo run --example hello`
- [basic](https://github.com/kuy/jsonbox-rs/blob/master/examples/basic.rs)
- `cargo run --example basic`
- [errors](https://github.com/kuy/jsonbox-rs/blob/master/examples/errors.rs)
- `cargo run --example errors`
## License
MIT
## Author
Yuki Kodama / [@kuy](https://twitter.com/kuy)