Skip to content

Instantly share code, notes, and snippets.

@nickva
Created July 15, 2016 16:12
Show Gist options
  • Save nickva/aa157184fecd8bddef0e3c0de2ac3045 to your computer and use it in GitHub Desktop.
Save nickva/aa157184fecd8bddef0e3c0de2ac3045 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys, couchdb
DBURL='http://adm:pass@localhost:15984'
V = 'v'*1
def add_view(db):
db['_design/d1'] = {
"views": {
"v1": { "map": 'function(d){ emit(d._id, "%s"); }' % V,
# "reduce" : '_count'
}
}
}
def main(dbname, n, b):
print "DB URL:",DBURL,"DB Name:",dbname
print "Batches: ",n,"Batchsize:",b,"Total:",n*b
s = couchdb.Server(DBURL)
if dbname in set(s): s.delete(dbname)
db = s.create(dbname)
add_view(db)
for i in range(n):
db.update([{'_id':str(i*b+j)} for j in range(b)])
# query the view
vrs = db.view("d1/v1")
print "View Results: "
for vr in vrs:
print " -", vr.key, ":", vr.value
if __name__=='__main__':
args=sys.argv[1:]
if len(args)==3:
dbname, n, b = args[0], int(args[1]), int(args[2])
print ">>> dbname:", dbname, "n:", n, "b:", b
else:
raise Exception("Invalid arguments need dbname, numbatches, batchsize")
main(dbname, n, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment