Skip to content

Instantly share code, notes, and snippets.

@aerobless
Created June 28, 2018 12:09
Show Gist options
  • Save aerobless/8ef438b982837422b0b80053e46fc7b3 to your computer and use it in GitHub Desktop.
Save aerobless/8ef438b982837422b0b80053e46fc7b3 to your computer and use it in GitHub Desktop.
Example of how to use MySQL in a Google Cloud Function
const mysql = require('mysql');
const config = require('./config')['production'];
const pool = mysql.createPool({
connectionLimit: 1,
socketPath: '/cloudsql/' + config.database.connection,
user: config.database.user,
password: config.database.password,
database: config.database.name
});
function getResults(req, res) {
pool.query('select * from result;', (error, results) => {
if (error) {
console.log(error);
}
res.send(results);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment