declarative-db
An easy-to-use declarative json-based database for Node
Installation
npm install declarative-db
Usage
const path = ;const declare = ; // Declare json-based database;
Since it's Promise based you can also use async-await
const path = ;const declare = ; async { // Declare json-based database let db = await ; // Use it as you would normally use an object (or array) dbusers = username: 'loarca' ; // It will automatically save to disk asynchronously when appropriate};
You should declare()
only once per file
and share declared objects/arrays across all modules,
as every declared object/array is... exactly that... an object/array in memory
that automatically saves to disk when appropriate
Options
filename: path initialState: {} compression: 0
filename
File to store data
initialState (default = {})
When no database file exists initialState
is used,
it may be an object or array
compression (default = 0)
Compression level ranging from 0
to 9
Level 0
outputs database to readable json
Levels from 1
to 9
match DEFLATE compression levels
To do
- Documentation
- Extensive testing
Smart scheduled saving- Protect scheduled saving from unexpected process termination
- When
filename
option is not present, manage database in memory - Force saving when desired