How version ConnectionPool for mssql is better and why? I try understand, both work. I want a correct connection, I don't want create redundant connections.
All the examples I found use .then
and version A, maybe is another better option?
Should I close connection?
version A
// db.js
import sql from "mssql"
const config = {...}
export const mssqlPool = new sql.ConnectionPool(config).connect()
// n endpoint.js
import { mssqlPool } from "../lib/mssql/db"
try {
const pool = await mssqlPool
const result = await pool.request().query(`SELECT * FROM table`)
console.log(result)
} catch (err) {
console.log('error')
}
version B
// db.js
import sql from "mssql"
const config = {...}
export const mssqlPool = new sql.ConnectionPool(config)
// n endpoint.js
import { mssqlPool } from "../lib/mssql/db"
try {
const pool = await mssqlPool.connect();
const result = await pool.request().query(`SELECT * FROM table`)
console.log(result)
} catch (err) {
console.log('error')
}
Edit: answer github