-
-
Save inator/5f67333616050f9005c1 to your computer and use it in GitHub Desktop.
bash couch stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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