def get(self, request, table_name=None):
"""Get endpoint. Retrieve one object by id (url param `id=`)
:param request: Sanic Request.
:param table_name: Name of the table to access.
"""
waf = get_jawaf()
table = registry.get(table_name)
try:
target_id = int(request.raw_args.get('id', None))
except:
return json({'message': 'no id'}, status=400)
if not table:
return json({'message': 'access denied'}, status=403)
async with Connection(table['database']) as con:
query = sa.select('*').select_from(table['table']).where(table['table'].c.id==target_id)
result = await con.fetchrow(query)
if not result:
return json({'message': 'not found', 'data': None}, status=404)
return json({'message': 'success', 'data': result}, status=200)
评论列表
文章目录