NodeJS sqlite3 concurrent access
<p>Basically I have a database where not many accesses appear but sadly grouped by two. </p>

<p>Firstly, there is a write access to the database
Secondly, there is a read access. </p>

<p>The read access fails with the message that the database is locked (<code>{ [Error: SQLITE_BUSY: database is locked] errno: 5, code: 'SQLITE_BUSY' }</code>) which is totally normal. But how can I make my read access to wait until the database is closed? </p>

<p>My current code:</p>

<pre><code>var sql = "INSERT INTO chickenmilk (userID,channelID,message) VALUES (?,?,?)"
db.run(sql, userID, channelID, bot.fixMessage(message), function(err) {
    console.log(err);
    db.close();
});
</code></pre>

<p>And concurrent:</p>

<pre><code>var sql = "SELECT userID, COUNT(message) as count FROM chickenmilk WHERE channelID LIKE ? GROUP BY userID";
db.all(sql, data, function(err,res) {
    if(err) {
        console.log(err);
        return "";
    }

    callback(res); // data is used here
    db.close();
});
</code></pre>