pymorm是一个基于ORM框架的pymongo接口。
代码示例:
from pymorm import MongoObject, MongoObjectMetafrom pymongo import MongoClientdb = MongoClient("mongodb://localhost:27017/pymorm").get_default_database()class Test(MongoObject): __metaclass__ = MongoObjectMeta __collection__ = db.tests __defaults__ = {"username": "Test", "happiness": lambda: "poor"} def test_method(self, test): return test @property def test_property(self): return "test" @classmethod def test_classmethod(cls): return cls.__name__user = Test.add({})user2 = Test.add({"username": "Walter"})user2.happiness = "a lot!"print userprint user2user.commit()> User(_id=ObjectId('5519e5eb5dde7310f04d9bbe'), happiness=u'poor', username=u'Test') > User(_id=ObjectId('5519e5eb5dde7310f04d9bbe'), happiness=u'a lot!', username=u'Walter')
评论