API tweaks

Initial work on API and looking at indexes for query patterns.
This file looks outdated. It still has tables for rolify (the roles and user_roles) and the hstore extension which isn't being used.