Sql backend: basic implementation and some tests

Also a few raco refactoring and fixes inline.

@7andrew7 take a gander? To be honest, I kind of / really hate this.
(This is just a basic start at the functionality, looking for a sanity check and high-level feedback mostly)