1

Can anyone assist with letting me know where I need to define the connection because I keep on getting an error. This is my first stab at this and have been at it for some time now so any help would greatly be appreciated.

var Oracle = require('oracle');


var connectData = {
    hostname: "127.0.0.1",
    port: 1521,
    database: "hr", // System ID (SID)
    user: "user",
    password: "password"
}

Oracle.connect = function(callback) {
    oracle_driver.connect(connectData, function(err, connection) {
        if (err) {
            console.log(err);
        } else {
            callback(err, connection);
        }
        connection.close();
    });
}

var statement = connection.prepare("SELECT * FROM HR where rownum < :1");

function runQuery(stmt, row_num, cb) {
    stmt.execute([row_num], function(err, count) {
        if (err) return cb(err);
        if (count !== 1) return cb(new Error("bad count: " + count));
        // We are done
        return cb();
    });
}


runQuery(statement, 90, function(err) {
    if (err) {
        console.log("Error executing query:", err);
        return;
    }

    console.log(results);
    connection.close(); // call only when query is finished executing 
});

1 Answer 1

1

Unless the oracle driver already supports it, you should wrap your expensive resources into a generic-pool.

See this gist for an example of how you can create your own pool for use.

Sign up to request clarification or add additional context in comments.

3 Comments

If it's not self explanatory enough could do a brief example.. but generally you setup your queue with setup/teardown methods... get a connection from the pool, use it, and return it to the pool.
Pooling looked nice but I do not think it is for Node Oracle, I do not see it listed on the dependency.
No, you create your own module that creates a generic pool, and that pool is loaded with oracle connections...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.