MySQL query builder in JS