def get_ebooks_ids_for_object(object_name, id):
async with engine.acquire() as conn:
if object_name.lower() == 'author':
q = select([model.ebook_authors.c.ebook_id]).where(model.ebook_authors.c.author_id == id)
elif object_name.lower() == 'series':
ebook = model.Ebook.__table__
q = select([ebook.c.id]).where(ebook.c.series_id == id)
elif object_name.lower() == 'bookshelf':
bookshelf_item = model.BookshelfItem.__table__
q = select([bookshelf_item.c.ebook_id]).where(and_(bookshelf_item.c.ebook_id != None,
bookshelf_item.c.bookshelf_id == id)).distinct()
else:
raise ValueError('Invalid object_name')
res = await conn.execute(q)
res = await res.fetchall()
return list(map(lambda x: x[0], res))
评论列表
文章目录