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 chain multiple sql query #490
Comments
Have a look at @sagiegurari has a popular wrapper that you could evaluate. But overall, you may want to wrap up your command in a single PL/SQL block. This means node-oracledb only has to execute one statement, which may help overall scalability. |
might want to look at connection.transaction that enables to run multiple activities either in parallel (default) or in sequence (defined in options object) |
@sagiegurari After some discussion with a colleague and some testing, I would recommend removing the sequence option in the transaction method. The reason is that the connection object acts as a serialization device, meaning it can only do one thing at a time anyway. That makes the option a little misleading. When you use the async.series method, the queuing is done in the main JS thread. When you use async.parallel, the queuing ends up being done in the C layer via a mutex. The big problem here is that libuv isn't aware that a connection can only do one thing at a time - it only knows when it has background threads available and so it sends off the work to be done. So when you run in "parallel", you could use more than 1 background thread (perhaps all of them) and each one could be waiting on the one before it to finish its "execute". Of course other users/transactions can't use them at that time either. Here's a test that you can run to see that there's no real performance difference with the 2 methods (actually I generally had better times with series). Given this table: create table perf_test (
c varchar2(30) not null
); Run this test: var async = require('async');
var oracledb = require('oracledb');
var dbConfig = require('./dbconfig.js');
var asyncFunc = 'series'; //or parallel
oracledb.getConnection(dbConfig, function(err, conn) {
var funcs = [];
var start = Date.now();
var idx;
if (err) {throw err;}
function insertData(callback) {
conn.execute(
'insert into perf_test (c) values (:string)',
[Math.random().toString(36).replace(/[^a-z]+/g, '')],
function(err, result) {
callback(err);
}
);
}
for (idx = 0; idx <= 100000; idx += 1) {
funcs[idx] = insertData;
}
async[asyncFunc](funcs, function(err, results) {
if (err) {throw err;};
conn.commit(function(err) {
if (err) {throw err;};
conn.close(function(err) {
if (err) {throw err;};
console.log('done', Date.now() - start);
});
});
});
}); |
that's 100% true, the only thing is that sometimes, the connection.execute is not the only async IO action you are doing. sometimes, it is writing to http response/file, or reading from a file. Anyone killing the node.js threads will end up killing his process. I usually tune it to around 10/20 threads, depending on the specific component. |
What you're describing seems to be a better fit for If you're going to leave the option, maybe changing it to series by default would be good. |
ya, i'm actually making that change right now. |
Just published a new version with few changes like moving to parallelLimit (with limit of half the node.js threads) and using series as default and writing a bit more in the docs. |
Closing - I believe this has run its natural course. |
Hi,
I am pretty new to oracledb with NodeJS.
I want to do mutiple sql call that are dependant.
Before executing the query sqltoExecute, I need to configure the connection by executing a query that set "set role " and then another one to "set package" and finally execute my query sqltoExecute.
I am trying to find some examples but failed to find any.
Below, a snipper of the code I tried to execute but it fails since it only execute the first query , it fails to execute the second "then" that execute the query " sqlQueries.sqlQuerySetPackage()"
I am using on NodeJS 4.4.7 on Ubuntu 14.
Thanks for help.
The text was updated successfully, but these errors were encountered: