1.0.9 • Published 4 years ago

dbasefy-oracle v1.0.9

Weekly downloads
5
License
ISC
Repository
github
Last release
4 years ago

DBasefy Oracle (Beta)

npm i dbasefy-oracle -S

Encapsulates complexity from oracledb library. Its used along with dbasefy

import { OracleConnection } from 'dbasefy-oracle/lib'

async function sample(): Promise<void> {
    const conn = await new OracleConnection().open()
    const trx = conn.createTransaction()

    try {

        const query = conn.createQuery('SELECT * FROM DUAL')
        const rows = await query.execute()
        console.log(rows) // [OracleData { DUMMY: 'X'}]

        const sql = 'INSERT INTO TABLE_X (ID, VALUE) VALUES (:ID, :VALUE)'
        const cmd = conn.createCommand(sql, { ID: 1, VALUE: 'TEST' })
        await cmd.execute()
        await trx.commit()

    } catch (err) {

        await trx.rollback()
        throw err

    } finally {
        await conn.close()
    }
}

sample()

Connection Config

Configurate the connection is quite simple. It's just necessary create a directory on the root of the your project with the name "config" and one file "default.json" (like follow bellow). This package uses the library config to get configurations.

// config/default.json
{
    "providers": {
        "oracledb": {
            "user": "db_user",
            "password": "db_password",
            "connectionString": "db_oracle_connection_string"
        }
    }
}

You can also creating a manual configuration:

import { OracleConnection } from 'dbasefy-oracle/lib'

async function sample(): Promise<void> {
    const conn = await new OracleConnection().open({
        user: "db_user",
        password: "db_password",
        connectionString: "db_oracle_connection_string"
    })
    try {
        // your code
    } finally {
        await conn.close()
    }
}

sample()

With a session:

import { DB, Connection, SqlQuery } from 'dbasefy'
import { OracleConnection } from 'dbasefy-oracle'

interface DualTable {
  DUMMY: string
}

async function getData(conn: Connenction): Promise<DualTable[]> {
    const query = conn.createQuery() as SqlQuery
    query.commandText = 'SELECT * FROM DUAL'
    return await query.execute() as DualTable[]
}

async function getDataWithoutDbasefy(): Promise<DualTable[]> {
   const conn = await OracleConnection().open()
   try {
       return await getData(conn) as DualTable[]
   } finally {
       await conn.close()
   }
}

async function getDataWithDbasefy(): Promise<DualTable[]> {
    return await DB.session<DualTable>(OracleConnection, getData)
}
1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago