javascript - NodeJS mysql2 Bluebird? -


been testing mysql vs mysql2, seems 2 has made improvments it's not exact drop in replacement. @ same time q library seems easier integrate bluebird seems take less memory , run faster so...

my current mysql-bluebird connector follows , allows straight forward use of query('select email users.users id=?',id).then(function(res){var email=res[0][0];});

/* global module, require */ var conf=require('./conf.js').conf; var mysql = require('mysql'); var promise = require('bluebird'); var using = promise.using; promise.promisifyall(require('mysql/lib/connection').prototype); promise.promisifyall(require('mysql/lib/pool').prototype);  var pool = mysql.createpool(conf.mysql);  var getconnection = function () {  return pool.getconnectionasync().disposer(function (connection) {  return connection.release();  }); }; var query = function (command) {  return using(getconnection(), function (connection) {  return connection.queryasync(command);  }); }; function querywrapper(q,a){   if(a){     return query(mysql.format(q,a));   }   else{     return query(mysql.format(q));   } } module.exports = {  query: querywrapper }; 

so far attempts ad doing mysql2 haven't panned out.

does have insights on how convert this? thanks, jegsar

you can use mysql2-promise. it's simple wrapper, using q, promisifies mysql2. if you'd rather use bluebird, can @ how wrapper created , yourself.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -