Out of curiosity, have you tries logseq or silverbullet.md? They both have capabilities to query your notes similar to Notion.
I've had this challenge with structuring notes-data for a while, but haven't found something that suits my workflow yet. I have on my list to experiment with a sqlite solution.