-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 928 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { json, send } = require('micro');
const config = require('./config');
const hive = require('./lib/hive');
const { error } = console;
module.exports = async (req, res) => {
if (req.method !== 'POST') {
return send(res, 405, {
message: 'Method Not Allowed',
});
}
const { statement } = await json(req);
if (!statement) {
return send(res, 400, {
message: 'Invalid statement. Statement payload must have this form: { "statement": "SELECT * FROM table" }',
});
}
try {
const connection = await hive.connect({
host: config.HIVE_HOST,
port: config.HIVE_PORT,
username: config.HIVE_USERNAME,
password: config.HIVE_PASSWORD,
});
const data = await hive.execute(connection, statement);
connection.close();
return send(res, 200, data);
} catch (err) {
error(err);
return send(res, 500, {
message: err.message,
});
}
};