Tweak DB schema slightly

Tweak the approach to data storage to use a single table with compound
keys instead of separating tables. This will avoid having to generate
queries (and just parameterise the standard queries).