Skip to content

Commit e83ceb0

Browse files
committed
Add info about sectioned results and projections
1 parent c12d8b9 commit e83ceb0

7 files changed

+178
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The selected language does not currently support the class projection APIs.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The selected language does not currently support the sectioned results APIs.
2+
Instead, you can manually define logic to display only a subset of query
3+
results based on the needs of your app.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The documentation does not currently have information for how to query
2+
class projections in Objective-C.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
In Objective-C, you can create a :objc-sdk:`RLMSectionedResults
2+
<Classes/RLMSectionedResults.html>` type-safe collection in two ways:
3+
4+
- Using a keyPath: :objc-sdk:`-sectionedResultsSortedUsingKeyPath:ascending:keyBlock:
5+
<Protocols/RLMCollection.html#/c:objc(pl)RLMCollection(im)sectionedResultsSortedUsingKeyPath:ascending:keyBlock:>`
6+
- Using a sort descriptor: :objc-sdk:`-sectionedResultsUsingSortDescriptors:keyBlock:
7+
<Protocols/RLMCollection.html#/c:objc(pl)RLMCollection(im)sectionedResultsUsingSortDescriptors:keyBlock:>`
8+
9+
You can get a count of the sections, get a list of keys, or access an individual
10+
:objc-sdk:`RLMSectionedResult segment <Protocols/RLMSectionedResult.html>` by
11+
key or index.
12+
13+
You can :ref:`observe <sdks-react-to-changes>` ``RLMSectionedResults`` and
14+
``RLMSectionedResult`` instances.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
To query for class projections, pass the metatype instance
2+
``YourProjectionName.self`` to :swift-sdk:`Realm.objects(_:)
3+
<Structs/Realm.html#/s:10RealmSwift0A0V7objectsyAA7ResultsVyxGxmSo0aB6ObjectCRbzlF>`.
4+
This returns a :swift-sdk:`Results <Structs/Results.html>` object
5+
representing all of the class projection objects in the database.
6+
7+
.. literalinclude:: /examples/generated/code/start/ClassProjection.snippet.retrieve-data-through-class-projection.swift
8+
:language: swift
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
For example, you might add a computed variable to your object to get the
2+
first letter of the ``name`` property:
3+
4+
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.sectioned-result-variable.swift
5+
:language: swift
6+
7+
Then, you can create a :swift-sdk:`SectionedResults <Structs/SectionedResults.html>`
8+
type-safe collection for that object, and use it to retrieve objects sectioned
9+
by that computed variable:
10+
11+
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.get-sectioned-results.swift
12+
:language: swift
13+
14+
You can get a count of the sections, get a list of keys, or access an individual
15+
:swift-sdk:`ResultSection <Structs/ResultsSection.html>` by index:
16+
17+
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.section-query-results.swift
18+
:language: swift
19+
20+
You can also section using a callback. This enables you to section a
21+
collection of primitives, or have more control over how the section key is
22+
generated.
23+
24+
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.section-query-results-callback.swift
25+
:language: swift
26+
27+
You can :ref:`observe <sdks-react-to-changes>` ``SectionedResults`` and
28+
``ResultsSection`` instances, and both conform to
29+
:swift-sdk:`ThreadConfined <Protocols/ThreadConfined.html>`.

source/sdk/crud/read.txt

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,132 @@ specified numerical property or collection.
766766
Section Query Results
767767
~~~~~~~~~~~~~~~~~~~~~
768768

