Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm React Native - does SORT DISTINCT actually work?

The Realm JavaScript documentation says:

Sorting and find distinct values are possible with functions SORT and DISTINCT, e.g. age > 20 SORT(name ASC, age DESC) DISTINCT(name).

  • The ordering for sorting can be one of the following case insensitive literals: ASC, ASCENDING, DESC, DESCENDING.
  • Any number of properties can appear inside the brackets in a comma separated list.
  • Any number of sort/distinct conditions can be indicated, they will be applied in the specified order.
  • Sort or distinct cannot operate independently, these conditions must be attached to at least one query filter.

I'm trying to use it like this:

realm
  .objects<CardFace>(CardFaceSchema)
  .filtered(`SORT(name ASC, expansion.releaseDate DESC) DISTINCT(name)`)

And get the red screen of death with the following message: SORT(name ASC, expansion.releaseDate DESC) DISTINCT(name):1:4(4): Invalid predicate.

What am I doing wrong? My realm version is 2.3.3

like image 550
sellmeadog Avatar asked Apr 03 '18 19:04

sellmeadog


People also ask

What is realm in React Native App?

We are hoping you have read our previous post on Local Database in React Native App. A realm is an open-source object database management system, initially for mobile, also available for platforms such as Xamarin or React Native, and others, including desktop applications, and is licensed under the Apache License.

How do I get Started with React Native?

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility.

How to sort data in react with ID and name?

If data consist of name and id as attributes then we should be able to sort data with alphabetical order of name or we can also sort according to the increasing or decreasing value of Id. In React it is easy to sort things because of the sort function.

What is a realm in Salesforce?

A realm is an open-source object database management system, initially for mobile, also available for platforms such as Xamarin or React Native, and others, including desktop applications, and is licensed under the Apache License. We can perform all the CRUD transactions in this database and much faster than the SQLite database.


1 Answers

Sort and Distinct can't be applied without a predicate. So modify your filter to:

realm
  .objects<CardFace>(CardFaceSchema)
  .filtered(`TRUEPREDICATE SORT(name ASC, expansion.releaseDate DESC) DISTINCT(name)`)
like image 127
Nikola Irinchev Avatar answered Nov 15 '22 10:11

Nikola Irinchev