Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import oracledb from 'oracledb';
- export class ConnectionDB {
- constructor() {
- }
- public getElements(consult :string) : Promise<Object> {
- return new Promise(async function (resolve, reject) {
- let connectionDB;
- await oracledb.getConnection({
- user: "system",
- password: "51264",
- connectString: "localhost:1521/xe"
- }).then(async (connection: oracledb.IConnection) => {
- console.log("Conección abierta.");
- await connection.execute(consult, [],{ outFormat: oracledb.OBJECT })
- .then((result) => { resolve(result.rows) });
- connection.close().then(() => {console.log('Conección cerrada.')});
- }).catch((err: any) => {
- console.error(err.message);
- });
- });
- }
- public addElement(element: Object, sql: string, options: Object)
- {
- oracledb.getConnection({
- user: "system",
- password: "51264",
- connectString: "localhost:1521/xe"
- }).then(async (connection: oracledb.IConnection) => {
- console.log("Conección abierta.")
- await connection.execute(sql, element, options).
- then((result)=>{console.log("Rows: \n", result.rowsAffected)})
- .catch((err)=>{console.error("Promise rejected - ",err)});
- connection.close().then( () => { console.log("Conección cerrada.") } )
- .catch((err) => { console.error(err.message) });
- }).catch((err: any) => {
- console.error(err.message);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement