DB: Allow multiple database connections

I’ve eliminated top-level state from the 'db' module, encapsulating it
instead in the 'db.Index' class.  This should make it substantially
easier to work with multiple databases at once.  It should also ease
working with different database schemas if we ever have to do that in
the future.