gupshup-mysql-demodb
v1.0.8
Published
Demo mysql npm module
Downloads
6
Readme
Run Locally
Set below environment variables for connecting mysql.
GUPSHUP_DB_CONNECTION_URL="00.224.114.86"
GUPSHUP_DB_USERNAME="root"
GUPSHUP_DB_PASSWORD="password"
GUPSHUP_DB_DATABASE="DATABASE_NAME"
For Journey builder, you can setup above mentioned variables as a local/global variable and pass it to initializeMysql method.
Database Connection Code and Query Execution
Sample code for fetching user records
//Self executing function for journey codeNode. Which allows user to execute async code.
(async () => {
try{
/************************************************************/
/**********************SET ENV VARIABLES*********************/
/************************************************************/
const HOST = process.env.GUPSHUP_DB_CONNECTION_URL;
const USERNAME = process.env.GUPSHUP_DB_USERNAME;
const PASSWORD = process.env.GUPSHUP_DB_PASSWORD;
const DATABASE = process.env.GUPSHUP_DB_DATABASE;
/************************************************************/
const GupshupDB = require(`gupshup-mysql-demodb`).mysql;
GupshupDB.initializeMysql( HOST, USERNAME, PASSWORD, DATABASE );
const userId = 1;
const name = "John Wick";
let insert = await GupshupDB.addUser( userId, name ); // Record will get added to table
let select1 = await GupshupDB.getSingleUser( userId ); // Fetch single record
let selectAll = await GupshupDB.getAllUsers(); // Fetch all records
let deleteUser = await GupshupDB.deleteUser( userId ); // Delete specific record
} catch (e) {
console.log(e);
}
})()