Adds tests and some inline fixes in db pagination

Refactors the pagination code to be a bit more DRY and
gets the procession.db.api module up to 100% code coverage.