Hướng dẫn nodejs pool - hồ bơi nodejs

Tôi muốn sử dụng gộp kết nối bằng NodeJS với cơ sở dữ liệu MySQL. Theo tài liệu, có hai cách để làm điều đó: hoặc tôi rõ ràng nhận được kết nối từ nhóm, sử dụng nó và phát hành nó:

Nội dung chính

  • Bình luận
  • Làm thế nào để bạn đóng một hồ bơi trong nút js?
  • Làm cách nào để đóng kết nối nút trong MySQL?
  • Tại sao MySQL kết nối gần?
  • Làm thế nào để bạn đóng cơ sở dữ liệu MySQL?

var pool = require('mysql').createPool(opts);

pool.getConnection(function(err, conn) {
    conn.query('select 1+1', function(err, res) {
        conn.release();
    });
});

Hoặc tôi có thể sử dụng nó như thế này:

var mysql = require('mysql');
var pool  = mysql.createPool({opts});

pool.query('select 1+1', function(err, rows, fields) {
  if (err) throw err;

  console.log('The solution is: ', rows[0].solution);
});

Nếu tôi sử dụng các tùy chọn thứ hai, điều đó có nghĩa là, các kết nối đó được tự động rút ra khỏi nhóm, được sử dụng và phát hành? Và nếu vậy, có lý do để sử dụng phương pháp đầu tiên không?

Vấn đề mới

Có một câu hỏi về dự án này? Đăng ký một tài khoản GitHub miễn phí để mở một vấn đề và liên hệ với người bảo trì và cộng đồng của nó. Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Bằng cách nhấp vào Đăng ký đăng ký cho GitHub, bạn đồng ý với Điều khoản dịch vụ và tuyên bố quyền riêng tư của chúng tôi. Chúng tôi thỉnh thoảng gửi cho bạn các email liên quan đến tài khoản.

Đã có trên Github? đăng nhập vào tài khoản của bạn

Đóng

Aminadav đã mở vấn đề này

24 tháng 4 năm 2016

· 5 bình luận

Người được giao

Bình luận

Hướng dẫn nodejs pool - hồ bơi nodejs

Làm thế nào để bạn đóng một hồ bơi trong nút js?
If not, where should I add this functionality in the source ccode?

Làm cách nào để đóng kết nối nút trong MySQL?
For example:

var pool=db.createPool({})
for(var i=1;i<100;i++)
pool.query()

// Now I want to close all the connection of the pool

Tại sao MySQL kết nối gần?

var pool=db.createPool({})
for(var i=1;i<100;i++)
pool.query()

// Now I want to close all the connection of the pool
pool.end()

Hello,

Làm thế nào để bạn đóng cơ sở dữ liệu MySQL?

Hoặc tôi có thể sử dụng nó như thế này:
S

Nếu tôi sử dụng các tùy chọn thứ hai, điều đó có nghĩa là, các kết nối đó được tự động rút ra khỏi nhóm, được sử dụng và phát hành? Và nếu vậy, có lý do để sử dụng phương pháp đầu tiên không?

		_shouldWeStopChild() {
			return new Promise((resolve, reject) => {
				setInterval(() => {
					// Ensure all queries has been executed before exiting the script
					let connectionQueue = this.Database.getCurrentConnection()._connectionQueue.length;
					if(connectionQueue == 0) {
						clearInterval(this._shouldWeStopChild);
						debug('All queries has been completed.');
						resolve();
					} else {
						debug('There are ' + connectionQueue + ' queries left');
					}
				}, 50);
			});
		}

Làm thế nào để bạn đóng một hồ bơi trong nút js?

Làm cách nào để đóng kết nối nút trong MySQL?explicitly get connection from the pool, use it and release it: var pool = require('mysql'). createPool(opts); pool. getConnection(function(err, conn) { conn.

Làm cách nào để đóng kết nối nút trong MySQL?

Tại sao MySQL kết nối gần?call the end() method on the connection object. The end() method ensures that all remaining queries are always executed before the database connection closed. To force the connection close immediately, you can use the destroy() method.

Tại sao MySQL kết nối gần?

Làm thế nào để bạn đóng cơ sở dữ liệu MySQL?the server timed out and closed the connection. By default, the server closes the connection after 8 hours if nothing has happened. You can change the time limit by setting the wait_timeout variable when you start mysqld.

Làm thế nào để bạn đóng cơ sở dữ liệu MySQL?

Hoặc tôi có thể sử dụng nó như thế này:close() / mysqli_close() function closes a previously opened database connection.