Skip to content

cosier/jsondb-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Dependency Status Documentation

jsondb

A simple JSON file store written in Rust. This is a port and drop-in replacement of the Node.js library json-file-store.

WARNING: Don't use it if you want to persist a large amount of objects. Use a real DB instead.

Example

extern crate jfs;
#[macro_use]
extern crate serde_derive;
use jsondb::Store;

#[derive(Serialize,Deserialize)]
struct Foo {
  foo: String
}

pub fn main() {
   let db = Store::new("data").unwrap();
   let f = Foo { foo: "bar".to_owned() };
   let id = db.save(&f).unwrap();
   let obj = db.get::<Foo>(&id).unwrap();
   db.delete(&id).unwrap();
}

You can also store all data in one single JSON-File:

let mut cfg = jfs::Config::default();
cfg.single = true; // false is default
let db = jsondb::Store::new_with_cfg("data",cfg);

If you like to pretty print the file content, set pretty to true and choose a number of whitespaces for the indention:

let mut cfg = jsondb::Config::default();
cfg.pretty = true;  // false is default
cfg.indent = 4;     // 2 is default

License

This project is licensed under the MIT License.

About

A simple, yet configurable JSON based Database in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages