数据库设计| PHP-Mysql | JSON [重复]

时间:2020-12-05 16:56:17

This question already has an answer here:

这个问题在这里已有答案:

I am developing an application using F3 in which report generation is a sub-app. Now i have the reports in the form of json data which will be large.

我正在使用F3开发一个应用程序,其中报告生成是一个子应用程序。现在我有json数据形式的报告,这些报告很大。

Problem is that, JSON data is in multiple levels and difficult to define schema for it.

问题是,JSON数据是多层次的,很难为它定义模式。

Now, any suggestion on how i should store the JSON, as file? or in mysql database as blob or text?

现在,关于我应该如何存储JSON作为文件的任何建议?或者在mysql数据库中作为blob或文本?

Note: I would JSON data only to generate report (PDF, Excel etc) . I never modify it.

注意:我只会将JSON数据生成报告(PDF,Excel等)。我从不修改它。

Thank you, Sash.

谢谢你,腰带。

1 个解决方案

#1


1  

Ok, if you're going to be using that JSON data as read-only material, to build PDF's then it sort of depends on a number of things:

好的,如果您要将JSON数据用作只读材料,那么构建PDF则会取决于以下几点:

  • How many JSON formatted objects are we talking about? Storing them stringified isn't that much of a problem (as the question I marked as duplicate states). Of course, if we're talking about thousands of JSON strings, you'll need to index that table (those tables) and that requires either a unique id that's unrelated to the actual data, or parsing the string, and using some properties you could use to query.

    我们在谈论多少个JSON格式的对象?将它们存储为字符串并不是一个很大的问题(因为我标记为重复状态的问题)。当然,如果我们谈论成千上万的JSON字符串,你需要索引该表(那些表)并且需要一个与实际数据无关的唯一id,或者解析字符串,并使用一些属性你可以用来查询。

  • You say the JSON-objects are fairly large (because you're talking about TEXT/BLOB fields) which can hold up to 65k characters... Are you sure you're going to be using even half that amount of chars, 20% of the time?? It does feel like overkill to me, to be honest

    你说JSON对象相当大(因为你在谈论TEXT / BLOB字段),它可以容纳多达65k个字符......你确定你将使用甚至一半的字符,20%的时间??说实话,这对我来说确实有些过分

  • How variable is the JSON's structure? does one object consist of a simple JS-style object literal while the other one is a 7-level-deep nested object? If all objects share a certain structure, you're probably going to be better of building a schema.

    JSON的结构有多变量?一个对象是由一个简单的JS风格的对象文字组成,而另一个是一个7级深的嵌套对象吗?如果所有对象共享某个结构,那么您可能会更好地构建模式。

  • I don't know if you're comfortable with it, or it's an option in your case, but since you're not going to be writing to that table too often, and it's al JSON formatted, why not look into another DB system? It's been a while, but I have worked with mongoDB which could be useful to you.

    我不知道你是否对它感到满意,或者它是你的一个选择,但是因为你不会经常写那个表,并且它是JSON格式的,为什么不调查另一个数据库系统?已经有一段时间了,但我使用的mongoDB可能对你有用。

Recap: If you only have, say, ~10 JSON objects: just store them in a simple table as VARCHARS (or TEXT), add an id field if needs must. If you can, a simple file will do, too, of course. No need to connect to a MySQL server, no need for all that overhead just file_get_contents('JSON_DATA1.json'); can do the trick. Of course, take safety precautions where needed.
If you have tons of objects, build a MySQL schema... unless the objects have truly no similarities as far as format goes (no similar properties @ the same level)
Do take a look at alternatives like mongoDB and, perhaps, other NoSQL DB's. They might be of use to you. Mongo, for example, stores its data in JSON-style documents and is quite easy to work with because of it's JavaScript-like interface.

回顾:如果您只有~10个JSON对象:只需将它们存储在一个简单的表中作为VARCHARS(或TEXT),如果需要必须添加一个id字段。如果可以,一个简单的文件当然也可以。无需连接到MySQL服务器,不需要所有开销只需file_get_contents('JSON_DATA1.json');可以做到这一点。当然,在需要时采取安全预防措施。如果你有大量的对象,那么构建一个MySQL模式......除非这些对象与格式完全没有相似之处(没有类似的属性@同一级别)请看看像mongoDB这样的替代品,也许还有其他NoSQL DB的。它们可能对你有用。例如,Mongo将其数据存储在JSON样式的文档中,因为它具有类似JavaScript的界面,因此很容易使用。

#1


1  

Ok, if you're going to be using that JSON data as read-only material, to build PDF's then it sort of depends on a number of things:

好的,如果您要将JSON数据用作只读材料,那么构建PDF则会取决于以下几点:

  • How many JSON formatted objects are we talking about? Storing them stringified isn't that much of a problem (as the question I marked as duplicate states). Of course, if we're talking about thousands of JSON strings, you'll need to index that table (those tables) and that requires either a unique id that's unrelated to the actual data, or parsing the string, and using some properties you could use to query.

    我们在谈论多少个JSON格式的对象?将它们存储为字符串并不是一个很大的问题(因为我标记为重复状态的问题)。当然,如果我们谈论成千上万的JSON字符串,你需要索引该表(那些表)并且需要一个与实际数据无关的唯一id,或者解析字符串,并使用一些属性你可以用来查询。

  • You say the JSON-objects are fairly large (because you're talking about TEXT/BLOB fields) which can hold up to 65k characters... Are you sure you're going to be using even half that amount of chars, 20% of the time?? It does feel like overkill to me, to be honest

    你说JSON对象相当大(因为你在谈论TEXT / BLOB字段),它可以容纳多达65k个字符......你确定你将使用甚至一半的字符,20%的时间??说实话,这对我来说确实有些过分

  • How variable is the JSON's structure? does one object consist of a simple JS-style object literal while the other one is a 7-level-deep nested object? If all objects share a certain structure, you're probably going to be better of building a schema.

    JSON的结构有多变量?一个对象是由一个简单的JS风格的对象文字组成,而另一个是一个7级深的嵌套对象吗?如果所有对象共享某个结构,那么您可能会更好地构建模式。

  • I don't know if you're comfortable with it, or it's an option in your case, but since you're not going to be writing to that table too often, and it's al JSON formatted, why not look into another DB system? It's been a while, but I have worked with mongoDB which could be useful to you.

    我不知道你是否对它感到满意,或者它是你的一个选择,但是因为你不会经常写那个表,并且它是JSON格式的,为什么不调查另一个数据库系统?已经有一段时间了,但我使用的mongoDB可能对你有用。

Recap: If you only have, say, ~10 JSON objects: just store them in a simple table as VARCHARS (or TEXT), add an id field if needs must. If you can, a simple file will do, too, of course. No need to connect to a MySQL server, no need for all that overhead just file_get_contents('JSON_DATA1.json'); can do the trick. Of course, take safety precautions where needed.
If you have tons of objects, build a MySQL schema... unless the objects have truly no similarities as far as format goes (no similar properties @ the same level)
Do take a look at alternatives like mongoDB and, perhaps, other NoSQL DB's. They might be of use to you. Mongo, for example, stores its data in JSON-style documents and is quite easy to work with because of it's JavaScript-like interface.

回顾:如果您只有~10个JSON对象:只需将它们存储在一个简单的表中作为VARCHARS(或TEXT),如果需要必须添加一个id字段。如果可以,一个简单的文件当然也可以。无需连接到MySQL服务器,不需要所有开销只需file_get_contents('JSON_DATA1.json');可以做到这一点。当然,在需要时采取安全预防措施。如果你有大量的对象,那么构建一个MySQL模式......除非这些对象与格式完全没有相似之处(没有类似的属性@同一级别)请看看像mongoDB这样的替代品,也许还有其他NoSQL DB的。它们可能对你有用。例如,Mongo将其数据存储在JSON样式的文档中,因为它具有类似JavaScript的界面,因此很容易使用。