All queries rewritten to use sql bricks and extracted to builder.js, added some helpers.