SQL backend

This will need a while to be ready, but I figure already putting up a PR for code review is a good idea.