2.4.5 • Published 3 years ago

mysql-query-params v2.4.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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)

        })
    })
}
Use the ES6 method to throw your query

Koa context encapsulates the request and response objects of node into a single object, providing many useful methods for writing web applications and APIs. These operations are frequently used in HTTP server development, and they are added to this level rather than a higher level framework, which will force the middleware to re implement this common function.

mysql | koa-combine-routers | koa-router

2.4.5

3 years ago

2.1.5

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago