def find_author(ain):
async with engine.acquire() as conn:
author = model.Author.__table__
if ain.get('first_name'):
where = and_(author.c.first_name == ain[
'first_name'], author.c.last_name == ain['last_name'])
else:
where = and_(
author.c.last_name == ain['last_name'], author.c.first_name == None)
res = await conn.execute(select([author.c.id, author.c.first_name, author.c.last_name]).where(where))
a = await res.fetchone()
if a:
ao = {'id': a[0], 'last_name': a[2]}
if a[1]:
ao['first_name'] = a[1]
return ao
评论列表
文章目录