easy-oracledb
A simple way to connect in oracle database and execute querys. This module uses node-oracledb v3.1.2.
Oracle instant client available here.
If you have any question or issue, feel free to ask.
Table of content
Installation
via npm:
npm i -S easy-oracledb
Usage
const db =
Functions
config(dbConfig)
-
{string} dbConfig - an object javascript {user, pass, conn}
-
{string} user - db username
-
{string} pass - db password
-
{string} conn - db connection string hots:port/dbname
First step configure database connection:
db
testConnection()
asynchronous function
Connection can be tested:
await db
returns true if successfully connected or error message.
readSQL(file)
Read an existing .sql file as string
- {string} file - path to file
let sql = db
getData(sql, params)
asynchronous function
Used only for select statements.
-
{string} sql - a sql string
-
{array} params - an array of parameters (optional)
await db
Result:
[ , ]
exec(sql, params)
asynchronous function
Used to insert, update and delete statements.
-
{string} sql - a sql string
-
{array} params - an array of parameters (optional)
await db
Returns number of rows affected:
1
Examples
Configure and test connection
const db = db { await db }
Get customers
{ let sql = await db await db }
Get customers by registration date
{ // SELECT COD, NAME, EMAIL FROM CUSTOMERS WHERE REG_DATE BETWEEN :DATE1 AND DATE2' let sql = await db let param = '02/08/2019' '06/08/2019' await db }
Insert customer
{ // 'INSERT INTO CUSTOMERS(COD, NAME, EMAIL, REG_DATE) // VALUES (:COD, :NAME, :EMAIL, :REG_DATE)' let sql = await db let params = '1' 'John' 'john@domain.com' '08/07/2019' await db }
Changelog
see the update notes at CHANGELOG.
Copyright ® 2019 Victor Gianvechio