Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created January 27, 2011 06:32
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save brianleroux/798155 to your computer and use it in GitHub Desktop.
Save brianleroux/798155 to your computer and use it in GitHub Desktop.
examples for using lawnchair js
// create a new store
var store = new Lawnchair({adaptor:'dom', table:'people'});
// saving documents
store.save({name:'brian'});
// optionally pass a key
store.save({key:'config', settings:{color:'blue'}});
// updating a document in place is the same syntax
store.save({key:'config', settings:{color:'green'}});
// almost everything accepts a callback
var me = {name:'brian'};
store.save(me, function(doc){
console.log(doc);
});
// terse callbacks
store.all('console.log(r)');
// expands to:
store.all(function(r){ console.log(r) });
// other ways to find documents
store.get(me, 'console.log(r)');
store.find('name === "brian"', 'console.log(r)');
// classic iteration
people.each(function(r){
console.log(r);
});
// classic with terse shorthand syntax
people.each('console.log(r)');
// simple removal
store.remove(me, function() {
console.log('buh bye!');
});
// nothing lasts forever..
store.nuke();
@caponica
Copy link

You've got an adaptor / adapter typo in line 2

https://gist.github.com/caponica/5619408

@DURK
Copy link

DURK commented Jun 13, 2013

Apparently, Lawnchair's get-function only works with as a lookup by key. Also there is no find-function in Lawnchair's API. To get records using a filter, you can use the query plugin.

Disclaimer:
I am new to Lawnchair (that's the reason I'm on this page). So these statements are simply based on a quick look at the code and API-documentation, as I couldn't get these functions to work. Please correct me if I'm wrong:)

@Saiyan1
Copy link

Saiyan1 commented Sep 21, 2013

I have the same problem.
I can't get work the "find" function.
"Uncaught TypeError: Object # has no method 'find' "
(And yes, I am importing the query.js)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment