qantik qantik - 1 year ago 127
Node.js Question

Asynchronous HTTP-requests on sqlite database in Node.js

I'm currently trying to to test a little server with multiple asynchronous HTTP-requests, however my sqlite3 database seems to block simultaneous queries issuing


db.exec(query, (err) => {
if (err !== null) {
callback('Insertion failed.');
} else {

Is there a way to circumvent this problem using the sqlite3 module?

Thanks in advance.

Answer Source

Could you just use async.queue?

var async = require('async');

var q = async.queue(function(task, callback) {
    db.exec(task.query, function(err) {
        callback('Insertion failed.');
}, 1);

q.drain = function() {
    console.log('queue is empty, ready for more query');

q.push({query: "Your SQL INSERT query"}, function(err) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download