Giter VIP home page Giter VIP logo

jsonbox-rs's Introduction

jsonbox.rs

crates.io docs.rs build

โš™๏ธ Rust wrapper for ๐Ÿ“ฆ jsonbox.io.

Usage

// 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(())
}

See full documentation.

CREATE

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() for bulk creation.

READ

all (default parameters)

let all = client.read().all::<Data>()?;
println!("READ: len={}, all={:?}", all.len(), all);

with specific id

let (record, meta) = client.read().id("5d876d852a780700177c0557")?;
println!("READ: data={:?}, meta={:?}", record, meta);

with limit

let few = client.read().limit(10).run::<Data>()?;
println!("READ: len={}, few={:?}", few.len(), few);

with skip

let rest = client.read().skip(5).run::<Data>()?;
println!("READ: len={}, rest={:?}", rest.len(), rest);

with order (asc/desc)

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);

with filter

let filtered = client
    .read()
    .filter_by("name:{}", "Json Box")
    .run::<Data>()?;
println!("READ: len={}, filtered={:?}", filtered.len(), filtered);

See QueryBuilder, baisc example, or official documentation for more about filters.

UPDATE

let data = Data::new("kuy", "Hello, Jsonbox!");
client.update("5d876d852a780700177c0557", &data)?;
println!("UPDATE: OK");

DELETE

client.delete("5d876d852a780700177c0557")?;
println!("DELETE: OK");

Examples

License

MIT

Author

Yuki Kodama / @kuy

jsonbox-rs's People

Contributors

kuy avatar rchaser53 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rchaser53

jsonbox-rs's Issues

Readable filter chain

let filtered = client
    .read()
    .filter_by("name:{}", "Json Box")
    .and("age:>{}", 42)
    .run::<Data>()?;

Unified return value (record + meta)

Actual Client::read() returns a tuple of data and meta. This is not ergonomic API. So I want to unify them and change its signature to return a single value.

Before

let (record, meta) = client.read().id("...");
println!("name={}, created={}", record.name, meta.created_on);

After

let record = client.read().id("...");
println!("name={}, created={}", record.name, record.created_on);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.