769+
Some of the SDK languages provide an API to split results collections into
770+
individual sections. Each section corresponds to a key generated from a
771+
property on the object it represents. This simplifies working with logical
772+
subsets of query results.
773+
774+
.. tabs-drivers::
775+
776+
.. tab::
777+
:tabid: cpp-sdk
778+
779+
.. include:: /includes/api-details/generic/crud/read-section-query-results-not-supported.rst
780+
781+
.. tab::
782+
:tabid: csharp
783+
784+
.. include:: /includes/api-details/generic/crud/read-section-query-results-not-supported.rst
785+
786+
.. tab::
787+
:tabid: dart
788+
789+
.. include:: /includes/api-details/generic/crud/read-section-query-results-not-supported.rst
790+
791+
.. tab::
792+
:tabid: java
793+
794+
.. include:: /includes/api-details/generic/crud/read-section-query-results-not-supported.rst
795+
796+
.. tab::
797+
:tabid: java-kotlin
798+
799+
.. include:: /includes/api-details/generic/crud/read-section-query-results-not-supported.rst
800+
801+
.. tab::
802+
:tabid: javascript
803+
804+
.. include:: /includes/api-details/generic/crud/read-section-query-results-not-supported.rst
805+
806+
.. tab::
807+
:tabid: kotlin
808+
809+
.. include:: /includes/api-details/generic/crud/read-section-query-results-not-supported.rst
810+
811+
.. tab::
812+
:tabid: objectivec
813+
814+
.. include:: /includes/api-details/objectivec/crud/read-section-query-results-description.rst
815+
816+
.. tab::
817+
:tabid: swift
818+
819+
.. include:: /includes/api-details/swift/crud/read-section-query-results-description.rst
820+
821+
.. tab::
822+
:tabid: typescript
823+
824+
.. include:: /includes/api-details/generic/crud/read-section-query-results-not-supported.rst
825+
769826
.. _sdks-read-query-projections:
770827

771828
Query Projections
772829
~~~~~~~~~~~~~~~~~
773830

831+
If your app defines a :ref:`class projection <sdks-define-model-projection>`
832+
to work with persisted data in a different way in a view model or based on
833+
certain business logic, you can query on that projection.
834+
835+
.. tabs-drivers::
836+
837+
.. tab::
838+
:tabid: cpp-sdk
839+
840+
.. include:: /includes/api-details/generic/crud/read-query-projections-not-supported.rst
841+
842+
.. tab::
843+
:tabid: csharp
844+
845+
.. include:: /includes/api-details/generic/crud/read-query-projections-not-supported.rst
846+
847+
.. tab::
848+
:tabid: dart
849+
850+
.. include:: /includes/api-details/generic/crud/read-query-projections-not-supported.rst
851+
852+
.. tab::
853+
:tabid: java
854+
855+
.. include:: /includes/api-details/generic/crud/read-query-projections-not-supported.rst
856+
857+
.. tab::
858+
:tabid: java-kotlin
859+
860+
.. include:: /includes/api-details/generic/crud/read-query-projections-not-supported.rst
861+
862+
.. tab::
863+
:tabid: javascript
864+
865+
.. include:: /includes/api-details/generic/crud/read-query-projections-not-supported.rst
866+
867+
.. tab::
868+
:tabid: kotlin
869+
870+
.. include:: /includes/api-details/generic/crud/read-query-projections-not-supported.rst
871+
872+
.. tab::
873+
:tabid: objectivec
874+
875+
.. include:: /includes/api-details/objectivec/crud/read-query-projections-missing-description.rst
876+
877+
.. tab::
878+
:tabid: swift
879+
880+
.. include:: /includes/api-details/swift/crud/read-query-projections-description.rst
881+
882+
.. tab::
883+
:tabid: typescript
884+
885+
.. include:: /includes/api-details/generic/crud/read-query-projections-not-supported.rst
886+
887+
.. tip::
888+
889+
Don't do derived queries on top of class projection results. Instead, run a
890+
query against the SDK object directly and then project the result. If you
891+
try to do a derived query on top of class projection results, querying a
892+
field with the same name and type as the original object works, but querying
893+
a field with a name or type that isn't in the original object fails.
894+
774895
.. _sdks-read-filter-by-property-type:
775896

776897
Filter by Property Type

0 commit comments

Comments
 (0)