Separated out common db functionalities to DB lib and added unit tests.