ahserver_g/ahserver/dbadmin.py

58 lines
1.3 KiB
Python
Raw Normal View History

2020-04-22 11:37:20 +08:00
import os
import re
import traceback
2022-06-22 17:10:20 +08:00
from aiohttp.web_response import Response
2020-04-22 11:37:20 +08:00
from aiohttp.web_exceptions import (
HTTPException,
HTTPExpectationFailed,
HTTPForbidden,
HTTPMethodNotAllowed,
HTTPNotFound,
)
from aiohttp import web
from aiohttp.web_request import Request
from aiohttp.web_routedef import AbstractRouteDef
from aiohttp.web import json_response
from sqlor.crud import CRUD
from appPublic.dictObject import multiDict2Dict
from appPublic.jsonConfig import getConfig
2022-06-23 14:58:03 +08:00
from appPublic.app_logger import AppLogger
2020-04-22 11:37:20 +08:00
from .error import Error,Success
actions = [
"browse",
"add",
"update",
"filter"
]
2022-06-23 14:58:03 +08:00
class DBAdmin(AppLogger):
2020-04-22 11:37:20 +08:00
def __init__(self, request,dbname,tablename, action):
self.dbname = dbname
self.tablename = tablename
self.request = request
self.action = action
if action not in actions:
2022-06-23 14:58:03 +08:00
self.debug('action not defined:%s' % action)
2020-04-22 11:37:20 +08:00
raise HTTPNotFound
try:
self.crud = CRUD(dbname,tablename)
except Exception as e:
2022-06-23 14:58:03 +08:00
self.info('e= %s' % e)
2020-04-22 11:37:20 +08:00
traceback.print_exc()
raise HTTPNotFound
async def render(self) -> Response:
try:
d = await self.crud.I()
return json_response(Success(d))
except Exception as e:
2022-06-23 14:58:03 +08:00
self.debug('except=%s' % e)
2020-04-22 11:37:20 +08:00
traceback.print_exc()
return json_response(Error(errno='metaerror',msg='get metadata error'))