如何使用 TypeORM 的参数化查询作为 postgres 数据库和 nodejs 作为应用程序的后端服务器 [英] How to use Parameterized query using TypeORM for postgres database and nodejs as the application's back-end server

查看:152
本文介绍了如何使用 TypeORM 的参数化查询作为 postgres 数据库和 nodejs 作为应用程序的后端服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 name = SUPREME INT'L 的 postgres 表中获取行,注意:此字符串在名称字符之间有一个单引号.我使用 TypeORM 作为 ORM,使用 POSTGRESQL 作为数据库.

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.

我的查询:

 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.

任何帮助将不胜感激.

推荐答案

SOLVED:感谢您抽出时间回答我的问题,我真的很感激.我通过参考 typeorm.io 文档更改了一些内容.最后的变化:-

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])

这篇关于如何使用 TypeORM 的参数化查询作为 postgres 数据库和 nodejs 作为应用程序的后端服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