#320 Move SQL generation into dialect