Skip to content

Instantly share code, notes, and snippets.

@mtthwkfmn
Forked from jcrosby/gist:92294
Created September 16, 2009 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtthwkfmn/187831 to your computer and use it in GitHub Desktop.
Save mtthwkfmn/187831 to your computer and use it in GitHub Desktop.
var store = $.cloudkit;
store.boot({
// booting the store reads the metadata on the server,
// loads existing data, and configures the local store
// for use
success: function() {
// the local store is now ready
// create a 'thing'
store.collection('things').create({name:"box"}, {
success: function(thing) {
// the 'thing' resource has now been created
// locally and posted to the server
alert(thing.json().name); // this will display "box"
// update the 'thing'
thing.update({name:"book"} {
success: function() {
// the updated 'thing' resource has been mirrored
// on the server and is ready for use again
alert(thing.json().name); // this is now "book"
// delete the 'thing'
thing.destroy({
success: function() {
// the 'thing' has now been deleted
}
}
}
})
}
});
// create a 'note'
store.collection('notes').create({foo:"bar"}, {
success: function(note) {
// do something with the note
}
});
// find all 'note' resources
var notes = store.collection('notes').all();
// get a specific note
var note = store.collection('notes').get(some_random_note.id());
// find all things having a name of 'book'
var matches = store.collection('things').query("?name='book'");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment