Overhaul the database API

**This is not an AS-IS pull request**

Though everything is in a functional state, I feel that the DBOperationImpl* code should be cleaned up more. We should discuss the best way to do that before merging.