Ported the Database class.

The Database class was brought over with a combination of
hand-written code plus sharpened code (some of which was
refactored). There was significant dependent code that came
with, and all of it was either brought in or stubbed out.