0

Hi I a beginner to the web development I wanted to accept n number of the instance(n is inputted by the user) from the user and then store those values in an array-like structure so that my frontend can have access to it. Can this be done using mysql ?. I was reading StackOverflow posts that mentioned that it is not a good idea to use MySQL for this. However I am already kind of deep into my project so I want to clarify this.

Is this feasible using MySQL?

2
  • please clarify your que and share some code what you have did so far .? Commented Jun 19, 2020 at 15:57
  • sure checkout github.com/lcherone/autorm could do await (new database.row('table_name', req.body)).store() though you should always validate inputs Commented Jun 19, 2020 at 20:53

1 Answer 1

2

I guess you want to store something like object or array of something
let's say that in your front end there is a form with input and button where the input is Add More Columns and the input is value so in your backend you will get an array of objects like

[
        { question: '1', answer: 'Answer1' },
        { question: '2', answer: 'Answer2' },
        { question: '3', answer: 'Answer3' },
        { question: '4', answer: 'Answer4' }
]

you can make a table

id | userId | payload

where id is generated by SQL userId that you injected in the token (or something else to relate the user with his payloads) and payload that contains the information that you need to store

const saveUserPayLoads = async (req, res) => {

    const { payloads } = req.body;
    const { id } = req.user
    const data = []
    for(payload of payloads) data.push(DBModule.create({ payload: JSON.stringify(payload), userId: id }))
    return res.status(201).json({
      message: 'Done',
      success: true,
      data
    })

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.