oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.26k stars 1.07k forks source link

add option allow lowercase name of fields and metaData #1449

Closed hayhv closed 1 year ago

hayhv commented 2 years ago
  1. Describe your new request in detail this current version away upper field name we need support option allow lowercase of field name on query because it is easy for developer typing code
  2. Give supporting information about tools and operating systems. Give relevant product version numbers
anthony-tuininga commented 2 years 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!

hayhv commented 2 years ago

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​)) ​        } ​    } '''

cjbj commented 2 years ago

@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.

cjbj commented 1 year ago

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});