A library such as [`squel`](https://github.com/hiddentao/squel) would be nice to ease your generation of SQL.