I am creating an API with Node.js, Fastify and Postgresql, this is supposed to get the data of a form from a yet to be developed React client, I imagine the structure of the data that will eventually arrive in my API as follows:
{
"quote": {
"body": "Of our qualities, none can be ascribed to the divine being without tainting it with its imperfection.",
"author": "michel de montaigne",
"page": "55",
"book": {
"title": "Diary of the Journey to Italy",
"publisher": "Eichborn Verlag",
"year": "2009"
}
},
"hashtag": "#God",
"user": {
"name": "betonhead",
"email": "bier@wurst.de"
}
}
Now I want to store these values in my Postgresql database, for this I need to split the data to the different tables (authors, quotes, books, user, etc.) that are related to each other.
In my research on how to implement the JSON data I want to use as input to my API file I found two concepts:
1. creating a view in Postgres, splitting the data via Node.js middleware.
2. store the raw JSON files directly in Postgres and from there distribute them to the tables using a function.
My question now is which method is preferable here, or maybe there are other better methods?
Thanks for your help.