db operation refactor