Create API data structures from Postgres queries