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
Atendimento Controler
const Attendance = require('../models/attendance')
module.exports = app => {
app.get('/attendance', (req, res) => res.send("Rota de atendimento! Utilizando o GET"))
app.post('/attendance', (req,res) => {
const attendance = req.body
Attendance.add(attendance)
res.send("Rota de atendimento! Utilizando o POST")
})
}
Atendimento Models
const connection = require('../sql/connection')
class Attendance{
add(attendance){
const sql = 'INSERT INTO Attendance SET ?'
connection.query(sql, attendance ,(erro, result) => {
if(erro){
console.log(erro)
} else {
console.log('Atendimento enviado', result)
}
})
}
}
module.exports = new Attendance
class Tables{
init(connection){
this.connection = connection;
this.createAttendance()
}
createAttendance(){
const sql = "CREATE TABLE IF NOT EXISTS Attendance (id int NOT NULL AUTO_INCREMENT, cliente varchar(50) NOT NULL, pet varchar(50), serviço varchar(20) NOT NULL, status varchar(20) NOT NULL, observacoes text, PRIMARY KEY(id))"
this.connection.query(sql, erro => {
if(erro){
console.log("ERRO: ", erro)
} else {
console.log("Tabela de atendimento criada com sucesso!")
}
})
}
}
module.exports = new Tables
const customExpress = require('./config/customExpress')
const connection = require('./sql/connection')
const Tables = require('./sql/tables')
connection.connect(erro => {
if(erro){
console.log(erro)
} else {
console.log('conectado com sucesso!')
app.listen(3000, () => console.log("Servidor rodando na porta: 3000, da URL: http://localhost"))
app.get('/', (req, res) => res.send("Home Funcionando!"))
Tables.init(connection)
}
})
const app = customExpress()