factor out db code
sphinx doc