Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Parameterized query using TypeORM for postgres database and nodejs as the application's back-end server

I want to fetch the rows from a postgres table where name = SUPREME INT'L, Note: this string has a single quote in between the name characters. I am using TypeORM as an ORM, POSTGRESQL as the database.

My query:

 import { getConnection } from 'typeorm';
 const connection =  getConnection();

 var query = `SELECT * from skusimulations where "name"= ? `;
 const output =await connection.query(query, ['SUPREME INT'L']) 

I am getting error while executing this, I want to escape the single quote by using stored proc.

Any help would be highly appreciated.

like image 748
Rohan Kumar Avatar asked Jul 01 '26 14:07

Rohan Kumar


1 Answers

I changed a few things by referring to the typeorm.io docs.

Final changes:

  var name = "SUPREME INT'L" ;
  var query = `SELECT * from skusimulations where "skuId"= $1 `;
  var skuData =await connection.query(query, [name])
like image 185
Rohan Kumar Avatar answered Jul 03 '26 04:07

Rohan Kumar