I’m creating a blog about programming and I’m having issues while deciding on the database schema for articles. Basically, my idea was that each article is composed of multiple so-called ‘building blocks’ and each of these blocks has some kind of properties. Let’s say there’s a ‘paragraph’ block, there’s a ‘heading’ block and an ‘image’ block. My simple article would then look something like this:
{
"title": "My blog article",
"authoredOn": "2022-04-29T16:30:11.525Z",
"buildingBlocks": [
{
"type": "heading",
"content": "Kotlin Variables"
},
{
"type": "paragraph",
"content": "Lorem ipsum dolor sit amet consectetur."
},
{
"type": "image",
"source": "/image005.jpg"
},
{
"type": "code",
"language": "kotlin",
"content": "fun main() {\n\tprintln(\"Hello World!\")\n}"
}
]
}
Is this the proper approach? I have a problem with the fact that there can be multiple types of objects stored in the buildingBlocks
array which means I can’t access it in a type-safe way using Kotlin (or any other programming language). Also, what if I want to also store markings about the text, like bold text or underlined text? How would I have to approach that?