Guest User

Untitled

a guest
Jul 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class MysqlIdGenerator:
  2. def __init__(self, engine):
  3. self.engine = engine
  4.  
  5. async def next(self, table):
  6. tpl = "REPLACE INTO {} (stub) VALUES ('a');"
  7. sql = tpl.format(table.name)
  8. sel = "SELECT LAST_INSERT_ID();"
  9. async with self.engine.acquire() as conn:
  10. await conn.execute(sql)
  11. return await (await conn.execute(sel)).scalar()
Add Comment
Please, Sign In to add comment