Start refactoring repositories

Logic in repos is the same. What changes are the sql queries to the
(potentially) different database engines.