[英]How can I get distinct column values using LoopBack REST API
I have loopback REST API, which returns all the data from MySQL table in JSON format. 我有环回REST API,它以JSON格式返回MySQL表中的所有数据。 But, I want to query or apply filter where it returns only distinct values for a given column.
但是,我想查询或应用过滤器,它只返回给定列的不同值。 For eg in SQL we use this syntax :SELECT DISTINCT column1 FROM table_name;
例如,在SQL中,我们使用以下语法:SELECT DISTINCT column1 FROM table_name; How can I achieve this using LoopBack Rest API?
如何使用LoopBack Rest API实现此目的? Does LoopBack support something like above?
LoopBack是否支持上述内容? Please suggest me any other solution.
请建议我任何其他解决方案。
To my knowledge there is no filter for DISTINCT. 据我所知,DISTINCT没有过滤器。
You can execute the sql
command instead and receive the JSON
object in return 您可以改为执行
sql
命令并接收JSON
对象
var sql = "select DISTINCT name from user";
var ds = {YourModel}.app.datasources.{yourConnectionName};
ds.connector.execute(sql, [], function(err, data) {
// your code here
});
Refer http://loopback.io/doc/en/lb2/Executing-native-SQL.html for more details. 有关详细信息,请参阅http://loopback.io/doc/en/lb2/Executing-native-SQL.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.