@condor-labs/knex-oracle

This module provide and usefull helper to connect ORACLE using KNEX library.

Usage no npm install needed!

<script type="module">
  import condorLabsKnexOracle from 'https://cdn.skypack.dev/@condor-labs/knex-oracle';
</script>

README

This module provide and usefull helper to connect ORACLE using KNEX library.

See official documentation here.

Compatibility

  • The minimum supported version of Node.js is v8.
  • Since the version 2.0.1, we are supporting node v.12 with oracledb5.1.0

How to use it

To use the library you just need to follow the following steps Install the library with npm

npm install @condor-labs/knex-oracle

Import the library:

const knexOracle = require('@condor-labs/knex-oracle')(settings);

settings object properties

Property Default Description
user (String) The username for authentication. This option is mongoose-specific, they are equivalent to the MongoDB driver's auth.username options.
password (String) The password for authentication. This option is mongoose-specific, they are equivalent to the MongoDB driver's auth.password options.
connectionString (String) Specifies the connection string to connect to the Oracle database
options (Object) Additional settings or properties used to initialize the knex connection, more information.

Examples

Create testing package in ORACLE

constants.js

module.exports = {
    settings: {
        user: 'my_user',
        password: 'my_pass',
        connectionString: '10.111.222.333:1521/MY_ORACLE_DATABASE',
        options: {
            acquireConnectionTimeout: 10000,
            pool: { min: 0, max: 10 }
        }
    },
    executeStatement: {
        statement: `
            declare
                pparam1 varchar2(10) := :param1;
                pparam2 varchar2(10) := :param2;
            begin
                open :creturn_1 for select 'TEST OK 1!!!' as "result1", pparam1 as "param 11", pparam2 as "param 21" from dual;
                open :creturn_2 for select 'TEST OK 2!!!' as "result2", pparam1 as "param 12", pparam2 as "param 22" from dual;
                open :creturn_3 for select 'TEST OK 3!!!' as "result3", pparam1 as "param 13", pparam2 as "param 23" from dual;
            end;
        `,
        params: { param1: "abc", param2: '123' },
        cursorTypeParams: ['creturn_1', 'creturn_2', 'creturn_3']
    },
    executeFunction: {
        name: 'pkg_test_knex_oracle.fnc_calculator',
        params: { pcd_operator: '+', pam_value1: 10, pam_value2: 5 }
    },
    executeProcedure: {
        name: 'pkg_test_knex_oracle.proc_count_until_value_plus_5',
        params: { pam_start_value: 1000 },
        cursorTypeParams: ['pcursor_return'],
        outputParams: ['pam_value_out_1', 'pam_value_out_2']
    }
};

index.js

let {
    settings,
    executeStatement,
    executeFunction,
    executeProcedure
} = require('./constants');

try {
    (async () => {
        // init knex-oracle connection
        const knexOracle = require('@condor-labs/knex-oracle')(settings);

        //---------------------------------------------------
        // prepare query statement (EXECUTE STATEMENT)
        //---------------------------------------------------

        let ret = {};
        try {
            ret = await (knexOracle.getClient()).executeStatement(
                executeStatement.statement,
                executeStatement.params,
                executeStatement.cursorTypeParams
            );
        }
        catch (error) {
            ret = {
                code: error.code,
                message: error.message,
                stack: error.stack
            }
        }
        // print response
        console.log('EXECUTE STATEMENT Result:', ret);

        //---------------------------------------------------
        // prepare query statement (EXECUTE FUNCTION)
        //---------------------------------------------------

        try {
            ret = await (knexOracle.getClient()).executeFunction(
                executeFunction.name,
                executeFunction.params
            );
        }
        catch (error) {
            ret = {
                code: error.code,
                message: error.message,
                stack: error.stack
            }
        }
        // print response
        console.log('EXECUTE FUNCTION Result:', ret);

        //---------------------------------------------------
        // prepare query statement (EXECUTE PROCEDURE)
        //---------------------------------------------------

        try {
            ret = await (knexOracle.getClient()).executeProcedure(
                executeProcedure.name,
                executeProcedure.params,
                executeProcedure.cursorTypeParams,
                executeProcedure.outputParams
            );
        }
        catch (error) {
            ret = {
                code: error.code,
                message: error.message,
                stack: error.stack
            }
        }
        // print response
        console.log('EXECUTE PROCEDURE Result:', ret);

        process.exit(1);
    })();
} catch (error) {
    console.error(error)
}

How to Publish

Increasing package version

You will need to update the package.json file placed in the root folder.

identify the property version and increase the right number in plus one.

Login in NPM by console.

 npm login
 [Enter username]
 [Enter password]
 [Enter email]

If all is ok the console will show you something like this : Logged in as USERNAME on https://registry.npmjs.org/.

Uploading a new version

 npm publish --access public

Ref: https://docs.npmjs.com/getting-started/publishing-npm-packages

Note: you will need to have a NPM account, if you don't have one create one here: https://www.npmjs.com/signup

Contributors

The original author and current lead maintainer of this module is the @condor-labs development team.

More about Condorlabs Here.

License

MIT