#json #bin #data-store #database #cli

app nest-cli

使用您的文件系统作为嵌套数据存储

4 个版本 (2 个重大更新)

0.3.0 2019 年 5 月 6 日
0.2.0 2019 年 4 月 27 日
0.1.1 2019 年 4 月 27 日
0.1.0 2019 年 4 月 27 日

#67 in #bin

MIT/Apache

45KB
977

Nest 🐦

使用您的文件系统作为嵌套数据存储!

模块

nest

示例

use nest::{Error, Store, Value};
use serde_json::json;
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    // what is the root path to your data store?
    let root = "./example-data";
    // describe how your data store will map to the filesystem
    let schema = json!({
        // refers to a directory: ./example-data/hello/
        "hello": {
            // refers to a file: ./example-data/hello/world.json
            "world": "json"
        }
    })
    .try_into()?;

    let store = Store::new(root, schema);

    // get `nest` key from `./example-data/hello/world.json` file
    let value = store.get(&["hello", "world", "nest"])?;
    println!("value: {:?} == 🐣", value);

    // set `nest` key in `./example-data/hello/world.json` file
    let next_value = &Value::String("🐥".into());
    store.set(&["hello", "world", "nest"], next_value)?;

    // get a sub-store for data within `./example-data/hello/world.json
    let sub = store.sub(&["hello", "world"])?;
    let value = sub.get(&["nest"])?;
    println!("value: {:?} == 🐥", value);

    // try to get a value that doesn't map to the schema
    if let Err(err) = store.get(&["invalid", "path"]) {
        println!("err: {}", err);
    };

    Ok(())
}

nest-cli

安装

cargo install nest-cli

示例

给定 example-data

tree -a example-data
# example-data
# ├── hello
# │   └── world.json
# └── .nest.json
#
# 1 directory, 2 files

cat example-data/.nest.json
# {
#   "hello": {
#     "world": "json"
#   }
# }

cat example-data/hello/world.json
# {
#   "nest": "🐣"
# }
cd example-data

nest get 'hello/world'
# {
#   "nest": "🐣"
# }

nest set 'hello/world/nest' '"🐥"'

nest get 'hello'
# {
#   "world": {
#     "nest": "🐥"
#   }
# }

用法

Use your filesystem as a nested data store!

USAGE:
    nest [FLAGS] [OPTIONS] <SUBCOMMAND>

FLAGS:
    -h, --help         
            Prints help information

    -P, --pretty       
            Enable pretty printing

    -V, --version      
            Prints version information

    -v, --verbosity    
            Pass many times for more log output
            
            By default, it'll only report errors. Passing `-v` one time also prints warnings, `-vv` enables info
            logging, `-vvv` debug, and `-vvvv` trace.

OPTIONS:
        --root <root>    
            


SUBCOMMANDS:
    get     Get value from Nest.
    help    Prints this message or the help of the given subcommand(s)
    set     Set value in Nest.

贡献

行为准则

Nest 项目遵循 贡献者行为准则。这描述了所有贡献者应遵守的最小行为准则。

许可协议

许可协议为以下之一

任选其一。

贡献

除非您明确声明,否则您有意提交的任何贡献,按照 Apache-2.0 许可协议开发者起源证书 定义,应按上述方式双许可,无需任何额外的条款或条件。

依赖项

~11–20MB
~276K SLoC