db: moving flatten, unflatten to top-level db.__init__, updating tests db.py to work with new cursor from find.