Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created October 9, 2012 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boxxxie/3861438 to your computer and use it in GitHub Desktop.
Save boxxxie/3861438 to your computer and use it in GitHub Desktop.
bash couch stuff
#!/bin/bash
# These functions require underscore-cli (npm install -g underscore-cli)
# a CouchDB instance
#host=$(<~/.couchrc)
host="$1"
couch-get() {
db="$1"
url="$host/$db"
echo curl -sX GET "$url"
curl -sX GET "$url"
}
couch-push(){
http="$1"
db="$2"
doc="$3"
url="$host/$db"
echo curl -X "$http" "$url" -H "'""Content-Type: application/json""'" -d @"$doc"
curl -X "$http" "$url" -H "'""Content-Type: application/json""'" -d @"$doc"
}
couch-post() {
db="$1"
doc="$2"
couch-push POST "$db" "$doc"
}
couch-put() {
db="$1"
doc="$2"
couch-push PUT "$db" "$doc"
}
couch-upload() {
db="$1"
file="$2"
couch_response=`$(couch-get "$db")`
echo "response = $couch_response"
echo underscore -d "$couch_response" extract _rev
rev=$(underscore -d "$couch_response" extract _rev)
echo "rev = $rev"
echo "rev w/o quotes = ${rev//\"}"
safe_file=${file// /-}
echo "file name = $safe_file"
url="$host/$1/$safe_file?rev=${rev//\"}"
echo "$url"
curl -sX PUT "$url" -H "Content-Type: $3" --data-binary @"$file"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment