markdown guide
 

need to store it into database

Scenarios like this is why document-based storage system is best for, but I'm going to assume you can't use document storage. I'm also going to assume you want the data to be normalized, so you can't just stick a blob into a single field and be done with it.

If a single form is associated with a single user, you can have a single table for form answers with columns like:

  • user_id
  • answer_id
  • answer_type
  • answer_type_text_value
  • answer_type_number_value
  • answer_type_date_value
  • answer_type_multi_text_value

Based on the answer type enum (included in this table to try to avoid a join on the answers table to get type), you would store it in the appropriate field value column to preserve types. Add as many field_value_* columns as you need - but keep it to the minimum. If your DB supports array column types you can store multiple-select answers in a single column. If not, and you want it to be normalized, you'll need a few more tables.

Remember that databases are good at storing a lot of data when it's in a single table with only a few columns, so even if your table ends up with millions for records for all of your large forms it should still stay relatively fast with proper indexing.

My morning coffee hasn't kicked in yet, so someone else could probably do better.

 

What format is the data in? What database do you have available?

 
 

Cool, how is the data structured? You might get away by serializing it in JSON on a jsonb column and then load it again.

Classic DEV Post from Jan 14

How To Learn JavaScript

Do you want to learn JavaScript? Here is how to learn JS

Lew Yuburi profile image
Easy code, easy life