I am new in Google Cloud Function, Here am trying to load data from cloud SQL for that I have written a code, which has database connection as well as SQL query string however when am trying to test the function it is throwing either error or Object or sometime it says you are not returning any data. I tried many ways to send data but still doesn't work for me. Thanks in advance.
Code snippets,
exports.welcome = async (req, res) => {
const tag = req?.body?.fulfillmentInfo?.tag;
let message = tag || req?.query?.message || req?.body?.message || 'Hello World!';
const pool = mysql.createPool({
connectionLimit: 1,
host: '10.30.48.2',
user: 'root',
password: 'TEST@TEST',
database: 'hospital_assist'
});
const jsonResponse = {
fulfillment_response: {
messages: [
{
text: {
//fulfillment text response to be sent to the agent
text: [`Welcome entry point ${message}`],
},
},
],
},
};
let qResult = await pool.query('SELECT * FROM Patients;');
// pool.query('SELECT * FROM Patints', (error, result) => {
// console.log(error);
// console.log(result);
// console.log('In loop');
// res.status(200).send(jsonResponse);
// });
// await pool.query('select * from Patients;', (error, results) => {
// if (error) {
// console.log(error);
// res.status(200).send(jsonResponse);
// }
// qResult = results;
// // res.send(results);
// });
console.log(qResult);
console.log(`In loop ${qResult}`);
res.status(200).send(JSON.stringify(qResult));
// res.status(200).send(jsonResponse);
};