Vi que é um erro relatado no fórum a bastante tempo, porém sem nenhuma solução concreta por parte dos instrutores, apenas recomendações para utilizar outros aplicativos de teste. Acredito que o erro esteja no uso do caractere coringa '?'.Já testei com postman, insomnia e plugin Rest Client do Vscode, nenhum funciona. Estou utilizando MySQL Client 8.0
models/atendimentos.js
const conexao = require('../infraestrutura/conexao')
class Atendimento {
adiciona(atendimento) {
const sql = 'INSERT INTO Atendimentos SET ?'
conexao.query(sql, atendimento, (erro, resultados) => {
if(erro) {
console.log(erro)
} else {
console.log(resultados)
}
})
}
}
module.exports = new Atendimento
test.http
get http://localhost:3000
####
post http://localhost:3000/atendimentos/
Content-Type: application/json
{
"cliente": "jardel",
"pet": "ruby",
"servico": "tosa",
"status": "agendado",
"observacoes": "docil"
}
log terminal
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at Query.Sequence._packetToError (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
at Protocol._parsePacket (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/Connection.js:88:28)
at Socket.<anonymous> (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
--------------------
at Protocol._enqueue (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Connection.query (/home/jardel/dev/projeto-nodeapi/node_modules/mysql/lib/Connection.js:198:25)
at Atendimento.adiciona (/home/jardel/dev/projeto-nodeapi/models/atendimentos.js:6:17)
at /home/jardel/dev/projeto-nodeapi/controllers/atendimento.js:10:17
at Layer.handle [as handle_request] (/home/jardel/dev/projeto-nodeapi/node_modules/express/lib/router/layer.js:95:5)
at next (/home/jardel/dev/projeto-nodeapi/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/jardel/dev/projeto-nodeapi/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/jardel/dev/projeto-nodeapi/node_modules/express/lib/router/layer.js:95:5)
at /home/jardel/dev/projeto-nodeapi/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/jardel/dev/projeto-nodeapi/node_modules/express/lib/router/index.js:341:12) {
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1",
sqlState: '42000',
index: 0,
sql: 'INSERT INTO Atendimentos SET '
}