Common code for all the database related code