使用 NestJS 执行自定义查询的正确方法是什么?
What is the correct way to execute a custom query with 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,
});
我刚刚开始使用 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,
});