Closed DanielF93Dev closed 5 years ago
Please see the Upgrading from V3 section in the readme: https://github.com/lukeb-uk/node-promise-mysql#upgrading-from-v3
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
})
@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
}
}
}
@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();
});
nothing error always
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;
pool.getConnection is not a function
@Leonardorossato mysql.createPool
now returns a promise.
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 !