Solucionado (ver solução)
Solucionado
(ver solução)
6
respostas

code: 'ER_PARSE_ERROR', errno: 1064,

class Tabelas {
  init(conexao) {
    this.conexao = conexao

    this.criarAtendimentos()
  }

  criarAtendimentos() {
    const sql =

    'CREATE TABLE IF NOT EXISTS Atendimentos (id in 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

ERRO

[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
conectado com sucesso
consign v0.1.6 Initialized in C:\alura\node-js
+ .\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 'in NOT NULL AUTO_INCREMENT, cliente varchar(50) NOT NULL, pet varchar(20), servi' at line 1
    at Query.Sequence._packetToError (C:\alura\node-js\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
    at Query.ErrorPacket (C:\alura\node-js\node_modules\mysql\lib\protocol\sequences\Query.js:79:18)
    at Protocol._parsePacket (C:\alura\node-js\node_modules\mysql\lib\protocol\Protocol.js:291:23)
    at Parser._parsePacket (C:\alura\node-js\node_modules\mysql\lib\protocol\Parser.js:433:10)
    at Parser.write (C:\alura\node-js\node_modules\mysql\lib\protocol\Parser.js:43:10)
    at Protocol.write (C:\alura\node-js\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (C:\alura\node-js\node_modules\mysql\lib\Connection.js:88:28)
    at Socket.<anonymous> (C:\alura\node-js\node_modules\mysql\lib\Connection.js:526:10)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    --------------------
    at Protocol._enqueue (C:\alura\node-js\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Connection.query (C:\alura\node-js\node_modules\mysql\lib\Connection.js:198:25)
    at Tabelas.criarAtendimentos (C:\alura\node-js\infraestrutura\tabelas.js:13:18)
    at Tabelas.init (C:\alura\node-js\infraestrutura\tabelas.js:5:10)
    at Handshake.<anonymous> (C:\alura\node-js\index.js:11:13)
    at Handshake.<anonymous> (C:\alura\node-js\node_modules\mysql\lib\Connection.js:526:10)
    at Handshake._callback (C:\alura\node-js\node_modules\mysql\lib\Connection.js:488:16)
    at Handshake.Sequence.end (C:\alura\node-js\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
    at Handshake.Sequence.OkPacket (C:\alura\node-js\node_modules\mysql\lib\protocol\sequences\Sequence.js:92:8)
    at Protocol._parsePacket (C:\alura\node-js\node_modules\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 'in NOT NULL AUTO_INCREMENT, cliente varchar(50) NOT NULL, pet varchar(20), servi' at line 1",
  sqlState: '42000',
  index: 0,
  sql: 'CREATE TABLE IF NOT EXISTS Atendimentos (id in 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))'
}

passei a tarde procurando e não consegui uma solução ainda, caso alguem souber agradeço, valeu

6 respostas
solução!

O erro diz que a query SQL que você escreveu não é válida. Por favor, compare a sua string da variável sql com a da aula disponível aqui: https://github.com/alura-cursos/nodejs-api-rest/blob/ab79a5a2b5323f478b323101812f3ac942fdde0a/infraestrutura/tabelas.js#L9

eu copiei o codigo e mesmo assim apresentou o mesmo erro, ele acontece quando manda o "send" do postman.

Na sua versão tá id in NOT NULL (erro de sintaxe do MySQL) e no código que enviei está id int NOT NULL. Não tem como ter dado exatamente o mesmo erro. Cole a mensagem de erro que está dando agora.


PS C:\alura\node-js> npm start

> projeto-nodejs-rest@1.0.0 start
> nodemon index.js

[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
conectado com sucesso
consign v0.1.6 Initialized in C:\alura\node-js
+ .\controllers\atendimentos.js
Servidor rodando na porta 3000
Tabela Atendimentos criada com sucesso
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 (C:\alura\node-js\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
    at Query.ErrorPacket (C:\alura\node-js\node_modules\mysql\lib\protocol\sequences\Query.js:79:18)
    at Protocol._parsePacket (C:\alura\node-js\node_modules\mysql\lib\protocol\Protocol.js:291:23)
    at Parser._parsePacket (C:\alura\node-js\node_modules\mysql\lib\protocol\Parser.js:433:10)
    at Parser.write (C:\alura\node-js\node_modules\mysql\lib\protocol\Parser.js:43:10)
    at Protocol.write (C:\alura\node-js\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (C:\alura\node-js\node_modules\mysql\lib\Connection.js:88:28)
    at Socket.<anonymous> (C:\alura\node-js\node_modules\mysql\lib\Connection.js:526:10)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    --------------------
    at Protocol._enqueue (C:\alura\node-js\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Connection.query (C:\alura\node-js\node_modules\mysql\lib\Connection.js:198:25)
    at Atendimento.adiciona (C:\alura\node-js\models\atendimentos.js:7:17)
    at C:\alura\node-js\controllers\atendimentos.js:11:17
    at Layer.handle [as handle_request] (C:\alura\node-js\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\alura\node-js\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\alura\node-js\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\alura\node-js\node_modules\express\lib\router\layer.js:95:5)
    at C:\alura\node-js\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\alura\node-js\node_modules\express\lib\router\index.js:335: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 '
}

copiei o codigo do models tambem no github, apresenta este erro ai

O erro estava no atendimento.js dei um ctrl C nele e sumiu o erro, mas a unica coisa diferente que eu identifiquei foi as " ; " que eu havia colocado