db upserting functional