cooldb
v1.0.2
Published
CoolDB allows easy CRUD Array events.
Downloads
6
Readme
coolDB
This is a lightweight library for Client | Server which helps the CRUD actions in memory over objects / data stored in an internal JS Array.
Browser
<script src="dist/browser-cooldb.js"></script>
var cooldb = cooldb,
coolDB = cooldb();
Node
npm install cooldb
var cooldb = require('cooldb'),
coolDB = cooldb();
// Async coolDB.add({ item: {name: 'Steven 2'}, async: true, ms: 500 }, function(result){ console.log(result); // Object {old: null, new: Object, action: "Inserted"} });
// >> Add Array << // Sync coolDB.add({ item: [{ name: 'Steven' }, { name: 'Steven 2' }] });
// Async coolDB.add({ item: [{ name: 'Steven' }, { name: 'Steven 2' }], async: true, ms: 0 }, function(result){ console.log(result); // Object {old: null, new: Object, action: "Inserted"} // Object {old: null, new: Object, action: "Inserted"} });
### del
Delete the items where a key + value match with the items stored inside the cooldb Array
function del(params, cb) params: { key (Property name) | value (Property value) | async (true/false) | ms (setTimeout milliseconds) } returns: cooldb object
``` javascript
// Sync
coolDB.del({ key:'name', value: 'Mary' }); // Delete all items where name = Mary
// Async
coolDB.del({ key:'name', value: 'Mary', async: true, ms: 0 },
function(result){
console.log(result); // Object {old: Object, new: null, action: "Deleted"}
});
update
Update the items where a key + value match with the items stored inside the cooldb Array
function update(params, cb)
params: { key (Property name) | value (Property value) | item (New Property values) |async (true/false) | ms (setTimeout milliseconds) }
returns: cooldb object
// Sync
coolDB.update({ key: 'name', value: 'Blue', item: { name: 'Pacman' } }); // Update name = Pacman where name = Blue
// Async
coolDB.update({ key: 'name', value: 'Blue', item: { name: 'Pacman' }, async: false, ms: 0 },
function (result){
console.log(result); // Object {old: Object, new: Object, action: "Updated"}
});
first
Return the first item where a key + value match with the items stored inside the cooldb Array
function first(params, cb)
params: { key (Property name) | value (Property value) | async (true/false) | ms (setTimeout milliseconds) }
returns: Object { item (First object found) | count (Number of objects found) }
// Sync
coolDB.first({ key:'name', value: 'Blue' }); // Object {item: Object, count: 1}
// Async
coolDB.first({ key:'name', value: 'Blue', async: true, ms: 0 },
function(result){
console.log(result); // Object {item: Object, count: 1}
});
get
Get the items where a key + value match with the items stored inside the cooldb Array
function get(params, cb)
params: { key (Property name) | value (Property value) | async (true/false) | ms (setTimeout milliseconds) }
returns: Object { items (Array of objects found) | count (Number of objects found) }
// Sync
coolDB.get({ key:'name', value: 'Blue' }); // Object {items: Array[1], count: 1}
// Async
coolDB.get({ key:'name', value: 'Blue', async: true, ms: 0 },
function(result){
console.log(result); // Object {items: Array[2], count: 2}
});
db
Get the cooldb Array Mirror.
function db()
returns: Array
// Sync
coolDB.db(); // [Object, Object, Object, Object]
clone
Get the cooldb Array Clone.
function clone()
returns: Array
// Sync
coolDB.clone(); // [Object, Object, Object, Object]
clean
Reset to empty Array the internal cooldb Array.
function clean(cb)
returns: cooldb object
// Sync
coolDB.clean(); // Object {changeFeed: function, get: function, add: function, del: function, db: function…}
changeFeed
Subscribe to the internal cooldb Array's CRUD changes.
function changeFeed(fn)
returns: Object
coolDB.changeFeed(function(change){
console.log(change);
// Object {old: null, new: Object, action: "Inserted"}
// Object {old: Object, new: null, action: "Deleted"}
// Object {old: Object, new: Object, action: "Updated"}
// Object {old: null, new: null, action: "Cleaned"}
});