Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use oracle transaction with node.js #99

Open
sundarsrini opened this issue Apr 21, 2014 · 2 comments
Open

How to use oracle transaction with node.js #99

sundarsrini opened this issue Apr 21, 2014 · 2 comments

Comments

@sundarsrini
Copy link

I trying to use either 'persist' or 'oracle' to perform transactions in the oracle database through node.js program, i am not sure if there is a feasibility to do that required process or its not working for me. Kindly help!

@ioneyed
Copy link

ioneyed commented Apr 21, 2014

You mention that it may no be working for you but you didn't provide a code sample? The documentation currently doesn't have an oracle example but I can assure you it works just fine with oracle as I have been using it with oracle for a couple weeks now in production.

I have forked this repo and working on a few changes that I hope will be accepted into master once I finish them. In the meantime at my forked page you can view an expanded database.json file that shows how to declare oracle with and without using TNS names.(my fork: http://github.com/ioneyed/node-persist )

If that doesnt solve your problem then please provide a gist/sample of your implementation so we can resolve your issue. Stating its just not working isn't a good way to get a resolution.

@sundarsrini
Copy link
Author

Thanks for your response. I have added my simple code below for your perusal. Program is not executing the loop tx.rollback or tx.commit. Kind help if there is asynchronous flow or syntax issues.

var persist = require('persist');

var connectData = {
driver:"oracle",
hostname: "localhost",
port: 1521,
database: "xe", // System ID (SID)
user: "tsw",
password: "ts"
};

persist.connect(connectData, function(err, connection){
if(err)
{
return console.error('could not connect to oracle', err);
}
else
{
connection.tx(function(err,tx){
connection.runSql("update emp set employee_name = :1 where employee_id = :2",["RaguSachin",320923], function(err, result){
if(err)
{
console.log('rollback');
tx.rollback(function(err,result) {
if(err)
{
console.log('error in rollback');
connection.close();
}
else
{
console.log('rollback success');
}
});
}
else
{
console.log('No error');
tx.commit(function(err,result) {
if(err)
{
console.log('error in cvommit');
connection.close();
}
else
{
console.log('commit success');

          }
             });
      }
       });
    });
    }

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants