GCP Connecting cloud function with Cloud SQL .

Опубликовано: 10 Октябрь 2024
на канале: VeryLazyCoders
4,606
44

For what is serverless connector Please see the link below
   • GCP Serverless VPC Access #gcp #gcpcloud  

-----------------------------------------------------------------------
Code
const mysql = require('mysql');

exports.helloWorld = (req, res) = {

const pool = mysql.createPool({
connectionLimit : 1,
host: 'xx.xx.xx.xx',//host internal ip
port:'3306',
user: 'root',
password: 'xxx',
database: 'xxx'
});

pool.query(`SELECT * FROM User`, function (error, results) {
console.log(error);
console.log(results)
res.status(200).send(results);

});



};