I want my function to return a list of everything in a table if there are no query parameters, and a single row if the parameter id exists
var mysql = require('mysql');
var config = require('./config.json');
var pool  = mysql.createPool({
    host     : config.host,
    user     : config.user,
    password : config.password,
    database : config.database
  });
  exports.handler = (event, context, callback) => {
      var whereClause
      if(event.queryStringParameters.id !== null){
          let id = event.queryStringParameters.id
          whereClause = ' where id='+id
      }
    context.callbackWaitsForEmptyEventLoop = false;
    pool.getConnection(function(err, connection) {
        // Use the connection
        connection.query('SELECT * from users'+whereClause, function (error, results, fields) {
        // And done with the connection.
        connection.release();
        // Handle error after the release.
        if (err) callback(err);
        else {
            var response = {
                "statusCode": 200,
                "headers": {
                    "my_header": "my_value"
                },
                "body": JSON.stringify(results),
                "isBase64Encoded": false
            };
            callback(null, response);
        }
        });
    });
};
the function fails when no query parameter is present with the error
"Cannot read property 'id' of null"
why is that?
 
    