I am facing several difficulties to developer one Watson Function to access my MySql DB.
The code below is what I had tried so far :
/**
/**
*
* main() will be run when you invoke this action
*
* @param Cloud Functions actions accept a single parameter, which must be a JSON object.
*
* @return The output of this action, which must be a JSON object.
*
*/
function main(params) {
//Conexao com BD MySQL
const mysql = require('mysql');
//A partir do MySQL 8 apresenta o erro ao utilizar o usuário root para conexão, necessário criar novo usuário (instrução no Readme)
const connection = mysql.createConnection({
host: 'xxxxxxxxxxxxxxxxxxxxt',
user: 'yyyyyyyyyyyyy',
password: 'sssssssssssssssss',
database: 'zzzzzzzzzzzzzzzz'
});
connection.connect(function (err) {
if (err) {
console.log("deu erro");
console.log('error connecting: ' + err.stack);
return;
}
console.log('*****OK*****');
console.log ('connected as id : ' + connection.threadId);
});
console.log('** FINAL **');
return { message: 'Ropando CF com sucesso - MSG : ' + params.user_input };
}
With this code I am getting this error :
{
"error": "The action did not produce a valid response and exited unexpectedly."
}
[
"2020-09-17T11:42:16.628518Z stdout: *****OK*****",
"2020-09-17T11:42:16.628538Z stdout: connected as id : 242158410",
"2020-09-17T11:43:02.895087Z stderr: events.js:174",
"2020-09-17T11:43:02.895115Z stderr: throw er; // Unhandled 'error' event",
"2020-09-17T11:43:02.895122Z stderr: ^",
"2020-09-17T11:43:02.895127Z stderr: ",
"2020-09-17T11:43:02.895132Z stderr: Error: Connection lost: The server closed the connection.",
"2020-09-17T11:43:02.895138Z stderr: at Protocol.end (/node_modules/mysql/lib/protocol/Protocol.js:112:13)",
"2020-09-17T11:43:02.895143Z stderr: at Socket.<anonymous> (/node_modules/mysql/lib/Connection.js:97:28)",
"2020-09-17T11:43:02.895148Z stderr: at Socket.<anonymous> (/node_modules/mysql/lib/Connection.js:502:10)",
"2020-09-17T11:43:02.895153Z stderr: at Socket.emit (events.js:203:15)",
"2020-09-17T11:43:02.895159Z stderr: at endReadableNT (_stream_readable.js:1145:12)",
"2020-09-17T11:43:02.895164Z stderr: at process._tickCallback (internal/process/next_tick.js:63:19)",
"2020-09-17T11:43:02.895169Z stderr: Emitted 'error' event at:",
"2020-09-17T11:43:02.895174Z stderr: at Connection._handleProtocolError (/node_modules/mysql/lib/Connection.js:425:8)",
"2020-09-17T11:43:02.895179Z stderr: at Protocol.emit (events.js:198:13)",
"2020-09-17T11:43:02.895184Z stderr: at Protocol._delegateError (/node_modules/mysql/lib/protocol/Protocol.js:390:10)",
"2020-09-17T11:43:02.895190Z stderr: at Protocol.end (/node_modules/mysql/lib/protocol/Protocol.js:116:8)",
"2020-09-17T11:4
Can someone tell me what is wrong with it..?
Or someone has an example of how to do it .?
Thank you in advance.
------------------------------
Eduardo Gameiro
------------------------------
#WatsonAssistant