Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
co(function *(){
// set up a connection for the database
connection = yield mysql.createConnection({
host: config.db.host,
user: config.db.user,
password: config.db.password,
database: config.db.database
});
// login to redit and get your information
let loginResult = yield reddit('/api/v1/me').get();
console.log(`** : ${loginResult.name} has logged in.`);
//get a listing of all new posts on the front page
let listingResult = yield reddit('/r/borrow/new').listing();
for (let post of listingResult.get.data.children){
let newPost = processPost(post.data);
let user = yield getUser(newPost.poster);
if (newPost.type == "REQ"){
// generate a score for all requested loans
let score = generateScore(newPost, user);
const doDropAllDbTables = async config => {
let errorMessage
const defaultConfig = {
multipleStatements: true,
host: null,
user: null,
password: null,
database: null,
}
// Create the connection to the local database
const conn = await mysql
.createConnection({ ...defaultConfig, ...config })
.catch(error => (errorMessage = error))
if (errorMessage) return new Error(errorMessage)
conn.query(dropDbQuery)
conn.end()
}
private init() {
mysql
.createConnection({
host: this.config.mysql.host,
port: this.config.mysql.port,
user: this.config.mysql.user,
password: this.config.mysql.password,
database: "leadcoin",
})
.then(conn => {
return conn.end()
})
.catch(err => {
if (this.config.env != "test") {
console.log("Failed to connect to mysql:", err.message)
}
setTimeout(this.init, 2000)
})
promiseWhile(function(){ if(connectionAttempts>10){ throw new Error ( "Cannot connect after 10 attempts" ) }; connectionAttempts++; return !connection},function(){
console.log(statusMsg('Connecting to MySQL... ',(connectionAttempts>1?'(attempt '+connectionAttempts+')':'') ) );
return mysql.createConnection({
host : dbhost,
port : dbport,
user : dbuser,
password : dbpassword,
database : dbname
}).then(function(conn){
connection = conn;
}).catch(function(err){
console.error(err);
});
})
.then(function(){
return new Promise(function(resolve, reject) {
console.log('Connecting to MySQL database');
var mysql = require('promise-mysql');
var connection;
mysql.createConnection({
host: params.MYSQL_HOSTNAME,
port: params.MYSQL_PORT,
user: params.MYSQL_USERNAME,
password: params.MYSQL_PASSWORD,
database: params.MYSQL_DATABASE
}).then(function(conn) {
connection = conn;
console.log('Querying');
var queryText = 'DELETE FROM cats WHERE id=?';
var result = connection.query(queryText, [params.id]);
connection.end();
return result;
}).then(function(result) {
console.log(result);
resolve({
statusCode: 200,
static Connect() {
return mysql.createConnection({
host: 'localhost',
user: 'root',
password: config.mySql.password,
database: 'discord'
});
}
static CreateTable(tableName) {
function createConnection(){
return mysql.createConnection({
host: exports.config.db.host,
user: exports.config.db.user,
password: exports.config.db.password,
database: exports.config.db.database
});
}
module.exports.modifyAccount = function* modifyAccount(account){
const connection = yield mysql.createConnection({
host: config.db.host,
user: config.db.user,
password: config.db.password,
database: config.db.database
});
let results = yield connection.query("UPDATE accounts SET ? WHERE id = ?;", [account, account.id]);
return results;
};