title: NodeJS and SQLite3 check row exist before insert
body: <pre><code>var db = new sqlite3.Database("items.db");
  db.serialize(function()
      {
          var stmt = " SELECT * FROM items;";
          db.get(stmt, function(err, row){
              if(err) throw err;
              if(typeof row == "undefined") {
                      db.prepare("INSERT INTO items (ID) VALUES(?)").run("item1").finalize();
              } else {
                  console.log("row is: ", row);
              }
          });
      });
  </code></pre>
  
  <p>The snippet above produces the following error:</p>
  
  <pre><code>events.js:72
     throw er; // Unhandled 'error' event
                ^
  Error: SQLITE_MISUSE: Database handle is closed
  </code></pre>
  
  <p>I am not sure what I am doing wrong, and is this the best way to do this?</p>
  
  <p>I also tried to use:</p>
  
  <pre><code>var stmt = " SELECT EXISTS(SELECT * FROM monitor LIMIT 1)";
  </code></pre>
  
  <p>to check if the entry exists or not.</p>
  
  <h2>Thank you,</h2>
  
  <p>D</p>