diskdb / 0.1.14 last updated a month ago created on Jun 14th 2014
Install
npm install --save diskdb
Clone
git clone git@github.com:arvindr21/diskdb.git
maintainers
versions
15 total
| 0.1.14 | a month ago | arvindr21 |
| 0.1.13 | a month ago | arvindr21 |
| 0.1.12 | 2 months ago | arvindr21 |
| 0.1.11 | 2 months ago | arvindr21 |
| 0.1.10 | 2 months ago | arvindr21 |
| 0.1.9 | 2 months ago | arvindr21 |
| 0.1.8 | 2 months ago | arvindr21 |
| 0.1.7 | 2 months ago | arvindr21 |
| 0.1.6 | 2 months ago | arvindr21 |
| 0.1.5 | 2 months ago | arvindr21 |
| 0.1.4 | 2 months ago | arvindr21 |
| 0.1.3 | 2 months ago | arvindr21 |
| 0.1.2 | 2 months ago | arvindr21 |
| 0.1.1 | 2 months ago | arvindr21 |
| 0.1.0 | 2 months ago | arvindr21 |
readme
diskDB

A Lightweight Disk based JSON Database with a MongoDB like API for Node.
You will never know that you are interacting with a File System
Contents
Getting Started
Install the module locally :
Documentation
Connect to DB
Filename will be the name of the JSON file. You can omit the extension, diskDB will take care of it for you.
This will check for a directory at given path, if it does not exits, diskDB will throw an error and exit.
If the directory exists but the file/collection does not exist, diskDB will create it for you.
Note : If you have manually created an empty JSON file, please make sure that it contains at least an empty array.
Else it will throw an error like
Load Collections
Alternatively you can also load collections like
Load Multiple Collections
Write/Save to Collection
Once you have loaded a collection, you can access the collection's methods using the dot notation like
To save the data, you can use
The saved data will be
You can also save multiple objects at once like
And this will return the inserted objects
Read from Collection
There are 2 methods available for reading the JSON collection
- db.collectioName.find(query)
- db.collectioName.findOne(query)
db.collectioName.find()
This will return all the records
You can also query with a criteria like
This will return all the articles which have a rating of 5.
Nested JSON :
Since diskDB is mostly for light weight data storage, avoid nested structures and huge datasets.
db.collectioName.findOne(query)
If you do not pass a query, diskDB will return the first article in the collection. If you pass a query, it will return first article in the filtered data.
Update Collection
You can also update one or many objects in the collection
Usage
Remove Collection
You can remove the entire collection (including the file) or you can remove the matched objects by passing in a query. When you pass a query, you can either delete all the matched objects or only the first one by passing multi as false. The default value of multi is true.
Using remove without any params will delete the file and will remove the db instance.
After the above operation db.articles is undefined.
Count
Will return the count of objects in the Collection
Examples
Refer to the examples folder.
Performance
To validate diskDB's performance and to check if it meets your needs, you can clone this repo and run
An average of few tests (run on OS X - 10.9.3 | 2.9GHZ i7 | 8GB 1600MHz DDR3) can be found below
Time taken to process x number of objects (in ms) vs Action Performed
| 1 (object) | 1000 (objects) | 10000 (objects) | 100000 (objects) | 1000000 (objects) | |
| Save | 1 (ms) | 15 (ms) | 137 (ms) | 1782 (ms) | 14425 (ms) |
| Find all without query | 0 (ms) | 2 (ms) | 12 (ms) | 204 (ms) | 2923 (ms) |
| Find all with query | 0 (ms) | 2 (ms) | 17 (ms) | 738 (ms) | 1985 (ms) |
| Find one without query | 0 (ms) | 1 (ms) | 9 (ms) | 791 (ms) | 1676 (ms) |
| Find one with query | 0 (ms) | 1 (ms) | 8 (ms) | 219 (ms) | 1410 (ms) |
| Update all records | 1 (ms) | 7 (ms) | 61 (ms) | 206 (ms) | 48035 (ms) |
| Get count | 0 (ms) | 3 (ms) | 11 (ms) | 260 (ms) | 2420 (ms) |
| Remove with query | 0 (ms) | 7 (ms) | 59 (ms) | 984 (ms) | 48191 (ms) |
| Remove collection | 0 (ms) | 1 (ms) | 4 (ms) | 52 (ms) | 154 (ms) |
| File size | 0.000111 (MB) | 0.116671 (MB) | 1.196671 (MB) | 12.266671 (MB) | 125.666671 (MB) |
Contributing
See the CONTRIBUTING Guidelines
Release History
- 0.1.x
- Base Module with
- Connect to a Folder
- Access a Collection/File
- Create Read Update Delete on JSON object
- Minor fixes and tests
- Performance improvements
- Base Module with
License
Copyright (c) 2014 Arvind Ravulavaru. Licensed under the MIT license.
