factor out Database#store