-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.js
49 lines (43 loc) · 1.4 KB
/
sql.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
41
42
43
44
45
46
47
48
49
var mysql = require('mysql');
var con;
app.post('/setserver', (req, res) => {
//res.end;
con = mysql.createConnection({
host:req.body.host,// "localhost",
user: req.body.username,
password: req.body.password,
port: req.body.port
});
con.connect(function (err) {
if (err) throw err;
console.log("myysql server Connected!");
res.end();
});
});
app.post('/gettablenames', (req, res) => {
var product = [];
con.query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_schema ='" + req.body.mysqdatabasename + "'" , function (err, result) {
if (err) throw err;
result.forEach(element => {
product.push([element.TABLE_NAME])
});
res.send(product);
console.log("table names send!");
});
});
app.post('/gettabledata', (req, res) => {
var product = [];
con.query("SELECT * from " + req.body.mysqdatabasename + "." + req.body.sqltablesnames , function (err, result) {
if (err) throw err;
res.send(result);
console.log("table data send!");
});
});
app.post('/gettabledatabyquery', (req, res) => {
var product = [];
con.query(req.body.query, function (err, result) {
if (err) throw err;
res.send(result);
console.log("table data send!");
});
});