Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 Respuestas
Responde la pregunta

0

Usa map() , no reduce() .

 const newHoraires = horaires.map(({jour, horaire}, index) => [index, jour, horaire])
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda