flat-db
Flat-file based data storage
Setup
npm install flat-db --save
APIs
- FlatDB.configure(Object options)
- FlatDB.Collection(String name[, Object schema]) - Constructor - return Collection class instance
- .add(Object entry | Array entries)
- .get(String key)
- .update(String key, Object updates)
- .remove(String key)
- .all()
- .count()
- .reset()
- .find() - return Finder class instance
- .equals(String property, String | Number value)
- .notEqual(String property, String | Number value)
- .gt(String property, Number value)
- .gte(String property, Number value)
- .lt(String property, Number value)
- .lte(String property, Number value)
- .matches(String property, RegExp value)
- .skip(Number value)
- .limit(Number value)
- .run()
Example:
const FlatDB = ; // configure path to storage dirFlatDB;// since now, everything will be saved under ./storage // create Movie collection with schemaconst Movie = 'movies' title: '' imdb: 0; // The schema is optional.// But once it was defined, any new item come later// will be compared with this schema's structure and data type // insert a set of movies into collectionconst keys = Movie;console;console; // add a single movieconst key = Movie;// the property "year" will be ignored// because it does not match with schemaconsole;console; // get item with given keyconst movie = Movie;console;console; // update itconst updating = Movie;// the property "title" will be ignored// because it does not match with expected typeconsole;console; // remove itconst removing = Movie;console;console; // count collection sizeconst count = Movie;console;console; // get all itemconst all = Movieall;console;console; // find items with imdb < 7.1const results = Movie;console;console; // get 2 items since 2nd item (skip first item), which have "re" in the titleconst results = Movie;console;console; // find items with imdb > 6 and title contains "God"const results = Movie ;console;console; // remove allMovie; // count collection size after removing allconst count = Movie;console;console;
Test
git clone https://github.com/ndaidong/flat-db.git
cd flat-db
npm install
npm test
License
The MIT License (MIT)