As tabelas foram criadas no MySQL, porém é apresentado a seguinte mensagem de erro no terminal:
[nodemon] starting node index.js
conectado com sucesso
consign v0.1.6 Initialized in C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto
- .\controllers\atendimentos.js
servidor rodando na porta 3000
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 '(id))' at line 1
at Query.Sequence.packetToError (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\nodemodules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Query.ErrorPacket (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\protocol\sequences\Query.js:79:18)
at Protocol.parsePacket (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\nodemodules\mysql\lib\protocol\Protocol.js:291:23)
at Parser.parsePacket (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\nodemodules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket. (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\Connection.js:88:28)
at Socket. (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (node:events:365:28)
at addChunk (node:internal/streams/readable:314:12)
at Protocol.enqueue (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\nodemodules\mysql\lib\protocol\Protocol.js:144:48) at Connection.query (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\Connection.js:198:25) at Tabelas.criarAtendimentos (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\infraestrutura\tabelas.js:11:21) at Tabelas.init (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\infraestrutura\tabelas.js:5:13) at Handshake. (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\index.js:11:17) at Handshake. (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\Connection.js:526:10) at Handshake.callback (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\nodemodules\mysql\lib\Connection.js:488:16) at Handshake.Sequence.end (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24) at Handshake.Sequence.OkPacket (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\node_modules\mysql\lib\protocol\sequences\Sequence.js:92:8) at Protocol.parsePacket (C:\Users\Brenno\Desktop\DEV\nodeRest\alura\projeto\nodemodules\mysql\lib\protocol\Protocol.js:291:23) { 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 '(id))' at line 1", sqlState: '42000', index: 0, sql: 'CREATE TABLE Atendimentos (id int NOT NULL AUTO_INCREMENT, cliente varchar(50) NOT NULL, pet varchar(20), servico varchar(20) NOT NULL, status varchar(20) NOT NULL, observacoes text PRIMARY KEY(id))' }
CÓDIGO:
class Tabelas {
init(conexao) { this.conexao = conexao
this.criarAtendimentos()
}
criarAtendimentos() { const sql = 'CREATE TABLE Atendimentos (id int NOT NULL AUTO_INCREMENT, cliente varchar(50) NOT NULL, pet varchar(20), servico varchar(20) NOT NULL, status varchar(20) NOT NULL, observacoes text PRIMARY KEY(id))'
this.conexao.query(sql, erro => {
if(erro) {
console.log(erro)
} else {
console.log('Tabela Atendimentos criada com sucesso')
}
})
} }
module.exports = new Tabelas `