我们可以在 node-oracledb 中记录一个具有绑定参数的 SQL 查询吗?

Can we log a SQL query having bind parameters in node-oracledb?

const query = `INSERT INTO countries VALUES (:country_id, :country_name)`;
try {
    const result = await connection.execute(query, { country_id: 90, country_name: "Tonga" });
} catch (error) {
    console.error(`error while executing: ${query}`);
}

有什么方法可以记录 query 以及绑定参数数据
这样我就可以记录 INSERT INTO countries VALUES (90, "Tonga")

我认为目前没有内置选项可以做到这一点,但根据文档,您可以围绕 execute 函数创建一个包装器并在其中记录实际查询。来自 docs:

Sometimes it is useful to trace the bind data values that have been used when executing statements. Several methods are available.

In the Oracle Database, the view V$SQL_BIND_CAPTURE can capture bind information. Tracing with Oracle Database’s DBMS_MONITOR.SESSION_TRACE_ENABLE() may also be useful.

You can also write your own wrapper around execute() and log any parameters.

最终,我找到了一个名为 bind-sql-string 的软件包,它具有 queryBindToString 方法来解决我的问题。