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
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
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))
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))
def __init__(self, database): self.driver = registry.get_driver(database) self.connection = None self.cursor = None