Move SQL queries to model