【发布时间】:2021-03-27 10:31:09
【问题描述】:
我正在使用 Node.js、Fastify 和 Postgresql 创建一个 API,这应该从尚未开发的 React 客户端获取表单的数据,我想象最终将到达我的 API 的数据结构如下:
{
"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"
}
}
现在我想将这些值存储在我的 Postgresql 数据库中,为此我需要将数据拆分到彼此相关的不同表(作者、引用、书籍、用户等)中。
在研究如何实现我想用作 API 文件输入的 JSON 数据时,我发现了两个概念:
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.
我现在的问题是这里哪种方法更可取,或者是否还有其他更好的方法?
感谢您的帮助。
【问题讨论】:
标签: node.js json postgresql http fastify