Flatty
This library was build for quickly testing API using local DB. Also can be used as non-failing, always reachable DB used for presentations (This is why it was created). This module is small ~300 LOC.
Be warned, that it is not stable and API is subject to change.
install: npm install flatty
API
var flatty = ;var Store = ; var pokemons = "./pokemons.db" interval: 50 // In ms store: ;
Methods
set([id], data, callback)
Options:
id
(if omitted, random id will be generated)data
- valid JSON datacallback
- Obvious
Example:
pokemons;pokemons;
get([id], callback)
Options:
id
(if omitted, will return all records)callback(results)
- Again, callback!typeof results === (id === undefined) ? "array" : "object"
Example:
pokemons; pokemons;
delete(id, callback)
Options:
id
- ID of the recordcallback
- OH, THAT!
Example:
pokemon;
update(id, data, callback)
Options:
id
- ID of the recordcallback
- SUCH CALLBACK!
Example:
pokemon;
find(search, callback)
Options:
search
- valid JSON objectcallback(results)
- CALLBACK WOW!typeof results === "array"
Example:
pokemon; pokemon;
option(key, val)
Options:
key
- option nameval
- options value
Example:
pokemon;
Events
record:set
- callback: fn(key)
. Key is id of record.
record:update
- callback: fn(key)
. Key is id of record.
record:delete
- callback: fn(key)
. Key is id of record.
option:change
- Emitted when option has changed.
Ticker
Ticker is a function, that saves data to disk at certain interval. Data format is JSON or native format, which looks like ID\t{data: "stuff"}\n
, so it`s highly editable and readable.
Currently interval is set to 50ms
. But dont worry! It will not flood your drive, because it will write only if changes were made.