record.js/docs/api.md

1.9 KiB

Record.js API

constructor

Parameters

  • opts object
    • opts.store object localStorage ID to use
    • opts.debug object show console logs
  • init array collection to start with

Examples

// create a new record (in-memory)
let pets = new Record();
// create a new record (localStorage)
let pets = new Record({"store": "pets"});

add

Add record to collection creating an sudo unique id if one not provided

Parameters

  • entry Object 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 object entry added

find

Finds records in collection by id or object filter.

Parameters

  • key (string | [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 matching records

remove

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 records removed