mysql-query-params
v2.4.5
Published
``` Import your MySQL installation package let mysql = require('mysql') ``` ``` let connection = mysql.createConnection({ host: 'localhost', // Your connected database server port: '3306', // Your port number user: 'root', // Your user
Downloads
2
Readme
Import your MySQL installation package
let mysql = require('mysql')
Createconnection establish connection & close connection
Connection pool is a very important concept when developing web applications. The performance cost of establishing a database connection is very high. In a server application, if one or more database connections are established for each received client request, the performance of the application will be seriously degraded.
Therefore, in the server application, it is usually necessary to create and maintain a connection pool for multiple database connections. When the connections are no longer needed, these connections can be cached in the connection pool. When the next client request is received, the connections will be taken out of the connection pool and reused without re establishing the connection
let connection = mysql.createConnection({
host: 'localhost', // Your connected database server
port: '3306', // Your port number
user: 'root', // Your username
password: '', // Your password
database: '' // Your database name
})
nodejs- TypeError: connection.connect is not a function I have an app developed using ExpressJS (Express 4) framework. I am planning to use connection pooling instead of single connection, heard it allows us to reuse existing database connections instead of opening a new connection for every request to the Node application.
So in the existing code, I made a change. Replaced mysql.createConnection with mysql.createPool in the following code Note: This is just a portion of the app where the database connection is getting established.
connection.connect(err => {
if (err) {
console.log(err)
return
} else {
console.log('Service ok')
}
})
In the project, the data returned in connection.query needs to be processed circularly, but it is found that after the circular processing is used
let query = (sql) => {
return new Promise((resolve, reject) => {
connection.query(sql, (err, results) => {
if (err) {
reject(err)
return
}
resolve(results)
})
})
}