Help with querying frontmatter subattributes

I’m wondering if its possible to select all subattributes of a given attribute using Lua query to build a table??

I’m a relative newcomer to silverbullet, I’ve imported a bunch of pages and started converting some common features of my knowledge base to subattributes in the frontmatter. Ideally I’d like to build a table of these subattributes so that I can see where there’s gaps in my knowledge.

The query I’m using at present is:

${query[[
  from index.tag "page" 
  where name:startsWith("Medication") 
  order by name
  select {
    name = _.name, 
    medication = _.medication
  }
]]}

However the subattributes all render in a single column, ideally they’d expand so each attribute has its own column and the table dynamically updates so that if I add additional sub-attributes it creates a column automatically to show where other gaps are…

Bonus question, is it possible to have the text wrap inside the table?

I’m not quite sure if I understand you correctly, but maybe this works.

${query[[
  from index.tag "page" 
  where name:startsWith("Medication") 
  order by name
  select table.merge({
    name = _.name
  }, _.medication)
]]}

with this helper function

function table.merge(t1, t2)
  local result = {}
  t1 = t1 or {}
  t2 = t2 or {}
  for k, v in pairs(t1) do
    result[k] = v
  end
  for k, v in pairs(t2) do
    result[k] = v
  end
  return result
end

(Putting this merge function in the table scope may not be the best idea, because a hell of a lot of people in the lua community for some reason seem to think that a merge is a concatenation, which I strongly disagree with, but I guess it could cause confusion)