So something to note, while this is an interesting idea, you have to
be careful. We make zero commitments about the stability of the
database schema today ... so expect an upgrade to break things,
especially if we have a migration. In short, accessing the data
directly is not a supported stable API. Not saying it won't work, but
just letting you know the risks involved here.
Not sure how useful it is, we do have a lot of complex query
capability just built into PDB via the REST interface which might be
able to provide what you need:
http://docs.puppetlabs.com/puppetdb/2.0/api/query/v4/query.html
ken.