knd-db

1.0.5 • Public • Published

Description

Library created to help connect to the Oracle database

Installation

npm i knd-db --save

Usage

const getConnection = require('knd-db')

const sql = `
    SELECT VALUES
      FROM TABLE_NAME
     WHERE COLUMN_NAME = :PARAM_A
       AND COLUMN_NAME_2 = :PARAM_B
`

const binds = {
    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 value


const test = async () => {
    
    const connection = await getConnection()

    try {

        const result = await connection.execute( sql, connection.createOracleBinds(binds) )
        // result.rows = array[{...},{...},...]
        // await connection.commit()  --> use for transactions actions

    } catch (error) {
        
        // await connection.rollback()  --> use for transactions actions
        throw new Error(error)  

    } finally {

        await connection.close()

    }

}
// built-in function to search the next sequence value by name
    let id = await con.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

POOL_MAX=maximum number of connection instances

Readme

Keywords

none

Package Sidebar

Install

npm i knd-db

Weekly Downloads

0

Version

1.0.5

License

ISC

Unpacked Size

6.35 kB

Total Files

11

Last publish

Collaborators

  • knd_desenv