Refactored to work with Flask-SQLAlchemy

SQLAlchemy was used with a declarative base configuration, allowing a
new db to be dropped in at any point.