1.6 KiB
1.6 KiB
Record.JS
constructor
Parameters
init
[array][6] collection to start withopts
[object][7]opts.store
[object][7] localStorage ID to useopts.debug
[object][7] show console logs
Examples
// create a new record (in-memory)
let pets = new Record();
add
Add record to collection creating an sudo unique id if one not provided
Parameters
entry
[Object][7] object(s) you want to store
Examples
// add pet to collection
let dog = pets.add({"name": "Yonkers", "age": 5});
// [{"id": "14rj345k9", "name": "Yonkers", "age": 5}]
Returns [array][6] record added
find
Finds records in collection by id or object filter.
Parameters
key
([string][8] | [number][9]) (optional) by id, or object
Examples
// find all
let all = collection.find();
// find by id
let record = collection.find(1);
// filter by object
let dogs = collection.find({"type": "dog"});
Returns [array][6] matching records
remove
- See: [find][10]
Remove record(s) from collection. Leverages same functionality as find
Parameters
entry
any (optional)
Examples
// remove all records by type
let removed = collection.remove({"type": "cat"});
Returns [array][6] records removed
count
Returns [number][9] count of records in collection