Move db interaction to SQLAlchemy to support multiple database drivers.

This abstracts all database interaction through SQLAlchemy, and adds support for using a connection string instead of the default sqlite database. Tested on postgres which works fine :) Might need some optimization and testing though, but this is a start. Try it! (Also, please verify that the quality of the output is still the same.)