Major refactoring to support multiple databases

In order to support multiple databases under the same interface, turn
Db into an abstract class that is subclassed in order to support a
given database and database library (e.g., PostgreSQL and pg). Pass all
method calls through Db to the appropriate implementing subclass.

This commit contains an implementation for PostgreSQL and pg only.