Привет, у меня есть массив объектов, которые я хотел бы передать на свой сервер (sql сервер).
ниже - массив объектов, это точные результаты из
console.info(results)
Вот массив объектов (это называется результатами)
[0] [
[0] {
[0] answer: 'bmbm,nn',
[0] question: 'Is the keyboard separate from the screen?',
[0] state: 'problem specified'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Does the keyboard tilt?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Is it possible to find a comfortable typing postion?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Do you have a good keyboard technique?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Are the characters on the keyboard clear and readable?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: "Is your mouse or other pointing device suitable to the task you're using it for?",
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'bnmgjvgh',
[0] question: 'Is the mouse (or other pointing device) located sufficently close to you? ',
[0] state: 'Declined with soloution defined'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Does the mouse (or other pointing device) work smoothly at a speed that suits you?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Is there support for your wrist and forearm when using the mouse(or other pointing device)',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Can you easily adjust the software settings for speed and accuracy of the pointer?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Are the characters on your screen clear and readable?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Is the text size on your screen confortable to read?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Is the image on your screen free from flicker and jitter?',
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: "Is your screen's specification suitable for its intended use?",
[0] state: 'Accepted'
[0] },
[0] {
[0] answer: 'yes',
[0] question: 'Is the brightness and/or contrast on your screen adjustable?',
[0] state: 'Accepted'
[0] }
[0] ]
Это то, как я изначально собирался передать его, хотя на мой sql, однако я застрял с логи c как это сделать.
app.post("/post-question-answers", async (req, res) => {
console.log("!called");
try {
let results = req.body.results;
//This is the console.info posted earlier
console.info(results);
await sql.connect(config, function(err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
request.input("Results", sql.VarChar, results);
// query to the database and get the records
request.execute("dbo.StoreAnswers", function(err, recordset) {
if (err) console.log(err);
// send records as a response
res.json(recordset);
});
});
} catch (e) {
console.info(e);
}
res.statusCode = 400;
res.statusMessage = "bad request";
// res.json({ message: "Email Missing" });
});
Все, что мне нужно знать, это как это выполнимо. Нужно ли мне перебирать и вырывать каждую отдельную переменную? Нужно ли использовать пользовательские таблицы в sql? Могу ли я передать объект прямо в базу данных?
Я понятия не имею, что привело к этому, и тратил время на решение этой проблемы.
Пожалуйста, любые советы приветствуются !!!