database interface rewrite - WIP

This moves all of the database code into purpose-specific classes, then
combines those all in a nice facade.  The current DB object is passed
around, rather than being a global; this
 * presents minimal difficulty
 * ensures that only code that should be talking to the DB does
 * ensures that a given server instance shares exactly one instance of
   the DB facade

lots of TODO's left.
WIP - tests