Source

pythonwise / curl-and-couchdb.sh

#!/bin/bash

# curl and couchdb - a love story

set -v
server=http://localhost:5984

# Handshake
curl -s $server
read

# Is something running?
curl -s $server/_active_tasks
read

# List of all databases
curl -s $server/_all_dbs
read

# Readable list of all databases
curl -s $server/_all_dbs | python -m json.tool
read

# View database
curl -s $server/people | python -m json.tool
read

# View all docs
curl -s $server/people/_all_docs | python -m json.tool
read

# View all docs with content
curl -s "$server/people/_all_docs?include_docs=true" | python -m json.tool
read

db=foo
# Create database
curl -s -X PUT $server/$db
read

# Create document
id=$(uuid)
curl -s -d'{"a" : 1, "b" : 2}' -X PUT $server/$db/$id
read

# Get document
curl -s $server/$db/$id | python -m json.tool
read

# Edit document
curl -s $server/$db/$id | python -m json.tool > doc.json
vim doc.json
curl -s -d@doc.json -X PUT $server/$db/$id
curl -s $server/$db/$id | python -m json.tool
read

# Delete it (we need the revision)
rev=$(curl -s $server/$db/$id | egrep -o '[0-9]+-[a-z0-9]{32}')
curl -s -X DELETE "$server/$db/$id?rev=$rev"
read

# Delete the database
curl -s -X DELETE $server/$db
read

# Run a view
curl -s $server/people/_design/people/_view/managers | python -m json.tool
read
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.