Skip to main content

This is my blog, more about me at marianoguerra.github.io

🦋 @marianoguerra.org 🐘 @marianoguerra@hachyderm.io 🐦 @warianoguerra

jquery.couch snippets

algunos snippets para hacer tareas comunes en jquery.couch


var datos = {};
datos.db = "datos";

datos.login = function (user, password, okCb, errorCb) {
$.couch.login({"name": user, "password": password, "success": okCb, "error": errorCb});
};

datos.logout = function (okCb, errorCb) {
$.couch.logout({"success": okCb, "error": errorCb});
};

datos.checkSession = function (okCb, errorCb) {
$.couch.session({"success": okCb, "error": errorCb});
};

datos.create = function (data, okCb, errorCb) {
$.couch.db(datos.db).saveDoc(data, {"success": okCb, "error": errorCb});
};

datos.get = function (id, okCb, errorCb, rev) {
$.couch.db(datos.db).openDoc(id, {"success": okCb, "error": errorCb, "rev": rev});
};

datos.remove = function (id, rev, okCb, errorCb) {
$.couch.db(datos.db).removeDoc({"_id": id, "_rev": rev}, {"success": okCb, "error": errorCb});
};

datos.getRecent = function (limit, okCb, errorCb) {
$.couch.db(datos.db).view("datos/recent-items",
{"limit": limit, "descending": true, "success": okCb, "error": errorCb});
};