Estoy tratando de actualizar una columna en mi base de datos PostgresQL usando Nodejs:
res.rows.forEach((tmdbID) => { (async () => { const json = await fetchMovieData(tmdbID.tmdb_id); const overview = json.overview.replace('\'', '\\\''); console.log(overview); pool.query(`UPDATE "Movie" SET overview = '${overview}' WHERE tmdb_id = ${json.id}`); })(); });
async function fetchMovieData(tmdbID) { const response = await fetch(`https://api.themoviedb.org/3/movie/${tmdbID}?api_key=a8f7039633f2065942cd8a28d7cadad4&language=en-US`); const data = response.json(); return data; }
El error que estoy recibiendo:
(nodo: 1412) UnhandledPromiseRejectionWarning: error: error de sintaxis en o cerca de "s"
Sucede en esta cadena:
The Bride unwaveringly continues on her roaring rampage of revenge against the band of assassins who had tried to kill her and her unborn child. She visits each of her former associates one-by-one, checking off the victims on her Death List Five until there \'s nothing left to do … but kill Bill.
Estoy tratando de escapar del '
pero parece que no funciona. ¿Algun consejo?
No intente pasar todo como una cadena, así es como ocurre la inyección SQL. Un mejor enfoque es usar parámetros.
No estoy exactamente seguro de qué biblioteca está usando, pero la sintaxis debería ser algo similar a esto:
pool.query('UPDATE "Movie" SET overview = ? WHERE tmdb_id = ?', [overview, json.id]);