Library created to help connect to the Oracle database
Installation
npm i knd-db --save
Usage
constgetConnection=require('knd-db')constsql=` SELECT VALUES FROM TABLE_NAME WHERE COLUMN_NAME = :PARAM_A AND COLUMN_NAME_2 = :PARAM_B`constbinds={PARAM_A: {val:'YOUR_VALUE',dir:'IN'},PARAM_B: {val:'YOUR_VALUE',dir:'IN'}}// Bind default direction is 'IN', most values 'OUT' or 'INOUT'// Possible pass bind value PARAM_A: 'YOUR_VALUE', when using direction with default valueconsttest=async()=>{constconnection=awaitgetConnection()try{constresult=awaitconnection.execute(sql,connection.createOracleBinds(binds))// result.rows = array[{...},{...},...]// await connection.commit() --> use for transactions actions}catch(error){// await connection.rollback() --> use for transactions actionsthrownewError(error)}finally{awaitconnection.close()}}
// built-in function to search the next sequence value by nameletid=awaitcon.nextSequenceId('SEQUENCE_NAME')
Configuration
the settings are fetched from the node environment variables, just set the following in the .env file:
USER=database user
PASSWORD=database password
CONNECTION_STRING=database connection string
optional
POOL_CONNECTION=true if you want to use a connection pool, otherwise you don't need to pass this parameter or the next one