UNPKG

@node-server/renderer

Version:

NodeServerJs is a library with standard feature implemented for web and api

36 lines (34 loc) 1.03 kB
import { Handler } from "./handler"; import { Api, ApiResponse } from "./api"; import { Logger } from "@node-server/utils"; export class SQLHandler extends Handler { extention:string = "sql"; async Handle(api:Api, req, res){ var response = new ApiResponse(); var db = req.GetContext("mysql"); if(db) { try { var _db = db(); response.setSuccess(await db().query(api.func)); } catch(e) { Logger.error(e); response.setError("Can not handle the api", 500) } } else response.setError("Can not handle the api", 500) return response; } Create(filepath , api_name , data) { var api = new Api(); api.name = api_name; api.filename = filepath; api.ext = this.extention; api.func = data; return api; } }