CodeFoodPixels / node-promise-mysql

A wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
MIT License
338 stars 64 forks source link

pool.getConnection is not a function after latest update #118

Closed DanielF93Dev closed 5 years ago

DanielF93Dev commented 5 years ago

Hello!

my code was working fine until the last update, where I get now pool.getConnection() is not a function, how can I get a connection in the latest version?

Thanks !

CodeFoodPixels commented 5 years ago

Please see the Upgrading from V3 section in the readme: https://github.com/lukeb-uk/node-promise-mysql#upgrading-from-v3

DanielF93Dev commented 5 years ago

Thanks for your reply , I got confused because there was no example, but I manage to change it correctly, for future reference: I used to do

pool.getConnection().then(function(){

 // here the query was executed
})

Now I just changed it to:

pool.then(function(p){

  return  p.getConnection()

}).then(function(){

 // here the query is executed
})
yanqic commented 4 years ago

@WebmasterClickPanda .so can you tell me if it needed to releaseConection at the new version?

function  initMysql (config = {}){
  const pool: any = pmysql.createPool(config)
  const mysql = {
    async excuteQuery(sql: string, value?: any) {
      try {
        let results = await pool.then((p: any) => {
          let connection
          try {
            connection = await p.getConnection()
            let result = await connection.query(sql, value)
            return result
          } catch (error) {
            throw error
          } finally {
            if (connection) {
              pool.releaseConnection(connection) // how can i release the connection ?
            }
          }
        })
        return results
      } catch (error) {
        throw error
      }
    }
  }
DanielF93Dev commented 4 years ago

@yanqi321

I would use in your example connection.release();

here is how I do using promises:

let con = null;
pool.then(function(p){  
return  p.getConnection()    
}).then(function(connection) {
con = connection;
return   con.query('HERE GOES THE QUERY') 
}).then(rows => {
  con.release();  
});
Leonardorossato commented 3 years ago

nothing error always

Leonardorossato commented 3 years ago

const mysql = require('promise-mysql'); const keys = require('./keys');

const pool = mysql.createPool(keys.database);

pool.getConnection().then((connection: any) => { pool.ReleaseConnection(connection) console.log('Connection with database was successfully established') })

export default pool;

Leonardorossato commented 3 years ago

pool.getConnection is not a function

CodeFoodPixels commented 3 years ago

@Leonardorossato mysql.createPool now returns a promise.