Let me drop an idea here, and see what you think — this is still early stage, but interested in some feedback on if this would be of interest to you.
My original design for Objects in SB was to keep it very loose and dynamic. You could add arbitrary attributes to objects, and validation would always be optional. The query language is nice and simple, but has limitations compared to a “proper” SQL implementation and likely always will, because implementing a full on SQL database is hard.
Nevertheless, I see people wanting to do more and more with the data that SilverBullet collects for them, or the data they collect in it. They want effectively do joins, aggregations and other standard SQL stuff. To some degree can implement these now in Lua, but this is going to be slow and a bit of a pain to write.
One obvious solution would be to let Objects be backed by a “proper” database, like SQLite. To get the true power of SQLite, you’d have to create proper tables. Those tables require a schema, and when we talk about schemas we also talk about data migrations when schemas change. This is a pain I don’t want to make part of the SilverBullet experience, which is why I never really considered it.
But now I’m thinking: what if we offer both.
What if we offer a way (probably a Lua API) to define schemas for tags. For all the tags with a defined schema (again, this would be optional), we then create SQLite tables, and as part of regular indexing insert data into those tables as well.
If you change the schema, you’d have to a SQLite reindex: drop all the SQLite tables, create them anew with the new schema, pull all the objects from the “regular” Objects database, and reinsert them (if they match the schema, otherwise not). There’d be ways for you to see what objects don’t match the schema and will not be indexed as a result.
And then, we can simply offer a Lua API to perform real SQL queries in your pages:
${sql[[
select hello, avg(something) from sometag
left join bla on dah
group by something
]]}
etc.
I don’t think would even be that hard to do, but could offer some fancy new features.
One reason not to do this is added complexity: there’s now be two query languages, one with nice Lua integrations, and one just being plain SQL.
Thoughts?