Skip to content

Instantly share code, notes, and snippets.

@batok
Created November 19, 2008 19:08
Show Gist options
  • Save batok/26642 to your computer and use it in GitHub Desktop.
Save batok/26642 to your computer and use it in GitHub Desktop.
rom couchdb.schema import Document, View, IntegerField, TextField
from couchdb import Database
map_fun = """
function(doc){
emit(doc.name, doc.age);
}
"""
class Person(Document):
name = TextField()
age = IntegerField()
by_name = View('people', map_fun)
db = Database("http://127.0.0.1:5984/borrame")
#print Person.by_name
#print Person.by_name.map_fun
# to make a view permane either do this
#from couchdb.design import ViewDefinition
#ViewDefinition.sync_many(db, [Person.by_name])
# or this
#Person.by_name.sync(db)
#
#Person(name = "batok", age = 48).store(db)
#Person(name = "pochas", age = 47).store(db)
#Person(name = "robert", age = 30).store(db)
view = Person.by_name( db, count = 3)
for person in view:
print person
#when I run this I got this error ...
"""
Traceback (most recent call last):
File "cdb.py", line 29, in <module>
for person in view:
File "/Users/myself/couchdb_python_26_svn/couchdb/client.py", line 720, in __iter__
yield wrapper(row)
File "/Users/myself/couchdb_python_26_svn/couchdb/schema.py", line 239, in wrapper
data['_id'] = row.id
TypeError: 'int' object does not support item assignment
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment