Answer the question
In order to leave comments, you need to log in
How to correctly store data from an array in a Mysql database?
there are Javascript objects with different properties and methods. These objects are instantiated. These instances are placed in arrays when created. The question is what is the best way to save the data of these objects in the database. For example, there are "projects" objects that have properties "project id", "project name", "project creation date", etc. What is the best way to store this data?
Answer the question
In order to leave comments, you need to log in
I would store this only in JSON (well, "everywhere present" properties, of course, can be taken out separately and even assigned types to each line in order to distinguish them). Easy on the front - toString/JSON.parse, also on the back. Only here it is necessary to protect against injections, keep the rear covered =))
Array data can be serialized into a byte array using MsgPack/ProtoBuf/etc. and store in a BLOB column. Provided that the array does not need to be searched using SQL.
After it became known that it is necessary to search through an array of objects, I recommend creating entities corresponding to these objects in order to search them using SQL tools.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question