0
Just use column aliases:
只需使用列別名:
const oracledb = require('oracledb');
const config = require('./dbConfig.js');
(async function() {
let conn;
let result;
try {
conn = await oracledb.getConnection(config);
result = await conn.execute(
`select first_name || ' ' || last_name name,
from employees
where rownum = 1`,
[], // no binds
{
outFormat: oracledb.OBJECT
}
);
// This is the problem, uppercase column names, no?
console.log(result.rows); // [ { NAME: 'Steven King', EMAIL: 'SKING' } ]
result = await conn.execute(
`select first_name || ' ' || last_name "name",
email "email"
from employees
where rownum = 1`,
[], // no binds
{
outFormat: oracledb.OBJECT
}
);
// Here's the result with case sensitve aliases
console.log(result.rows); // [ { name: 'Steven King', email: 'SKING' } ]
} catch (err) {
// Will throw, but only after finally runs
throw err;
} finally {
if (conn) {
try {
await conn.close();
} catch (err) {
console.log('error closing conn', err);
}
}
}
}());
Or "process" the results after. You might find this relevant: https://jsao.io/2015/07/relational-to-json-with-node-js/
或者“處理”之后的結果。您可能會發現這相關:https://jsao.io/2015/07/relational-to-json-with-node-js/