How to use the oracledb.getConnection function in oracledb

To help you get started, we’ve selected a few oracledb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oracle / node-oracledb / test / connectionClass.js View on Github external
it('221.2 set the property when using a standalone connection', async () => {
    try {
      oracledb.connectionClass = 'NODB_TEST';
      const conn = await oracledb.getConnection(dbconfig);

      await conn.close();
    } catch (err) {
      should.not.exist(err);
    }
  }); // 221.2
});
github oracle / node-oracledb / examples / aqoptions.js View on Github external
async function enq() {
  let connection;

  try {
    connection = await oracledb.getConnection(dbConfig);

    const queue = await connection.getQueue(queueName);
    queue.enqOptions.visibility = oracledb.AQ_VISIBILITY_IMMEDIATE; // Send a message immediately without requiring a commit

    const messageString = 'This is my other message';
    const message = {
      payload: messageString, // the message itself
      expiration: 1           // seconds the message will remain in the queue if not dequeued
    };
    console.log('Enqueuing: ' + messageString);
    await queue.enqOne(message);
  } catch (err) {
    console.error(err);
  } finally {
    if (connection) {
      try {
github sbalagop / neo / nserver.js View on Github external
app.get('/user_profiles', function (req, res) {
    "use strict";

    oracledb.getConnection(connAttrs, function (err, connection) {
        if (err) {
            // Error connecting to DB
            res.set('Content-Type', 'application/json');
            res.status(500).send(JSON.stringify({
                status: 500,
                message: "Error connecting to DB",
                detailed_message: err.message
            }));
            return;
        }

        connection.execute("SELECT * FROM USER_PROFILES", {}, {
            outFormat: oracledb.OBJECT // Return the result as Object
        }, function (err, result) {
            if (err) {
                res.set('Content-Type', 'application/json');
github oracle / node-oracledb / examples / insert2.js View on Github external
async function run() {

  let connection1, connection2;

  try {
    connection1 = await oracledb.getConnection(dbConfig);
    connection2 = await oracledb.getConnection(dbConfig);

    let result;

    //
    // Create a table
    //

    const stmts = [
      `DROP TABLE no_tab2`,

      `CREATE TABLE no_tab2 (id NUMBER, name VARCHAR2(20))`
    ];

    for (const s of stmts) {
      try {
github oracle / node-oracledb / examples / blobhttp.js View on Github external
async function handleRequest(request, response) {

  const requrl = url.parse(request.url, true);
  const action = requrl.pathname;

  if (action == '/getimage') {

    let connection;

    try {
      connection = await oracledb.getConnection();  // gets a connection from the 'default' connection pool

      const result = await connection.execute(
        "SELECT b FROM no_lobs WHERE id = :id",  // get the image
        { id: 2 }
      );
      if (result.rows.length === 0) {
        throw new Error("No data selected from table.");
      }

      const lob = result.rows[0][0];
      if (lob === null) {
        throw new Error("BLOB was NULL");
      }

      const doStream = new Promise((resolve, reject) => {
        lob.on('end', () => {
github oracle / node-oracledb / test / fetchArraySize8.js View on Github external
before(function(done) {
    oracledb.getConnection(dbConfig, function(err, conn) {
      should.strictEqual(default_fetcArraySize, 100);
      should.strictEqual(default_maxRows, 0);
      should.not.exist(err);
      connection = conn;
      done();
    });
  });
github oracle / node-oracledb / test / fetchArraySize1.js View on Github external
before(function(done) {
    oracledb.getConnection(dbConfig, function(err, conn) {
      should.strictEqual(defaultVal, 100);
      should.not.exist(err);
      connection = conn;
      done();
    });
  });
github oracle / node-oracledb / test / fetchClobAsString4.js View on Github external
function(cb) {
        oracledb.getConnection(dbConfig, function(err, conn) {
          should.not.exist(err);
          connection = conn;
          cb();
        });
      },
      function(cb) {
github oracle / node-oracledb / test / fetchArraySize4.js View on Github external
before(function(done) {
    oracledb.getConnection(dbConfig, function(err, conn) {
      should.strictEqual(default_fetcArraySize, 100);
      should.strictEqual(default_maxRows, 0);
      should.not.exist(err);
      connection = conn;
      done();
    });
  });
github oracle / node-oracledb / examples / selectjsonblob.js View on Github external
async function run() {

  let connection;

  try {

    connection = await oracledb.getConnection(dbConfig);

    if (connection.oracleServerVersion < 1201000200) {
      throw new Error('This example only works with Oracle Database 12.1.0.2 or greater');
    }

    const stmts = [
      `DROP TABLE no_purchaseorder_b`,

      `CREATE TABLE no_purchaseorder_b (po_document BLOB CHECK (po_document IS JSON)) LOB (po_document) STORE AS (CACHE)`
    ];

    for (const s of stmts) {
      try {
        await connection.execute(s);
      } catch(e) {
        if (e.errorNum != 942)