#data-store #json #serde-json #filesystem

nest

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

11 个版本 (1 个稳定版本)

1.0.0 2019 年 5 月 6 日
0.4.0 2019 年 4 月 27 日
0.3.6 2019 年 4 月 27 日
0.2.0 2019 年 4 月 27 日
0.1.0 2019 年 4 月 27 日

数据库接口 中排名 1633

Download history 3/week @ 2024-04-15 8/week @ 2024-04-22 1/week @ 2024-04-29 7/week @ 2024-05-13 11/week @ 2024-05-20 4/week @ 2024-05-27 4/week @ 2024-06-03 3/week @ 2024-06-10 10/week @ 2024-06-17 1/week @ 2024-06-24 127/week @ 2024-07-29

每月下载量 127
nest-cli 中使用

MIT/Apache 协议

39KB
885

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 许可证开发者来源证书 定义,应作为上述双重许可,不附加任何额外条款或条件。

依赖项

~10MB
~203K SLoC