Created
March 9, 2018 14:30
-
-
Save dabroder/e5a00f2ff5e63a15f27a3f1d776e23dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const { promisify } = require('util') | |
/** | |
* Mysql tools factory | |
* @param {(Connection|Pool|PoolCluster)} db Conection | |
* @returns {Object} | |
*/ | |
module.exports = function tools (db) { | |
const query = promisify(db.query).bind(db) | |
const end = promisify(db.end).bind(db) | |
const q = sql => x => query(sql, x) | |
const first = (sql, x) => query(sql, x).then(r => r && r[0]) | |
const one = sql => x => query(sql, x).then(r => r && r[0]) | |
return { db, end, q, query, first, one } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment