db: eliminate code duplication