Javascript 如何将HTTP请求映射或关联到Node.js中的db调用?

Javascript 如何将HTTP请求映射或关联到Node.js中的db调用?,javascript,node.js,http,v8,Javascript,Node.js,Http,V8,我有一个带有MySQL数据库的节点应用程序。我想将每个HTTP请求关联或映射到MySQL db调用。 i、 需求是以某种方式将HTTP请求标识传递给后续的异步db调用(下一个异步调用完全在新上下文中) 请给我一些建议。经过大量研究,我发现在node.jsasync_hooks模块中提供了一个API,用于注册回调,跟踪node.js应用程序中创建的异步资源的生命周期 const async_hooks = require('async_hooks'); const eid = async_hook

我有一个带有MySQL数据库的节点应用程序。我想将每个HTTP请求关联或映射到MySQL db调用。 i、 需求是以某种方式将HTTP请求标识传递给后续的异步db调用(下一个异步调用完全在新上下文中)


请给我一些建议。

经过大量研究,我发现在node.jsasync_hooks模块中提供了一个API,用于注册回调,跟踪node.js应用程序中创建的异步资源的生命周期

const async_hooks = require('async_hooks');
const eid = async_hooks.executionAsyncId(); // Return the ID of the current execution context.
const tid = async_hooks.triggerAsyncId(); // Return the ID of the handle responsible for triggering the callback of the current execution scope to call.

表示您需要在http请求调用中访问db?@SasiKumarM,不,您错了。我想将http请求与mysql db callI关联。我面临类似的问题。你想将每个http请求存储在数据库中吗?@OscarR,不,我想知道http请求与db调用的关联。例如如果有1000个http请求导致1000个db调用,那么我想将每个请求唯一地映射到其各自的调用。所以我想要一个Id,它存在于http请求中,并在其生命周期内执行。