title: SQLite3 + Node.js - Should I open and close the database for each INSERT or keep it always open?
body: <p>I have a Node.js process monitoring an application, writing to the database when a certain action happens. There is a frontend for this database, which causes concurrency errors when both are trying to access the data. The internal processes dont matter too much, but theres a write to the database about 3 times a second (which I believe to be considered still quite slow). Here is my INSERT statement:</p>
  
  <pre><code>db.run(query, data, function(e)
  {
      if (e)
      {
          console.log("Could not insert a Sync!")
          console.log(e.message)
      }
  });
  </code></pre>
  
  <p>My question is, should I open and close the database for each insert:</p>
  
  <pre><code>db = new sql.Database('../db', sql.OPEN_READWRITE, (e) =&gt;
  {
      if (e)
      {
          console.log("Could not connect to the DB!")
          console.log(e.message)
      }
  })
  
  db.run(query, data, function(e)
  {
      if (e)
      {
          console.log("Could not insert a Sync!")
          console.log(e.message)
      }
  });
  
  db.close()
  </code></pre>
  
  <p>Or open at the start of the process and just leave the db object open? 
  Im hoping to reduce the amount of concurrency errors, WAL option I am looking into. Thanks</p>