-
Notifications
You must be signed in to change notification settings - Fork 1
CouchDBStore
podefr edited this page Apr 4, 2012
·
3 revisions
CouchDBStore is Emily's CouchDBStore. But by using Olive's Transport, it works perfectly fine in your browser!
###Full example
Say you have the following document in CouchDB
{
"_id": "document1",
"_rev": "1",
"key": "value"
}
require(["CouchDBStore", "Olives/Transport"], function (CouchDBStore, Transport) {
var couchDBStore = new CouchDBStore();
couchDBStore.setTransport(new Transport(io, href));
// Synchronize with document1 in database. Sync is asynchronous so it returns an [Emily Promise](https://github.com/flams/emily/wiki/Promise).
couchDBStore.sync("database", "document1").then({
// And you're done! CouchDBStore will always be updated if the database is updated.
couchDBStore.get("key"); // value
// You can modify the store
couchDBStore.set("key", "my value");
// Then upload its new value
couchDBStore.upload();
});
});