sidorares / node-mysql2

:zap: fast mysqljs/mysql compatible mysql driver for node.js
https://sidorares.github.io/node-mysql2/
MIT License
4.04k stars 610 forks source link

[Docs] Pool execute or query is automatically create and release a connection #745

Open mems opened 6 years ago

mems commented 6 years ago

The docs should mention that methods of connection pool execute() and query() internally create and release a connection each time it called:

await = pool.execute(query);

is same as

const conn = await pool.getConnection();
await conn.execute(query);
conn.release();
sidorares commented 6 years ago

yes, what's your question @mems ?

mems commented 6 years ago

Just to add that clarification in docs

sidorares commented 6 years ago

agreed, just had a look at /documentation/Promise-Wrapper.md and we should probably have good detailed api documentation there and not just couple of brief examples

soorajvnair commented 6 years ago

Yes this is important, because i've seen people manually accquire and release connection when working with query and execute, which is not necessary as @mems has highlighted.

anthgur commented 6 years ago

I agree with this. I went from using execute (implicit connection) to using transactions (user managed connection) and I got bit by a pool deadlock.

frenzymind commented 5 years ago

what bout if I use 'mysql2/promise' ? connection = await mysql.createConnection({ ... }) const [rows] = await connection.execute( ... ) Should I call connection.end() after ?

sidorares commented 5 years ago

Should I call connection.end() after ?

@frenzymind depends on your use case, but at some point before you exit from your app you need to close connection.