new Store(name, callback)
Creates a new client side storage object and will create an empty
collection if no collection already exists.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The name of our DB we want to use |
callback |
function | Our fake DB uses callbacks because in real life you probably would be making AJAX calls |
Methods
drop(callback)
Will drop all storage and start fresh
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback to fire after depositing the data |
find(query, callback)
Finds items based on a query given as a JS object
Parameters:
Name | Type | Description |
---|---|---|
query |
object | The query to match against (= {foo: 'bar'}) |
callback |
function | The callback to fire when the query has completed running |
Example
db.find({foo: 'bar', hello: 'world'}, function (data) {
// data will return any items that have foo: bar and
// hello: world in their properties
});
findAll(callback)
Will retrieve all data from the collection
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback to fire upon retrieving data |
remove(id, callback)
Will remove an item from the Store based on its ID
Parameters:
Name | Type | Description |
---|---|---|
id |
number | The ID of the item you want to remove |
callback |
function | The callback to fire after saving |
save(updateData, callback, id)
Will save the given data to the DB. If no item exists it will create a new
item, otherwise it'll simply update an existing item's properties
Parameters:
Name | Type | Description |
---|---|---|
updateData |
object | The data to save back into the DB |
callback |
function | The callback to fire after saving |
id |
number | An optional param to enter an ID of an item to update |