connection pool
类将返回一个承诺,该承诺与连接启动的池进行解析:
var executeQuery = function(res, query) {
var conn = new sql.ConnectionPool(dbConfig);
conn.connect()
.then(function (pool) {
// ^ the pool that is created and should be used
// create Request object
var request = new sql.Request(pool);
// ^ the pool from the promise
// query to the database
request.query(query, function (err, queryResult) {
if (err) {
console.log("Error while querying database :- " + err);
res.send(err);
} else {
res.send(queryResult);
}
});
conn.close();
});
}
conn
变量始终是承诺,而不是连接本身。
new sql.ConnectionPool(config).connect().then(pool => {
return pool.query`select * from mytable where id = ${value}`
}).then(result => {
console.dir(result)
}).catch(err => {
// ... error checks
})