Skip to main content

Hi, I'm Mariano Guerra, below is my blog, if you want to learn more about me and what I do check a summary here: marianoguerra.github.io or find me on twitter @warianoguerra or Mastodon @marianoguerra@hachyderm.io

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});
};