gpt4 book ai didi

node.js - Azure Functions + Azure SQL + Node.js 和请求之间的连接池?

转载 作者:太空宇宙 更新时间:2023-11-03 23:02:44 24 4
gpt4 key购买 nike

我想知道 - 有没有办法在 Azure Functions (Node.js) 请求之间建立 Azure SQL 连接池?

创建连接占我的请求运行总时间的很大一部分,我想知道如何改进它。

繁琐的网站上的所有示例http://tediousjs.github.io/tedious/getting-started.html打开一个新连接,同时 tedious-connection-pool https://github.com/tediousjs/tedious-connection-pool据我所知,它是为单个请求的生命周期而不是在请求之间使用单个连接池而设计的。

如有任何建议,我们将不胜感激!

最佳答案

我会选择乏味的连接池路线 - 它设计用于在请求之间使用。

在函数范围之外创建连接池:

// created only on first invocation
let pool = new ConnectionPool(poolConfig, connectionConfig);

module.exports = function(context, trigger) {
// runs on every invocation, acquiring a connection from the pool
pool.acquire((err, connection) => {
...
});
}

关于node.js - Azure Functions + Azure SQL + Node.js 和请求之间的连接池?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43234272/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com