Beispiel #1
0
import asyncio
from tailow.document import Document
from tailow.fields import *
from tailow.connection import Connection
from tailow import pymongo

loop = asyncio.get_event_loop()

conn = Connection.connect("mongodb://localhost:27017", "test", loop=loop)


class SampleDocument(Document):
    a = IntegerField(required=True)

    class Meta:
        indexes = [("a", pymongo.ASCENDING)]


s = SampleDocument()
s.a = 4


async def saveit():
    await s.save()
    print("save complete")
    await s.delete()
    print("delete also complete")


loop.run_until_complete(saveit())
Beispiel #2
0
 def test_connection_defaults(self, asyncio_mock):
     Connection.connect(self.uri, self.db_name)
     self.assertIsInstance(Connection._default_database,
                           AsyncIOMotorDatabase)
     self.assertIsInstance(Connection._default_client, AsyncIOMotorClient)
Beispiel #3
0
def connect(*args, **kwargs):
    Connection.connect(*args, **kwargs)
Beispiel #4
0
 def get_collection(cls, name):
     return Connection.get_collection(name)
Beispiel #5
0
 def coll(self):
     return Connection.get_collection(self.klass._collection)