Sunday, 15 January 2012

sql server - Send response before query is complete -



sql server - Send response before query is complete -

i have web app calls queries sql server via node.js.

i want fire off query client takes 1 - 2 seconds, in special cases may take min , half.

the client wants response xhr request, , doesn't want wait min , half. doesn't care response says.

the query delete statement via openquery - isn't expecting results back.

is there way fire such thing delete statement , homecoming response query before complete, regardless of results? haven't heard of such thing don't know look, can't find far.

in many other languages reply involve threading since js not back upwards threads have work processes create asynch returns 1 describe.

in app spawn kid process rest/web api function called , responsible returning result client. scheme decouple dependency on execution time of delete query. whether kid process runs in 2 seconds or 2 minutes client not know difference, he/she wants it, , result seem immediate.

there number of simple samples , other resources this one , this one etc. available.

simple code sample running kid processes nodejs:

var exec = require('child_process').exec; exec('node -v', function(error, stdout, stderr) { console.log('stdout: ' + stdout); console.log('stderr: ' + stderr); if (error !== null) { console.log('exec error: ' + error); } });

you don't care or need in/out/error streams code might simpler. this:

var exec = require('child_process').exec; exec('node -v', function() { // set delete code here });

this section added , modified comments below:

the way know of launching async task in sql server schedule execution of query, sproc etc. that's ugly hack. there native apis allow programmatically client you're started.

in case , suggest not implementing feature in sql because of tight coupling create between ui/ux , end. , don't think deep dive node.js necessary implement kid process solution. it's pretty straightforward, if don't care result. simple fire , forget.

sql-server node.js

No comments:

Post a Comment