Since use of external libraries in extensions isn't really possible, as per our discussion on IRC, I've decided to not write a library to do this and instead keep it in the entity.

The entity isn't supposed to be just an interface over the database, it handles everything someone would need to do that would affect a single rule.