Last active
July 18, 2018 19:28
-
-
Save gabidavila/5a975ae84b08edc9a6d523a9cc1a65d7 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Responds to any HTTP request that can provide a "message" field in the body. | |
* | |
* @param {!Object} req Cloud Function request context. | |
* @param {!Object} res Cloud Function response context. | |
*/ | |
const options = { | |
host: "your ip address", | |
port: 33060, | |
password: "your password", | |
user: "your username" | |
}; | |
const mysqlx = require('@mysql/xdevapi'); | |
exports.getTeam = (req, res) => { | |
console.log(req.query) | |
if (req.query.name === undefined) { | |
res.status(400).send('No name defined!'); | |
} else { | |
const name = req.query.name; | |
/** your code goes here **/ | |
mysqlx.getSession(options) | |
.then((session) => { | |
const db = session.getSchema("worldcup"); | |
let teamsCollection = db.getCollection("teams_2018"); | |
return teamsCollection.find("name = :country") | |
.limit(1) | |
.bind("country", req.query.name) | |
.execute(row => { | |
res.status(200).send(row); | |
}) | |
}) | |
.catch(err => { | |
console.log(err.stack); | |
process.exit(1); | |
}) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment