Refactor SQL specific code
Add database instance test case