NODE.js和ORACLE,dbObject的问题



我在Node.js 中使用Oracle阵列时遇到问题

function simpleExecute(statement, binds = [], opts = {}) {
return new Promise(async (resolve, reject) => {
let conn;
opts.outFormat = oracledb.OUT_FORMAT_OBJECT;
opts.autoCommit = true;
try {
conn = await oracledb.getConnection();
const result = await conn.execute(statement, binds, opts);
console.log(result);
resolve(result);
} catch (err) {
reject(err);
} finally {
if (conn) {
// conn assignment worked, need to close
try {
await conn.close();
} catch (err) {
console.log(err);
}
}
}
});
}
module.exports.simpleExecute = simpleExecute;

在simpleExecute函数中,一切正常。console.log正确显示数据

{
board_id: 242,
name: 'School at School',
user_name: 'David',
user_url: 'ej',
background_regular: 'red',
background_thumb: 'https://images.unsplash.com/photo-1558981806-ec527fa84c39?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjEyNTU3NX0',
list_order: [USER_TEST.LIST_ORDER] [ 'WMCBQaBQtQ66' ],
important: 0
},

但是当我把答案传回getAll函数时

async function getAll(user) {
user.user_id = parseInt(user.user_id, 10);
const query = `SELECT
BOARD_ID "board_id",
NAME "name",
t.background.user_name "user_name" , 
t.background.user_url "user_url" , 
t.background.background_regular "background_regular" , 
t.background.background_thumb "background_thumb" ,  
t.LIST_ORDER "list_order",
IMPORTANT "important"
from TO_DO_TABLE t
WHERE USER_ID=:user_id`;
const result = await database.simpleExecute(query, user);
console.log(result);
return result.rows;
}

Console.log显示错误

Error: DPI-1010: not connected
at DbObject._toPojo (C:UsersDavidDesktopBD_2020back-endnode_modulesoracledblibdbObject.js:48:19)
at Proxy.[nodejs.util.inspect.custom] (C:UsersDavidDesktopBD_2020back-endnode_modulesoracledblibdbObject.js:63:54)
at formatValue (internal/util/inspect.js:693:31)
at formatProperty (internal/util/inspect.js:1558:11)
at formatRaw (internal/util/inspect.js:933:9)
at formatValue (internal/util/inspect.js:721:10)
at formatProperty (internal/util/inspect.js:1558:11)
at formatArray (internal/util/inspect.js:1380:17)
at formatRaw (internal/util/inspect.js:930:14)
at formatValue (internal/util/inspect.js:721:10)

此Oracle阵列存在问题

list_order: [USER_TEST.LIST_ORDER] [ 'WMCBQaBQtQ66' ]

我不知道发生了什么,为什么我可以在一个功能中显示这个ARRAY,而不能在另一个中显示

编辑:

如果我在执行simpleExecute功能后没有关闭连接,一切都很好,但是否有可能在关闭连接的情况下取出这些数据并将其推高

访问底层对象时,连接必须保持打开状态。如果您正在流式传输LOB,那么它们也是如此。这就是为什么我们不再在node-oracledb API中内置"simpleexecute"函数的原因之一。

最新更新