couchdb-schematics

UNKNOWN


License
BSD-3-Clause
Install
pip install couchdb-schematics==1.1.1

Documentation

CouchDB + Schematics

Python Structured CouchDB Documents for Humans

Build Status

Here it is!!

You can start with a standalone schematics model

from schematics.models import Model
from schematics.types import StringType

class User(Model):
    name = StringType()
    email = StringType(required=True)

and mix in a SchematicsDocument

from couchdb_schematics.document import SchematicsDocument

class UserDocument(SchematicsDocument, User):
   pass

or equivalently,

from couchdb_schematics.document import SchematicsDocument
from schematics.types import StringType

class UserDocument(SchematicsDocument):
    name = StringType()
    email = StringType(required=True)

Now you are ready to load, store and setup either ViewFields or ViewDefinitions.

from couchdb import Server

server = Server()
if 'test' not in server:
   server.create('test')
db = server['test']

# both forms of initialization are equivalent
user = UserDocument(dict(name='Ryan', email='thedude@gmail.com'))

user.store(db)

# note: SchematicsDocument provides UserDocument with id and rev attirbutes
# that correspond to _id and _rev values of a CouchDB document
# SchematicsDocuments alway set the doc_type attribute to the name of the classs

# read the data back in
u2 = UserDocument.load(db, user.id)

assert u2.email = 'thedude@gmail.com'
assert u2.doc_type == 'UserDocument'

Installation

$ pip install couchdb-schematics

Tests

$ py.test tests/