Support for a Notion-like Schema
Hey! We're looking to implement a modular data schema inspired by Notion - see this great article on what that looks like: https://www.notion.so/blog/data-model-behind-notion
As you can see, Notion stores the children of a block (e.g. a page) as a list of ids to other blocks in a field called content. It does so vs just back references (e.g. with a parentId) as suggested here: https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas#back-references-scalable because the order of the ids in the content field actually determines the layout of those children. Given that Convex doesn't recommend having long arrays inside fields, I was wondering what the recommended approach here would be...
Notion
Exploring Notion's Data Model: A Block-Based Architecture | Notion
Notion’s data model enables the product’s most foundational component: blocks. Through blocks, we allow users more flexibility over their information.
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
3 Replies
I would store the order as a field, like
And then populate the rank with an algorithm like https://www.npmjs.com/package/lexorank so you can move children around easily.
npm
lexorank
A reference implementation of a list ordering system like JIRA's Lexorank algorithm. Latest version: 1.0.5, last published: 2 years ago. Start using lexorank in your project by running
npm i lexorank
. There are 11 other projects in the npm registry using lexorank.Oh wow interesting I had never heard of lexorank, thanks for sharing!
Tagging @Sirian
Also, arrays are not always a bad choice. Depends on what read patterns, and how many items you want to support (Convex arrays have a limit of 8000 items and 1MB).