user2301
user2301

Reputation: 1967

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. But, I want to query or apply filter where it returns only distinct values for a given column. For e.g in SQL we use this syntax :SELECT DISTINCT column1 FROM table_name; How can I achieve this using LoopBack Rest API? Does LoopBack support something like above? Please suggest me any other solution.

Upvotes: 1

Views: 1647

Answers (1)

itssajan
itssajan

Reputation: 830

To my knowledge there is no filter for DISTINCT.

You can execute the sql command instead and receive the JSON object in return

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.

Upvotes: 1

Related Questions