Factorize some common db function.