Skip to main content

Define loosly ordered schema for mongodb documents.

Project description

nosqlalchemy

usage:


from nosqlalchemy import (
Collection,
Key,
ListCollection,
MongoDBInterface,
MongoSession,
SubCollection,
)

class SampleSubCollection(SubCollection):
__name__ = 'sample_sub_collection'

sub_key1 = Key()
sub_key2 = Key()

class SampleListCollection(ListCollection):
__name__ = 'sample_list_collection'
__list_element_type__ = int # base collection is set to object
# do not override to store any object type
# in the list

class SampleCollection(Collection):
__name__ = 'sample'
__database__ = 'test'
__primary_key__ = 'key1' # declares a unique value as unique within the
# collection.

key1 = Key()
key2 = Key()
sub_collection = SampleSubCollection()
list_collection = SampleListCollection()


mdi = MongoDBInterface() # args host='host', port='27017'
MSession = MongoSession(mdi)

sample_collection = SampleCollection()
sample_collection.key1 = 'key1'
sample_collection.key2 = 2
sample_collection.sub_collection.sub_key1 = 'sub_key1'
sample_collection.sub_collection.sub_key2 = 2
sample_collection.list_collection.append(1)
sample_collection.list_collection = 2

print sample_collection

print type(MSession.add(sample_collection))
col = MSession.query(SampleCollection).find_one({'sub_collection.sub_key2': 2})
print col
MSession.drop_all(SampleCollection)



commit 3f0fdfc871e3fd55e57999e45567bdb372c0bc8c
Author: Jared Rodriguez <jared.rodriguez@rackspace.com>
Date: Tue May 28 09:32:01 2013 -0500

remove unneeded assignment

commit a9328a037100e095eea14c376f004d6558191bc7
Author: Jared Rodriguez <jared.rodriguez@rackspace.com>
Date: Tue May 28 09:28:05 2013 -0500

Changes

commit 82bab92adebcb452b832a1166990602d8d65d47e
Author: Jared Rodriguez <jared.rodriguez@rackspace.com>
Date: Sun May 26 14:45:43 2013 -0500

Creating a python package and adding tests

Added SubCollection and ListCollection support

commit 259a066cfcb974984c959c26bd0f6ea5139f8343
Author: Jared Rodriguez <jrod@blacknode.net>
Date: Fri Jan 6 18:16:01 2012 -0600

fux0rs

commit 67e6a57f3a123aacabf1ced020ab1a5606aa69bf
Author: Jared Rodriguez <jrod@blacknode.net>
Date: Thu Dec 15 21:10:42 2011 -0600

first commit

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nosqlalchemy-0.9.2.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

nosqlalchemy-0.9.2-py2.7.egg (15.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page