2017-12-15 09:38:56 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const auth = require('../../services/auth');
|
|
|
|
const sql = require('../../services/sql');
|
2018-01-07 22:35:44 +08:00
|
|
|
const wrap = require('express-promise-wrap').wrap;
|
2017-12-15 09:38:56 +08:00
|
|
|
|
2018-01-07 22:35:44 +08:00
|
|
|
router.post('/execute', auth.checkApiAuth, wrap(async (req, res, next) => {
|
2017-12-15 09:38:56 +08:00
|
|
|
const query = req.body.query;
|
|
|
|
|
2017-12-20 11:33:44 +08:00
|
|
|
try {
|
|
|
|
res.send({
|
|
|
|
success: true,
|
2017-12-24 00:02:38 +08:00
|
|
|
rows: await sql.getAll(query)
|
2017-12-20 11:33:44 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
res.send({
|
|
|
|
success: false,
|
|
|
|
error: e.message
|
|
|
|
});
|
|
|
|
}
|
2018-01-07 22:35:44 +08:00
|
|
|
}));
|
2017-12-15 09:38:56 +08:00
|
|
|
|
|
|
|
module.exports = router;
|