Guest User

Untitled

a guest
Jul 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. // create a new store
  2. var store = new Lawnchair({adaptor:'dom', table:'people'});
  3.  
  4. // saving documents
  5. store.save({name:'brian'});
  6.  
  7. // optionally pass a key
  8. store.save({key:'config', settings:{color:'blue'}});
  9.  
  10. // updating a document in place is the same syntax
  11. store.save({key:'config', settings:{color:'green'}});
  12.  
  13. // almost everything accepts a callback
  14. var me = {name:'brian'};
  15.  
  16. store.save(me, function(doc){
  17. console.log(doc);
  18. });
  19.  
  20. // terse callbacks
  21. store.all('console.log(r)');
  22.  
  23. // expands to:
  24. store.all(function(r){ console.log(r) });
  25.  
  26. // other ways to find documents
  27. store.get(me, 'console.log(r)');
  28.  
  29. store.find('name === "brian"', 'console.log(r)');
  30.  
  31. // classic iteration
  32. people.each(function(r){
  33. console.log(r);
  34. });
  35.  
  36. // classic with terse shorthand syntax
  37. people.each('console.log(r)');
  38.  
  39. // simple removal
  40. store.remove(me, function() {
  41. console.log('buh bye!');
  42. });
  43.  
  44. // nothing lasts forever..
  45. store.nuke();
Add Comment
Please, Sign In to add comment