Created
June 28, 2018 12:09
-
-
Save aerobless/8ef438b982837422b0b80053e46fc7b3 to your computer and use it in GitHub Desktop.
Example of how to use MySQL in a Google Cloud Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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