Skip to content

Instantly share code, notes, and snippets.

@olehcambel
Last active January 12, 2019 20:22
Show Gist options
  • Save olehcambel/b6aed76e6749e6df978fb41386c1fd68 to your computer and use it in GitHub Desktop.
Save olehcambel/b6aed76e6749e6df978fb41386c1fd68 to your computer and use it in GitHub Desktop.
const mysql = require('mysql')
const pool = mysql.createConnection({
host: config.db.host,
user: config.db.user,
password: config.db.password,
database: config.db.database,
});
class DB {
static query(sql, values, options) {
// ...
}
}
DB.pool = pool;
module.exports = DB;
const DB = require('./db.js')
const getInfo = async(param1, param2) => {
const sql = `
SELECT *
FROM ??
LEFT JOIN ?? USING(??)
WHERE ?? = ?`
const args = ['table1', 'table2', 'name', 'id', param1]
return DB.query(sql, args)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment