Thunder is an object-relational mapper (ORM) for Python
Python Shell
Latest commit 1c1a6d1 Jan 6, 2012 Johan Dahlin committed with jdahlin-litl Handle resetting of references and verify type checking
Permalink
Failed to load latest commit information.
thunder Handle resetting of references and verify type checking Jan 6, 2012
.gitignore Add testing infrastructure, making it pass pep8 and pyflakes Jan 4, 2012
LICENSE Initial revision Jan 3, 2012
MANIFEST.in Initial revision Jan 3, 2012
Makefile
NEWS Initial revision Jan 3, 2012
README.rst Add a mongoengine link as well Jan 5, 2012
ez_setup.py Initial revision Jan 3, 2012
requirements.txt Add testing infrastructure, making it pass pep8 and pyflakes Jan 4, 2012
setup.cfg Initial revision Jan 3, 2012
setup.py
setup.sh Initial revision Jan 3, 2012

README.rst

Thunder

Presentation

Thunder is an ORM for MongoDB built on top of the PyMongo driver.

It's inspired by Storm and reuses some APIs from mongoengine.

Tutorial

Thunder provides a Store class which provide apis for indexing and querying documents stored in MongoDB.

>>> from storm.store import Store

To create a simple store you can just provide the name of the database inside the mongo database:

>>> store = Store('mydb')

That's it, we now have a reference to store which can be used to insert and query objects.

First we need to define a document that can be inserted into a store:

>>> from storm.fields import ObjectIdField, StringField
>>> class Person(object):
...     id = ObjectIdField()
...     name = StringField()

All objects inserted into a store needs to at least have an ObjectIdField. There can only be one ObjectIdField per class.

To create a document you create the class normally:

>>> p = Person()
>>> p.name = 'John Cleese'
>>> store.add(p)

Note that this doesn't actually index the document into the database, that's only done when an explicit flush is issued:

>>> store.find(Person).count()
0
>>> store.flush()

We can now query the store for the document:

>>> store.find(Person).count()
1
>>> for person in store.find(Person):
>>>     print person
<X object at 0x.....>