cron tracks month
This commit is contained in:
74
config/dbConnCron.js
Normal file
74
config/dbConnCron.js
Normal file
@ -0,0 +1,74 @@
|
||||
const mysql = require("mysql2")
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.DBHOST,
|
||||
port: process.env.DBPORT,
|
||||
user: process.env.DBUSER,
|
||||
password: process.env.DBPASSWORD,
|
||||
database: process.env.DATABASE,
|
||||
connectionLimit: 100,
|
||||
multipleStatements: true,
|
||||
// waitForConnections: true,
|
||||
maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`
|
||||
idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000
|
||||
queueLimit: 50,
|
||||
// enableKeepAlive: true,
|
||||
// keepAliveInitialDelay: 0,
|
||||
})
|
||||
|
||||
const connection = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
pool.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
// Log the error and reject the promise
|
||||
console.error("Error getting connection from pool:", err)
|
||||
return reject(err)
|
||||
}
|
||||
const query = (sql, binding) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.query(sql, binding, (err, result) => {
|
||||
if (err) {
|
||||
// Log the query error for debugging
|
||||
console.error("Error executing query:", err, { sql, binding })
|
||||
return reject(err)
|
||||
}
|
||||
resolve(result)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const release = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (err) {
|
||||
// Log error in release method if exists
|
||||
console.error("Error during connection release:", err)
|
||||
return reject(err)
|
||||
}
|
||||
resolve(connection.release())
|
||||
})
|
||||
}
|
||||
|
||||
resolve({
|
||||
query,
|
||||
release,
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const query = (sql, binding) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
pool.query(sql, binding, (err, result, fields) => {
|
||||
if (err) {
|
||||
// Log the error for debugging
|
||||
console.error("Error executing pooled query:", err, { sql, binding })
|
||||
return reject(err)
|
||||
}
|
||||
resolve(result)
|
||||
})
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
pool,
|
||||
connection,
|
||||
query,
|
||||
}
|
||||
Reference in New Issue
Block a user