Skip to content

Instantly share code, notes, and snippets.

@gabidavila

gabidavila/xdevapi4.js

Last active Jul 18, 2018
Embed
What would you like to do?
/**
* 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
You can’t perform that action at this time.