Look at the example code like this;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
It should look like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
I just feel that closing the database connection should be done in the callback of the query. If it is written like the first way and the query is not finished, is it inappropriate to close the database? The internal principle of this mysql module is not very clear;
Hope everyone can clear up the confusion;
高洛峰2017-05-16 13:39:28
Documentation:
Closing the connection is done using end() which makes sure all remaining queries are executed before sending a quit packet to the mysql server.
So, calling end()
不会马上关闭连接,要等剩余的查询执行完才关闭,该触发的回调还是触发。destroy()
will directly close the connection.
The specific implementation is to put all operations into the queue for execution. end()
Just put a Quit operation into the queue, and it is actually closed after the Quit operation is executed.