{"action":"created","issue":{"url":"https://api.github.com/repos/dscape/nano/issues/51","labels_url":"https://api.github.com/repos/dscape/nano/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/dscape/nano/issues/51/comments","events_url":"https://api.github.com/repos/dscape/nano/issues/51/events","html_url":"https://github.com/dscape/nano/pull/51","id":2875853,"number":51,"title":"#50 Implement Support for Document Update Handlers","user":{"login":"twilson63","id":21292,"avatar_url":"https://avatars.githubusercontent.com/u/21292?v=3","gravatar_id":"","url":"https://api.github.com/users/twilson63","html_url":"https://github.com/twilson63","followers_url":"https://api.github.com/users/twilson63/followers","following_url":"https://api.github.com/users/twilson63/following{/other_user}","gists_url":"https://api.github.com/users/twilson63/gists{/gist_id}","starred_url":"https://api.github.com/users/twilson63/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twilson63/subscriptions","organizations_url":"https://api.github.com/users/twilson63/orgs","repos_url":"https://api.github.com/users/twilson63/repos","events_url":"https://api.github.com/users/twilson63/events{/privacy}","received_events_url":"https://api.github.com/users/twilson63/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2012-01-17T22:32:41Z","updated_at":"2015-04-29T20:40:42Z","closed_at":"2012-01-17T23:06:49Z","pull_request":{"url":"https://api.github.com/repos/dscape/nano/pulls/51","html_url":"https://github.com/dscape/nano/pull/51","diff_url":"https://github.com/dscape/nano/pull/51.diff","patch_url":"https://github.com/dscape/nano/pull/51.patch"},"body":"``` javascript\r\n   /*\r\n    * calls document update handler\r\n    *\r\n    * @param {design_name:string} design document namd\r\n    * @param {update_name:string} update method to call\r\n    * @param {doc_name:string} document name to update\r\n    * @param {params:object} additions to the querystring\r\n   */   \r\n  function update_with_handler_doc(design_name, update_name, doc_name, params, callback) {\r\n     if(typeof params === \"function\") {\r\n       callback = params;\r\n       params = {};\r\n     }\r\n     var update_path = '_design/' + design_name + '/_update/' + update_name + '/' + doc_name;\r\n     return relax({db: db_name, path: update_path, method: \"PUT\", params: params}, callback);\r\n   }\r\n```\r\n\r\nThen a public db alias called \"update\"\r\n\r\n``` javascript\r\n  public_functions.updateWithHandler = update_with_handler_doc;\r\n```\r\n\r\n## usage\r\n\r\nThis should provide the ability to easily execute atomic updates on the couchdb server:\r\n\r\nDocument Update Handler in Design Document called my_design_doc:\r\n\r\n``` javascript\r\n\"updates\": {\r\n  \"in-place\" : \"function(doc, req) {\r\n      var field = req.query.field;\r\n      var value = req.query.value;\r\n      var message = 'set '+field+' to '+value;\r\n      doc[field] = value;\r\n      return [doc, message];\r\n  }\"\r\n}\r\n```\r\n\r\nThen using nano:\r\n\r\n``` javascript\r\n@db.updateWithHandler(\"my_design_doc\", \"in-place\", \"<doc_name>\", { field: \"foo\", value: \"bar\" }, function(e,b) { console.log(b); }); \r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/dscape/nano/issues/comments/97578599","html_url":"https://github.com/dscape/nano/pull/51#issuecomment-97578599","issue_url":"https://api.github.com/repos/dscape/nano/issues/51","id":97578599,"user":{"login":"mandric","id":25641,"avatar_url":"https://avatars.githubusercontent.com/u/25641?v=3","gravatar_id":"","url":"https://api.github.com/users/mandric","html_url":"https://github.com/mandric","followers_url":"https://api.github.com/users/mandric/followers","following_url":"https://api.github.com/users/mandric/following{/other_user}","gists_url":"https://api.github.com/users/mandric/gists{/gist_id}","starred_url":"https://api.github.com/users/mandric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mandric/subscriptions","organizations_url":"https://api.github.com/users/mandric/orgs","repos_url":"https://api.github.com/users/mandric/repos","events_url":"https://api.github.com/users/mandric/events{/privacy}","received_events_url":"https://api.github.com/users/mandric/received_events","type":"User","site_admin":false},"created_at":"2015-04-29T20:40:42Z","updated_at":"2015-04-29T20:40:42Z","body":"Are the docs missing for updateWithHandler or am I just not finding them?"}}