sql - 使用 NestJS 执行自定义查询的正确方法是什么?
问题描述
我刚刚开始使用 NestJS。我在这里遵循了 sequelize 数据库示例https://docs.nestjs.com/recipes/sql-sequelize。这在使用模型时很棒,但是执行与此类似的自定义查询的 NestJS 方法是什么。
res = await this.sequelize.query(
`
select * from my_table where id=$id
`,
{
bind: {
id: id,
},
type: QueryTypes.SELECT,
transaction,
},
解决方案
你有 Sequelize 连接实例作为提供者,所以你可以尝试这样的事情:
return this.catsRepository.query('select * from my_table where id=$id',
{
bind: {
id: id,
},
type: QueryTypes.SELECT,
transaction,
});
推荐阅读
- php - 我怎样才能改变css的特性?
- python - Python Selenium rel=nofollow 链接
- python - 如何在 QScintilla 中实现基于缩进的代码折叠?
- wpf - XAML 属性编辑器中的 WPF Enum Flags Dependency 属性
- java - 表达式中的优先级,包括 java 中的括号和 int 类型转换
- google-apps-script - 根据匹配用新数据更新记录
- swift - Swift:本地通知提前 1 小时安排
- swift - Swift 4- http 请求发布以登录网站
- functional-programming - 排序 SML 列表中的问题
- angular - 返回BMI大于30的角管