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

你离开我真会死。 提交于 2021-02-18 18:08:25

问题


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.


回答1:


SOLVED: Thanks for giving your time to my question, I really appreciate it. 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])


来源:https://stackoverflow.com/questions/54684928/how-to-use-parameterized-query-using-typeorm-for-postgres-database-and-nodejs-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!