我已经开始在环回4中工作。我已经创建了一个具有基本CRUD操作的默认CRUD控制器,该控制器可以获取“表数据”,“特定ID的表记录”等。我现在需要的是对这个表执行我自己的查询。如何在控制器中编写查询并执行它?
下面的/ *是获取表数据的默认功能* /
@get('/customers', {
responses: {
'200': {
description: 'Array of customers model instances',
content: {
'application/json': {
schema: {type: 'array', items: {'x-ts-type': Customers}},
},
},
},
},
})
async find(
@param.query.object('filter', getFilterSchemaFor(Customers)) filter?: Filter,
: Promise<Customers[]> {
if (limit > 100) limit = 100; // your logic
return await this.CustomersRepository.find(filter);
}
我想要的代码类型是
Execute(数据集,sqlstatement); //有空吗?
答案 0 :(得分:1)
pull request #2681最近添加了对执行原始数据库查询的支持,此功能由Repository
方法execute
提供。
请注意,它们的查询格式是特定于连接器的。例如,如果您使用的是MySQL数据库,则可以编写以下查询:
await this.CustomersRepository.execute(
// the query template, use "?" for variables to AVOID SQL INJECTIONS ATTACKS!
'SELECT TOP ? * FROM CUSTOMERS',
// the values to use for variables
[limit]);