Guest User

Untitled

a guest
Mar 28th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. var pool = mysql.createPool({
  2. host: databaseHost,
  3. user: databaseUser,
  4. password: databasePassword,
  5. database: databaseName,
  6. multipleStatements: true
  7. });
  8.  
  9. pool.getConnection(function (err, connection) {
  10. if (err) {
  11. callback(err);
  12. } else {
  13. // Use the connection
  14.  
  15. var sql = "...sql statement...";
  16. var inserts = [...inserts...];
  17.  
  18. connection.query(sql, inserts, function (error, results, fields) {
  19.  
  20. // And done with the connection.
  21. connection.release();
  22.  
  23. // Handle error after the release.
  24. if (error) {
  25. callback(error);
  26. } else {
  27. callback(null, results);
  28. }
  29. });
  30. }
  31. });
  32.  
  33. "ER_CON_COUNT_ERROR: Too many connections"
  34.  
  35. console.log(pool.config.connectionLimit); // passed in max size of the pool
  36. console.log(pool._freeConnections.length); // number of free connections awaiting use
  37. console.log(pool._allConnections.length); // number of connections currently created, including ones in use
  38. console.log(pool._acquiringConnections.length); // number of connections in the process of being acquired
  39.  
  40. 10
  41. 0
  42. 0
  43. 0
Add Comment
Please, Sign In to add comment