GROUP BY and Object References

I’ve been using SB for about 2.5 weeks and have been loving it. The ability to throw in dynamic queries, customize templates / widgets, and write space-script’s to extend functionality is amazing. Thank you, Zef!

The main areas I would love to see more functionality on (and where I’ve been hacking it together so far) is in exposing more of the relational model to the user.

To illustrate one example: I’ve hacked together a light-weight personal CRM/PRM in Silverbullet using Meeting and Contact and Organization objects and have been using frontmatter attributes and queries to link in between:

  • on each Meeting object, I have a contact attribute with a value of Contact/[NAME] which links to the corresponding Contact object for the person I had the meeting with
  • my Meeting template has a suggestedName: "Meeting/[INSERT NAME]-{{today}}" and I prepopulate the contact attribute with a replace call and a quick regex to isolate the name from @page.name
  • on my Contact template, I have a query block that shows every meeting I’ve had with the individual by querying all meeting objects against contact = @page.name
  • I’ve had to hack together things an updated Contact.last_connected attribute which I’ve done by adding a custom command in my Meeting template which uses editor.setText to quickly create a template block in to runs a custom function changeAttribute(@page.contact, 'last_connected', @page.date) and then removes it (so that I can access the Meeting’s attributes)

In a traditional relational database, a lot of this would be handled with foreign key references and aggregation functions on GROUP BY queries or table JOINs (as I currently don’t have a great way of handling multi-contact meetings or things like counting the number of contacts at a particular organization).

I know the intent of SB is not to be a full-fledged database app (although that’s why I heavily considered Siyuan and AnyType while I was thinking about what to use) but I think exposing more relational functionality could be quite powerful and just wanted to plant that seed.

2 Likes