Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Problema para actualizar la tabla mysql con una matriz de objetos js

Tengo un proyecto personal que usa React.js para el front-end, Node.js/express para el back-end y mi base de datos es mySQL.

Tengo esta matriz:

 horaires = [ { jour: 'Lundi', horaire: 'Fermé' }, { jour: 'Mardi', horaire: 'Fermé' }, { jour: 'Mercredi', horaire: 'Fermé' }, { jour: 'Jeudi', horaire: 'Fermé' }, { jour: 'Vendredi', horaire: 'Fermé' }, { jour: 'Samedi', horaire: 'Fermé' }, { jour: 'Dimanche', horaire: 'Fermé' } ]

Y me gustaría actualizar mi tabla de "horaires" con estos nuevos valores. Esta tabla se ve así:

 +----+----------+-----------+ | id | jour | horaire | +----+----------+-----------+ | 1 | Lundi | Fermé | | 2 | Mardi | 18h - 21h | | 3 | Mercredi | 18h - 21h | | 4 | Jeudi | 18h - 21h | | 5 | Vendredi | 18h - 21h | | 6 | Samedi | 18h - 21h | | 7 | Dimanche | Fermé | +----+----------+-----------+

Traté de TRUNCAR y luego INSERTAR, traté de ACTUALIZAR... Traté de formatear mi matriz con reductor para usarla en mi solicitud:

 const newHoraires = horaires.reduce((acc, current, index) => { const newArray = []; newArray.push(index); newArray.push(current.jour); newArray.push(current.horaire); acc.push(newArray); return acc; }, []); // Output => newHoraires [ [ 0, 'Lundi', 'Fermé' ], [ 1, 'Mardi', 'Fermé' ], [ 2, 'Mercredi', 'Fermé' ], [ 3, 'Jeudi', 'Fermé' ], [ 4, 'Vendredi', 'Fermé' ], [ 5, 'Samedi', 'Fermé' ], [ 6, 'Dimanche', 'Fermé' ] ]

Tengo este error la mayor parte del tiempo: tiene un error en su sintaxis SQL; Consulte el manual que corresponde a la versión de su servidor MySQL para conocer la sintaxis correcta para usar cerca de '0, 'Lundi', 'Fermé' en la línea 1.

¿Cómo puedo formatear mi matriz para TRUNCAR y luego INSERTAR? ¿O ACTUALIZAR mi tabla actual con nuevos valores? ¿Cuál sería la mejor práctica?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Usa map() , no reduce() .

 const newHoraires = horaires.map(({jour, horaire}, index) => [index, jour, horaire])
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!