• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

166
Views
Cómo escapar de los apóstrofes usando NodeJS

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?

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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]);
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error