qantik
qantik

Reputation: 1097

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 SQLITE_BUSY.

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

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

Thanks in advance.

Upvotes: 0

Views: 590

Answers (1)

user7009026
user7009026

Reputation:

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.');
    });
    callback();
}, 1);

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

q.push({query: "Your SQL INSERT query"}, function(err) {
    console.error(err);
});

Upvotes: 1

Related Questions