Пример #1
0
        def aiotest():
            from aiorm import registry

            driver = yield from registry.connect("protocol://host/db", name="other")
            self.assertEqual(DummyDriver.last_url, "protocol://host/db")
            self.assertEqual(driver.database, "db")
            self.assertEqual(registry.get_driver("other"), driver)
            registry._drivers.pop("other")
            DummyDriver.last_url = None
Пример #2
0
        def aiotest():
            from aiorm import registry

            driver = yield from registry.connect('protocol://host/db',
                                                 name='other')
            self.assertEqual(DummyDriver.last_url, 'protocol://host/db')
            self.assertEqual(driver.database, 'db')
            self.assertEqual(registry.get_driver('other'), driver)
            registry._drivers.pop('other')
            DummyDriver.last_url = None
Пример #3
0
    def run(self, cursor=None):
        @asyncio.coroutine
        def wrapped(cursor):
            sql_statement = self.render_sql()
            log.debug('{!r} % {!r}'.format(*sql_statement))
            yield from cursor.execute(*sql_statement)
            return True

        if cursor:
            return (yield from wrapped(cursor))
        else:
            driver = registry.get_driver(self._args[0].__meta__['database'])
            with (yield from driver.cursor()) as cursor:
                return (yield from wrapped(cursor))
Пример #4
0
    def run(self, cursor=None):
        @asyncio.coroutine
        def wrapped(cursor):
            sql_statement = self.render_sql()
            log.debug('{!r} % {!r}'.format(*sql_statement))
            yield from cursor.execute(*sql_statement)
            return True

        if cursor:
            return (yield from wrapped(cursor))
        else:
            driver = registry.get_driver(self._args[0].__meta__['database'])
            with (yield from driver.cursor()) as cursor:
                return (yield from wrapped(cursor))
Пример #5
0
    def run(self, cursor=None, fetchall=True):
        @asyncio.coroutine
        def wrapped(cursor):
            sql_statement = self.render_sql()
            if log.isEnabledFor(logging.DEBUG):
                log.debug('{} % {!r}'.format(*sql_statement))
            yield from cursor.execute(*sql_statement)
            return ((yield from cursor.fetchall()) if fetchall else
                    (yield from cursor.fetchone()))

        if cursor:
            return (yield from wrapped(cursor))
        else:
            driver = registry.get_driver(self._args[0].__meta__['database'])
            with (yield from driver.cursor()) as cursor:
                return (yield from wrapped(cursor))
Пример #6
0
    def run(self, cursor=None, fetchall=True):

        @asyncio.coroutine
        def wrapped(cursor):
            sql_statement = self.render_sql()
            if log.isEnabledFor(logging.DEBUG):
                log.debug('{} % {!r}'.format(*sql_statement))
            yield from cursor.execute(*sql_statement)
            return ((yield from cursor.fetchall())
                    if fetchall else (yield from cursor.fetchone()))

        if cursor:
            return (yield from wrapped(cursor))
        else:
            driver = registry.get_driver(self._args[0].__meta__['database'])
            with (yield from driver.cursor()) as cursor:
                return (yield from wrapped(cursor))
Пример #7
0
 def __init__(self, database):
     self.driver = registry.get_driver(database)
     self.connection = None
     self.cursor = None
Пример #8
0
 def __init__(self, database):
     self.driver = registry.get_driver(database)
     self.connection = None
     self.cursor = None