refactor
generate sql