• This repository has been archived on 03/Aug/2022
  • Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple JSON store for Node.js

JSON file store

A simple JSON file store for node.js.

Build Status Dependency Status NPM version License

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

Install

npm install jfs --save

Usage

var Store = require("jfs");
var db = new Store("data");

var d = {
  foo: "bar"
};

// save with custom ID
db.save("anId", d, function(err){
  // now the data is stored in the file data/anId.json
});

// save with generated ID
db.save(d, function(err, id){
  // id is a unique ID
});

// save synchronously
var id = db.saveSync("anId", d);

db.get("anId", function(err, obj){
  // obj = { foo: "bar" }
})

// pretty print file content
var prettyDB = new Store("data",{pretty:true});
var id = prettyDB.saveSync({foo:{bar:"baz"}});
// now the file content is formated in this way:
{
  "foo": {
    "bar": "baz"
  }
}
// instead of this:
{"foo":{"bar":"baz"}}

// get synchronously
var obj = db.getSync("anId");

// get all available objects
db.all(function(err, objs){
  // objs is a map: ID => OBJECT
});

// get all synchronously
var objs = db.allSync()

// delete by ID
db.delete("myId", function(err){
  // the file data/myId.json was removed
});

// delete synchronously
db.delete("myId");

Single file DB

If you want to store all objects in a single file, set the type option to single:

var db = new Store("data",{type:'single'});

or point to a JSON file:

var db = new Store("./path/to/data.json");

In memory DB

If you don't want to persist your data, you can set type to memory:

var db = new Store("data",{type:'memory'});

ID storage

By default the ID is not stored within your object. If you like, you can change that behavior by setting saveId to true or a custom ID

var db = new Store("data",{saveId:'myKey'});

custom ID generator

We use uuid v4 for ID generation if you don't pass an id when save a data. If you want, you can pass custom generator.

var i = 0;
var db = new Store("data",{
  idGenerator: function() {
    i = i + 1;
    return i;
  }
});

Tests

npm test

License

This project is licensed under the MIT License.

More Repositories

1

rust-web-framework-comparison

A comparison of some web frameworks and libs written in Rust
Rust
4,385
star
2

sloc

simple tool to count SLOC (source lines of code)
CoffeeScript
935
star
3

rust-os-comparison

A comparison of operating systems written in Rust
593
star
4

scaleApp

scaleApp is a JavaScript framework for scalable and maintainable One-Page-Applications
CoffeeScript
352
star
5

clean-architecture-with-rust

Full-Stack Clean Architecture implementation example written in Rust
Rust
65
star
6

rust-json-file-store

A simple JSON file store written in Rust.
Rust
62
star
7

text-editors-written-in-rust

62
star
8

listOfToDoManagers

Collection of known web based ToDo/Task/Project/GTD-Managers
58
star
9

rust-sun

A Rust library for calculating sun positions
Rust
44
star
10

node-plc

Node.js module to connect to PLCs
C
26
star
11

linuxconsole

http://sourceforge.net/projects/linuxconsole/
C
25
star
12

FAST

Free All Scrambled Thoughs
JavaScript
24
star
13

node-xmpp-serviceadmin

Service Administration (XEP-0133) library for node-xmpp
CoffeeScript
18
star
14

go-modbus

DONT USE IT: A free modbus library for go
Go
12
star
15

r2d2-cypher

Cypher support for the r2d2 connection pool
Rust
10
star
16

node-xmpp-joap

Jabber Object Access Protocol (XEP-0075) library for node-xmpp
CoffeeScript
8
star
17

oven

simple cookie middleware for Iron
Rust
7
star
18

semanticExperiments

Experiments with semantic web technologies
JavaScript
5
star
19

npm-source-sans-pro

CSS
5
star
20

node-ezmlm

Node.js wrapper for ezmlm
CoffeeScript
5
star
21

inversePendulumExperiments

Arduino
5
star
22

bits

Easy bit manipulation
CoffeeScript
4
star
23

als-aid

Advanced Life Support - Mobile App
CSS
4
star
24

xmpp

Clone of the XMPP Standards Foundation XEP repository.
Python
3
star
25

react-vm-flower

React.js component to render a VM flower with SVG
CoffeeScript
3
star
26

smackScalaHelpers

A collection of little helpers written in Scala for the XMPP Smack library
Scala
2
star
27

r2d2-jfs

Rust
2
star
28

multi-vlc

Control multiple VLC instances with only one web interface
CoffeeScript
2
star
29

node-xmpp-logger

Logging over XMPP
CoffeeScript
2
star
30

hello-xmpp

A collection of "Hello world!" examples written with several XMPP-libraries
C
2
star
31

nickel-sqlite

A SQLite middleware for nickel.rs
Rust
2
star
32

node-jid

Parse and handle XMPP/Jabber Identifiers
JavaScript
2
star
33

wasm-browser-extension-test

JavaScript
2
star
34

egui-font-rendering-bug

Rust
1
star
35

npm-strophe-plugins

JavaScript
1
star