Improve sqlite query builder