javascriptnode.jsdatabaseoracle-databasenode-oracledb

Debugging fetchTypeHandler in nodejs Oracle library


I am using Oracle nodejs version 4.2.0 and trying to use a custom fetchTypeHandler as described in documentation https://node-oracledb.readthedocs.io/en/latest/api_manual/connection.html#propexecfetchtypehandler

However I don't see the expected result (numbers to fixed precision in the response) and uf I set the breakpoint inside fetchTypeHandler it never encounters it, so I believe the function set at fetchTypeHandler key in the opt object is not being executed at all.

    const opts={
        fetchAsString : [ oracledb.CLOB ],
        fetchTypeHandler: function(metaData) {
            console.log(metaData);
            if (metaData.dbType == oracledb.DB_TYPE_NUMBER) {
                const converter = (v) => {
                    if (v !== null)
                        v = parseFloat(v).toFixed(2);
                    return v;
                };
                return {type: oracledb.DB_TYPE_VARCHAR, converter: converter};
            }
        },
        outFormat : oracledb.OBJECT,
        autoCommit : true
    };

I am sure I am using the options as all the other but fetchTypeHandler seem to apply, but just for the sake of it, I execute statements as:

conn.execute(statement, [],opts)

Solution

  • As noted in that doc, fetch type handlers were "New in version 6.0." You will need to upgrade from 4.2.

    Also see the node-oracledb 6.0 release announcement.