This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

oracle-db-util

1.11.7 • Public • Published

oracle-db-util

Select example

/*
dbConfig format
{
   "username": "oracle",
   "port": "1521",
   "password": "yourpassword",
   "host": "yourhost/orcl"
}

*/
let dbConfig = require("./dbconfig-eduardo.json");
let db = require("oracle-db-util")(dbConfig).on("ready", function () {
   console.log("it works");
});

(async () => {
   try {
       const rows = await db.findOne(
           "USERS",//The table name
           ["ID", "NAME"], //optional, columns name
           {
               //optional where clause
               name: "Eduardo Carrillo"
           }
       );
       console.log("find one result");
       console.log(rows);
   } catch (e) {
       throw e;
   }
})();

(async () => {
   try {
       const { rows } = await db.find("USERS");
       console.log("getAllResults");
       console.log(rows);
   } catch (e) {
       throw e;
   }
})();


// For unhandled promise rejection error

process.on("unhandledRejection", function (reason, p) {
   console.log(
       "Possibly Unhandled Rejection at: Promise ",
       p,
       " reason: ",
       reason
   );
   // application specific logging here
});

// Prevent the server crashes with uncaught exception

process.on("uncaughtException", function (err) {
   console.log("Caught exception: " + err.stack);
});

Insert example

  let dbConfig = require("./dbconfig-eduardo.json");
  let db = require("oracle-db-util")(dbConfig).on("ready", function () {
      console.log("it works");
  });

  //Insert row with returning values
  (async () => {
      const id = Math.floor(Math.random() * 10000);
      try {
          const data = {
              id,
              name: "Awesome user " + id
          };
          const row = await db.save("users", data, ["ID", "NAME"]);//save user and return the id and name
          console.log("row saved");
          console.log(row);
      } catch (e) {
          throw e;
      }
  })();

  //common insert
  (async () => {
      const id = Math.floor(Math.random() * 10000);
      try {
          const data = {
              id,
              name: "Awesome user " + id
          };
          const {rowsAffected}= await db.save("users", data);
          console.log("rows affected %d ",rowsAffected);
      } catch (e) {
          throw e;
      }
  })();

Update example

/*
require db file 
*/
(async () => {
  try {
      const { rowsAffected } = await db.update({
          table: "users", data: {
              name: "Ecarrillo"
          }, where: {
              id: 1
          }
      });
      console.log(rowsAffected);
  } catch (e) {
      throw e;
  }
})();

Delete example

let db = require("./db");

(async () => {
    try {
        const r = await db.deleteRow({
            table: "users", where: {
                id: 1575
            }
        });
        console.log(r);
    } catch (e) {
        throw e;
    }
})();

Readme

Keywords

Package Sidebar

Install

npm i oracle-db-util

Weekly Downloads

1

Version

1.11.7

License

MIT

Unpacked Size

38.9 kB

Total Files

15

Last publish

Collaborators

  • ecarrillo