refactor to expose some utilities for Esqueleto

Moved some functionality regarding composite/custom primary keys to an exposed module (perhaps it should be under an "Internal" folder?) so Esqueleto can reuse it. See https://github.com/prowdsponsor/esqueleto/issues/87