Closed hayhv closed 1 year ago
It might be better to simply add the ability to supply a hook function that can be used to adjust the metadata returned from the database. You could then provide a simple function that simply converts the name to lowercase. Others may, however, wish to use CamelCase or something else.
Another option is to supply a function that is called for each row. This function would accept the metadata and the row that is being returned (as an array). It could then be transformed into an object with the desired names. This function is currently internal but it would not take too much effort to make this an external function.
@cjbj will add this to the list of desirable features I'm sure and may have his own ideas of which approach is going to work best. If others see this and have opinions, please chime in!
I review code on njsRessultset.c file and i think we need write stringlower fuction and call it in this code block ‘‘‘ if (rs->outFormat == NJS_ROWS_OBJECT) { for (col = 0; col < rs->numQueryVars; col++) { var = &rs->queryVars[col]; NJS_CHECK_NAPI(env, napi_create_string_utf8(env, var->name, var->nameLength, &var->jsName)) } } '''
@hayhv Did you check if it can be done more easily in the JS layer? What about the hook idea? If you plan on contributing a PR, please check https://github.com/oracle/node-oracledb/blob/master/CONTRIBUTING.md first.
Changing column metadata can be done in a node-oracledb 6.0 output type handler. For example:
const result = await connection.execute(
`SELECT 1 AS col1, 2 AS COL2 FROM dual`,
[],
{
fetchTypeHandler: function(metaData) {
// Tells the database to return column names in lowercase
metaData.name = metaData.name.toLowerCase();
}
}
);
console.dir(result.rows, {depth: null});