Factor out the db stuff into two

Now failing with a `pc_bytes_sigbits_encode` error, so going to check
master to see if problem exists there as well.