/motorm

Async Motor ORM

Primary LanguagePythonApache License 2.0Apache-2.0

motorm

Async Motor ORM

Coverage Coverage
  1. Declare model like in Schematics, but use AsyncModel instead Model.
class Person(AsyncModel):
     name = StringType(required=True)
     website = URLType()
  1. Connect to a database
>>> connect("MySystem_DB")
  • Save (Update / Create), if the object has id it will be an update
>>> person = Person()
>>> person.name = "Jonny Bravo"
>>> person.website = "http://google.com"

>>> person = yield person.save()
  • Retrive from id
>>> person = yield Person.objects.get(id=1)
  • Retrive from a model field
>>> person = yield Person.objects.get(name="Jonny Bravo")
  • Retrive all objects from cursor database
>>> persons = yield Person.objects.filter({"name": {"$regex": "Jon.*"}}).all()

or

>>> p_cursor = yield Person.objects.filter({"name": {"$regex": "Jon.*"}})
>>> persons = yield p_cursor.all()
  • Retrive all objects from database
>>> persons = yield Person.objects.all()
  • Iterate asynchrony through cursor objects
>>> p_cursor = Person.objects.filter({"name": {"$regex": "Jon.*"}})

>>> while (yield p_cursor.fetch_next):
>>>     person = p_cursor.next_object()