Asynchronous MongoDB ORM for Tornado
Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
monguo
test
.gitignore
.gitmodules
.travis.yml
MANIFEST.in
README.rst
requirements.txt
setup.py

README.rst

Monguo

https://github.com/shiyanhui/monguo/blob/master/doc/source/_static/monguo.jpg?raw=true

Info:Monguo is a full-featured, asynchronous MongoDB ORM with Motor dirver for Tornado applications.
Author:Lime YH.Shi

Installation

$ pip install monguo

Dependencies

Monguo works in all the environments officially supported by Tornado and Motor. It requires:

Examples

from monguo import *

Connection.connect('db') # connect to database

class UserDocument(Document):
    name  = StringField(required=True, unique=True, max_length=20)
    email = EmailField(required=True)
    age   = IntegerField()
    sex   = StringField(default='male', candidate=['male', 'female'])

    meta = {
        'collection': 'user'
    }

    @gen.coroutine
    def get_user_list(skip=0, limit=None):
        cursor = UserDocument.find().skip(skip)

        if limit is not None:
            assert isinstance(limit, int) and limit > 0
            cursor.limit(limit)

        user_list = yield cursor.to_list(None)
        raise gen.Return(user_list)

# insert
user_id = yield UserDocument.insert({
    'name': 'Bob',
    'email': 'bob@gmail.com'
})

# query
user = yield UserDocument.find_one({'name': 'Bob'})
user_list = yield UserDocument.get_user_list()

# update
yield UserDocument.update(
    {'_id': user_id},
    {'$set': {'age': 19}})

# delete
yield UserDocument.remove({'_id': user_id})