Skip to content

Instantly share code, notes, and snippets.

@jimklo
Created February 25, 2012 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimklo/1904807 to your computer and use it in GitHub Desktop.
Save jimklo/1904807 to your computer and use it in GitHub Desktop.
try to figure out collation in couchdb
from couchdb.client import Server
server = Server()
db = server['collation-test']
try:
for idx in range(65535):
db.save( {'unichr':unichr(idx), 'code': idx, 'hex': str(hex(idx))} )
print "{0}\n".format(hex(idx))
except Exception, e:
raise e
function(doc) {
log(doc.code + " hex:"+doc.hex);
emit(doc.unichr, doc.hex);
}
@kxepal
Copy link

kxepal commented Feb 28, 2012

bulk_update works faster(;

docs = []
for idx in range(65535):
    docs.append({'unichr':unichr(idx), 'code': idx, 'hex': str(hex(idx))})
db.update(docs)

@jimklo
Copy link
Author

jimklo commented Feb 28, 2012 via email

@kxepal
Copy link

kxepal commented Feb 28, 2012

It's easy to handle insert failure:

docs = []
for idx in range(65535):
    docs.append({'unichr':unichr(idx), 'code': idx, 'hex': str(hex(idx))})
for success, docid, rev_or_exc in db.update(docs, all_or_nothing=True):
    if success:
        print docid, rev_or_exc
    else:
        raise rev_or_exc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment