Created
December 19, 2016 02:55
-
-
Save mooyoul/cca40f678d06be500be8abcacb906d1c 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
// below line equal as | |
// const Promise = require('bluebird'); | |
// const getConnection = Promise.promisify(pool.getConnection.bind(pool)); | |
const getConnection = () => { | |
return new Promise((resolve, reject) => { | |
pool.getConnection((e, connection) => { | |
if (e) { return reject(e); } | |
resolve(connection); | |
}); | |
}); | |
} | |
const query = (conn, ...args) => { | |
return new Promise((resolve, reject) => { | |
conn.query(...args, (e, result) => { | |
if (e) { return reject(e); } | |
resolve(result); | |
}); | |
}); | |
}; | |
co(function* () { | |
const mb_no = 1; // @note this is fake value | |
const connection = yield getConnection(); | |
const memberData = yield query(connection, 'select * from member where mb_no = ?', [mb_no]); | |
conn.release(); | |
if (!memberData) { | |
// @todo handle empty results | |
return console.error('empty results'); | |
} | |
// do stuffs... | |
}).catch((e) => { | |
console.error(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment