-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filter data descriptions, Fluent interface and LINQ
- Loading branch information
Showing
14 changed files
with
1,153 additions
and
9 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
source/includes/api-details/cpp/crud/read-filter-or-query-objects-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
To filter data, call the ``.where()`` function on a collection with a valid | ||
query. Currently, C++ supports only a subset of RQL operators. | ||
|
||
Supported Query Operators | ||
````````````````````````` | ||
|
||
C++ supports the following query operators: | ||
|
||
- Equality (``==``, ``!=``) | ||
- Greater than/less than (``>``, ``>=``, ``<``, ``<=``) | ||
- Compound queries (``||``, ``&&``) |
38 changes: 38 additions & 0 deletions
38
...e/includes/api-details/csharp/crud/read-filter-or-query-objects-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
To query, filter, and sort data in the database, use the SDK query engine. | ||
There are two ways to use the query engine with C#: | ||
|
||
- :ref:`LINQ Syntax <sdks-dotnet-linq>` | ||
- :ref:`Realm Query Language (RQL) <realm-query-language>` | ||
|
||
Use LINQ syntax for querying when possible, as it provides compile-time checks | ||
for queries and aligns with .NET conventions. | ||
|
||
Filter Data with LINQ | ||
````````````````````` | ||
|
||
To filter data with LINQ syntax, call the :dotnet-sdk:`Where() | ||
<linqsupport.html#restriction-operators>` operator with a | ||
:dotnet-sdk:`Predicate <linqsupport.html#predicate-operations>` that describes | ||
the subset of data you want to access. | ||
|
||
.. literalinclude:: /examples/generated/dotnet/QueryEngineExamples.snippet.logical.cs | ||
:language: csharp | ||
|
||
Filter Data with RQL | ||
```````````````````` | ||
|
||
You can also use the :ref:`Realm Query Language <realm-query-language>` (RQL) | ||
to query realms. RQL is a string-based query language used to access the query | ||
engine. When using RQL, you use the | ||
:dotnet-sdk:`Filter() <reference/Realms.CollectionExtensions.html?q=Filter>` | ||
method: | ||
|
||
.. literalinclude:: /examples/generated/dotnet/QueryEngineExamples.snippet.rql.cs | ||
:language: csharp | ||
|
||
.. important:: | ||
|
||
Because :ref:`LINQ <sdks-dotnet-linq>` provides compile-time error checking | ||
of queries, you should use it instead of RQL in most cases. If you require | ||
features beyond LINQ's current capabilities, such as using | ||
:ref:`aggregation <rql-aggregate-operators>`, use RQL. |
8 changes: 8 additions & 0 deletions
8
source/includes/api-details/dart/crud/read-filter-or-query-objects-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Filter a collection to retrieve a specific segment of objects with the | ||
:flutter-sdk:`Realm.query() <realm/Realm/query.html>` method. In the | ||
``query()`` method's argument, use RQL to perform filtering. | ||
|
||
.. literalinclude:: /examples/generated/flutter/read_write_data_test.snippet.filter.dart | ||
:language: dart | ||
|
||
You can use iterable arguments in your filter. |
32 changes: 32 additions & 0 deletions
32
...ncludes/api-details/java/crud/read-filter-or-query-objects-java-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
In Java, you can filter objects with either the Fluent interface or RQL. | ||
|
||
Filter Data with Fluent Interface | ||
````````````````````````````````` | ||
|
||
To filter data with the Fluent interface, filter data with a | ||
:java-sdk:`RealmQuery <io/realm/RealmQuery.html>`. For more details, refer | ||
to :ref:`Fluent interface <sdks-java-filter-data>`. | ||
|
||
In the following example, we use the Fluent interface comparison operators to: | ||
|
||
- Find high priority tasks by comparing the value of the ``priority`` property value with a threshold number, above which priority can be considered high. | ||
- Find just-started or short-running tasks by seeing if the ``progressMinutes`` property falls within a certain range. | ||
- Find unassigned tasks by finding tasks where the ``assignee`` property is equal to null. | ||
- Find tasks assigned to specific teammates Ali or Jamie by seeing if the ``assignee`` property is in a list of names. | ||
|
||
.. literalinclude:: /examples/generated/java/sync/ReadsTest.snippet.filter-results.java | ||
:language: java | ||
:copyable: false | ||
|
||
Filter Data with RQL | ||
```````````````````` | ||
|
||
To filter data with RQL, use :java-sdk:`RealmQuery.rawPredicate() | ||
<io/realm/RealmQuery.html#rawPredicate-java.lang.String->`. | ||
For more information about syntax, usage and limitations, | ||
refer to the :ref:`Realm Query Language reference <realm-query-language>`. | ||
|
||
RQL can use either the class and property names defined in your SDK model | ||
classes or the internal names defined with ``@RealmField``. You can combine | ||
raw predicates with other raw predicates or type-safe predicates created with | ||
``RealmQuery``. |
33 changes: 33 additions & 0 deletions
33
...ludes/api-details/java/crud/read-filter-or-query-objects-kotlin-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
In Java or Kotlin (Java SDK), you can filter objects with either the | ||
Fluent interface or RQL. | ||
|
||
Filter Data with Fluent Interface | ||
````````````````````````````````` | ||
|
||
To filter data with the Fluent interface, filter data with a | ||
:java-sdk:`RealmQuery <io/realm/RealmQuery.html>`. For more details, refer | ||
to :ref:`Fluent interface <sdks-java-filter-data>`. | ||
|
||
In the following example, we use the Fluent interface comparison operators to: | ||
|
||
- Find high priority tasks by comparing the value of the ``priority`` property value with a threshold number, above which priority can be considered high. | ||
- Find just-started or short-running tasks by seeing if the ``progressMinutes`` property falls within a certain range. | ||
- Find unassigned tasks by finding tasks where the ``assignee`` property is equal to null. | ||
- Find tasks assigned to specific teammates Ali or Jamie by seeing if the ``assignee`` property is in a list of names. | ||
|
||
.. literalinclude:: /examples/generated/java/sync/ReadsTest.snippet.filter-results.kt | ||
:language: kotlin | ||
:copyable: false | ||
|
||
Filter Data with RQL | ||
```````````````````` | ||
|
||
To filter data with RQL, use :java-sdk:`RealmQuery.rawPredicate() | ||
<io/realm/RealmQuery.html#rawPredicate-java.lang.String->`. | ||
For more information about syntax, usage and limitations, | ||
refer to the :ref:`Realm Query Language reference <realm-query-language>`. | ||
|
||
RQL can use either the class and property names defined in your SDK model | ||
classes or the internal names defined with ``@RealmField``. You can combine | ||
raw predicates with other raw predicates or type-safe predicates created with | ||
``RealmQuery``. |
10 changes: 10 additions & 0 deletions
10
.../api-details/javascript/crud/read-filter-or-query-objects-js-ts-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
To filter a query, call :js-sdk:`filtered() | ||
<classes/Results.html#filtered>` on the query results collection. | ||
Pass a Realm Query Language query as argument to ``filtered()``. | ||
|
||
In the following example, we use RQL comparison operators to: | ||
|
||
- Find high priority tasks by comparing the value of the ``priority`` property | ||
value with a threshold number, above which priority can be considered high. | ||
- Find just-started or short-running tasks by seeing if the ``progressMinutes`` | ||
property falls within a certain range. |
6 changes: 6 additions & 0 deletions
6
...e/includes/api-details/kotlin/crud/read-filter-or-query-objects-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
To filter by property, you can pass Realm Query Language (RQL) filters and | ||
operators, use Kotlin's built-in extension methods or the SDK's convenience | ||
methods, or use a combination. | ||
|
||
In the following example, we query a ``Frog`` object type and filter by the | ||
``name`` property. |
6 changes: 6 additions & 0 deletions
6
...cludes/api-details/objectivec/crud/read-filter-or-query-objects-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
To filter results in Objective-C, call :objc-sdk:`-[RLMResults objectsWhere:] | ||
<Classes/RLMResults.html#/c:objc(cs)RLMResults(im)objectsWhere:>` | ||
with a query predicate. | ||
|
||
For more details about the supported operators available for Objective-C | ||
queries, refer to :ref:`sdks-nspredicate-query`. |
29 changes: 29 additions & 0 deletions
29
...ce/includes/api-details/swift/crud/read-filter-or-query-objects-description.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Swift has its own query APIs that use either the type-safe ``where`` syntax, | ||
or a string ``NSPredicate`` query. For more details about the supported | ||
operators available for Swift queries, refer to :ref:`sdks-filter-data-swift`. | ||
|
||
Type-Safe Queries | ||
````````````````` | ||
|
||
To use the :ref:`Realm Swift Query API <ios-realm-swift-query-api>`, call | ||
:swift-sdk:`.where <Structs/Query.html>` with a closure that contains a query | ||
expression as an argument. | ||
|
||
This query API provides compile-time type-safe query checking. Prefer using | ||
this API over the older string-based ``NSPredicate`` API. | ||
|
||
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.where.swift | ||
:language: swift | ||
|
||
NSPredicate Queries | ||
``````````````````` | ||
|
||
To filter with the older string-based ``NSPredicate`` API, call | ||
:swift-sdk:`Results.filter(_:) | ||
<Structs/Results.html#/s:10RealmSwift7ResultsV6filteryACyxGSo11NSPredicateCF>` | ||
with a query predicate. | ||
|
||
Prefer using the type-safe query API unless you are using an SDK version | ||
older than 10.19.0. The string-based ``NSPredicate`` query API does not provide | ||
compile-time checking for valid query syntax, and may crash at runtime with | ||
an invalid ``NSPredicate``. |
63 changes: 63 additions & 0 deletions
63
source/includes/sdk-examples/crud/read-filter-or-query-objects.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
.. tabs-drivers:: | ||
|
||
tabs: | ||
- id: cpp-sdk | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/cpp/crud.snippet.filter-using-type-safe-query.cpp | ||
:language: cpp | ||
|
||
- id: csharp | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/dotnet/QueryEngineExamples.snippet.rql.cs | ||
:language: csharp | ||
|
||
- id: dart | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/flutter/read_write_data_test.snippet.filter-iterable.dart | ||
:language: dart | ||
|
||
- id: java | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/java/local/FilterDataTest.snippet.realm-query-language.java | ||
:language: java | ||
|
||
- id: java-kotlin | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/java/local/FilterDataTest.snippet.realm-query-language.kt | ||
:language: kotlin | ||
|
||
- id: javascript | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/node/read-and-write-data.snippet.read-and-write-filter-queries.js | ||
:language: javascript | ||
|
||
- id: kotlin | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.query-by-property.kt | ||
:language: kotlin | ||
|
||
- id: objectivec | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/code/start/ReadWriteData.snippet.filter.m | ||
:language: objectivec | ||
|
||
- id: swift | ||
content: | | ||
|
||
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.filter.swift | ||
:language: swift | ||
|
||
- id: typescript | ||
content: | | ||
|
||
.. literalinclude:: /examples/MissingPlaceholders/example.ts | ||
:language: typescript | ||
:copyable: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.