Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 0.97 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ########### CouchDB api-bash ###########
  2. ###### type less, relax more ###########
  3.  
  4. function iris () {
  5.     export irdb="http://tzk.iriscouch.com/$1"
  6. }
  7.  
  8. function here () {
  9.     export loc="http://127.0.0.1:5984/$1"
  10. }
  11.  
  12. ## revision/2 : base doc
  13. function revision () {
  14.     return curl -s -n -X GET "$1/$2" | cut -d, -f2 | cut -d\" -f4
  15. }
  16.  
  17. ## delete/2 base doc
  18. function delete () {
  19.     local version=revision $1 $2
  20.     local resource="$1/$2"
  21.     curl -s -n -H "Content-Type: application/json" \
  22.     -X DELETE "$1/$2?rev=$version"
  23. }
  24.  
  25. ## list/2 base includep (if non-nil, true)
  26. function list () {
  27.     if [ $2 == "" ]; then
  28.         include=""
  29.     else
  30.         include="&include_docs=true"
  31.     fi
  32.     curl -s -n -X GET "$1?_all_docs$include"
  33. }
  34.  
  35. ## replicate/3 source target continuous
  36. function replicate () {
  37.     if [ $3 == "" ]; then
  38.         continuous=""
  39.     else
  40.         continuous=",\"continuous\":true"
  41.     fi
  42.     curl -X POST http://127.0.0.1:5984/_replicate \
  43.     -d "{\"source\":\"$1\",\"target\":"$2",$continuous}"
  44. }