Hi,
i have the following problem.. i can use a variable to be used as a query, but it only works when i use the "current" file, not when i make an extra file like "mysql" in Node.js editor.
so this works:
File Current
// get the client
const mysql = require('mysql2');
// create the connection to database
const connection = mysql.createConnection({
host: '10.10.10.1',
user: 'aaaa',
database: 'test1',
password: 'aaaa'
});
console.log("making request")
var query = [[QUERY]];
await(new Promise((resolve, reject) => {
connection.query(
query,
function (err, results, fields) {
if(err)
{
reject(err)
return
}
[[RESULTS]] = results
resolve()
}
);
}));
console.log([[RESULTS]])
connection.end();
console.log("ended connection")
Output is:
Thread #1 : making request
Thread #1 : [{"COL1":1,"COL2":"abc","COL3":"def"}]
Thread #1 : ended connection
But this works not:
File Current:
await require("../mysql")();
console.log("query done")
File mysql:
module.exports = async function(){
// get the client
const mysql = require('mysql2');
// create the connection to database
const connection = mysql.createConnection({
host: '10.10.10.1',
user: 'aaaa',
database: 'test1',
password: 'aaaa'
});
console.log("making request")
var query = [[QUERY]];
await(new Promise((resolve, reject) => {
connection.query(
query,
function (err, results, fields) {
if(err)
{
reject(err)
return
}
[[RESULTS]] = results
resolve()
}
);
}));
console.log([[RESULTS]])
connection.end();
console.log("ended connection")
}
I get the error
Thread #1 : making request
Thread #1 : TypeError: Cannot read property 'constructor' of undefined
how to get it done?