Home > Net >  Missing initializer in destructing declaration / identifier 'name' has already been declar
Missing initializer in destructing declaration / identifier 'name' has already been declar

Time:11-03

When I try to insert keys as params i receve this errors on nodemon: SyntaxError: Identifier 'name' has already been declared

this is my function on model:

const create = async (name, about, site) => {
    const sql = 'INSERT INTO client (name, about, site) VALUES (?, ?, ?)', [name, about, site];
    const [result] = await connection.execute(sql);
    return result;
};

and my route:

router.post('/', async (req, res) => {
  const { name, about, site } = req.body;
  const data = await create(name, about, site);
  res.status(200).json(data);
})

this is my first crud. how i resolve this errors?

CodePudding user response:

You cannot assign both the SQL string and the parameters array to one constant sql. What you probably mean is

const create = async (name, about, site) => {
  const [result] = await connection.execute(
    'INSERT INTO client (name, about, site) VALUES (?, ?, ?)',
    [name, about, site]
  );
  return result;
};
  • Related