title: How to create an sql statement with optional parameters
body: <p>I have a <code>lessons</code> table that contains the following fields:</p>
  
  <pre><code>id  title   type    language    level 
  </code></pre>
  
  <p>The user through the interface can select witch lesson he wants to open.</p>
  
  <p>He will start selecting the language, then the type and finally the level.</p>
  
  <p>During this process I want to query the database using a single sql statement, but of course the first query will have only the language field. I came up with this syntax but it does not work:</p>
  
  <pre><code>function queryLessonList (language, type, level){
  
      const values = [language, type, level];
  
      const sql = "SELECT * FROM lessons WHERE (language=?) AND (? is null OR type=?) AND (? is null OR level=?)";
  
      return query(sql, values);
  }
  </code></pre>
  
  <p>How can I make it work?</p>