Saving array to database without serializing

3

I am building a social networking website where the user can belong to groups and comment on posts.

I'm trying to save group memberships and comments cleanly to the database, preferably without serializing the arrays, but I'm not finding a way to do so.

I had thought about saving a table with this data within the groups and post lines, but I discovered that this is not possible.

Is there any clean way to save this data or do I really have to serialize user vectors and comments?

    
asked by anonymous 08.09.2014 / 03:05

1 answer

1
Solution 1

Gcanhete, the ideal is to revise your database modeling, there should be a clean way to store the data in the database, preferably obeying the first 3 formal rules.

I understand that the way you want to do now you are wanting to store a bank line for each group and comment, but this is not sustainable, for example, what size field you will use to accommodate this data, the what will you do when there are more comments than you expect?

The ideal is to store so that each comment has its own record, with all relevant information.

If the problem is performance ai is the case of adjusting in other points (indices, cache, etc).

If you still want to store the array inside the database you still have options:

  • Store fully (pass array to string and store it)
    • In this case you still have the benefits of being able to fetch and change and can be direct in SQL as in other languages (for APIs for example).
  • Store serial (pass through serialization)
    • You lose some of the ability to edit and read, since any error can invalidate the information.
  • Encode with Base64 or other reversible algorithms.
Solution 2 Another option if you want to store a non-rigid data structure (such as a relational database) is to use NoSQL banks such as Redis and MongoDB, where you can pass your entire arrays to persistence.

In this second case you can store them and retrieve them practically ready for use.

    
08.09.2014 / 05:29