Skip to content

Commit f8f71d7

Browse files
committed
Add details about collection types
1 parent e83ceb0 commit f8f71d7

22 files changed

+525
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
You can iterate and check the values of a realm :cpp-sdk:`map property
2+
<structrealm_1_1managed_3_01std_1_1map_3_01std_1_1string_00_01T_01_4_00_01void_01_4.html>`
3+
as you would a standard C++ `map <https://en.cppreference.com/w/cpp/container/map>`__.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
You can iterate, check the size of a set, and find values in a
2+
:cpp-sdk:`set property
3+
<structrealm_1_1managed_3_01std_1_1set_3_01T_01_5_01_4_01_4.html>`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Get a ``RealmMap`` by property name with
2+
:flutter-sdk:`dynamic.getMap() <realm//DynamicRealmObject/getMap.html>`
3+
4+
The following example demonstrates some basic usage of ``RealmMap``.
5+
For more information about all available methods, refer to the
6+
:flutter-sdk:`RealmMap reference <realm/RealmMap-class.html>` documentation.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Get a ``RealmList`` by property name with
2+
:flutter-sdk:`dynamic.getList() <realm//DynamicRealmObject/getList.html>`.
3+
4+
The following example demonstrates some basic usage of ``RealmList``.
5+
For more information about all available methods, refer to the
6+
:flutter-sdk:`RealmList reference <realm/RealmList-class.html>` documentation.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Get a ``RealmSet`` by property name with
2+
:flutter-sdk:`dynamic.getSet() <realm//DynamicRealmObject/getSet.html>`.
3+
4+
The following example demonstrates some basic usage of ``RealmSet``.
5+
For more information about all available methods, refer to the
6+
:flutter-sdk:`RealmSet reference <realm/RealmSet-class.html>` documentation.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Check if the dictionary contains an specific key:
2+
:java-sdk:`containsKey() <io/realm/RealmDictionary.html#containsKey-String->`
3+
- Check if the dictionary contains a specific value:
4+
:java-sdk:`containsValue() <io/realm/RealmDictionary.html#containsValue-Object->`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
``RealmSet`` implements Java's ``Set`` interface, so it works just like the
2+
built-in ``HashSet`` class, except managed ``RealmSet`` instances persist
3+
their contents to a database instance. ``RealmSet`` instances that contain SDK
4+
objects actually only store references to those objects, so deleting an
5+
SDK object from a database instance also deletes that object from
6+
any ``RealmSet`` instances that contain the object.
7+
8+
Because ``RealmSet`` implements ``RealmCollection``, it has some useful
9+
mathematical methods, such as ``sum``, ``min``, and ``max``. For a complete
10+
list of available ``RealmSet`` methods, see: :java-sdk:`the RealmSet API
11+
reference <io/realm/RealmSet.html>`.
12+
13+
- Check if the set contains a specific object with
14+
:java-sdk:`RealmSet.contains() <io/realm/RealmSet.html#contains-Object->`
15+
- Check if the set contains all of multiple objects with
16+
:java-sdk:`RealmSet.containsAll() <io/realm/RealmSet.html#containsAll-Collection->`
17+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
To filter a query, run :js-sdk:`collection.filtered()
2+
<classes/OrderedCollection.html#filtered>` to specify a subset of results
3+
based on the value(s) of one or more object properties. You can specify
4+
results based on the value of a dictionary's properties by using
5+
:mdn:`bracket-notation <Web/JavaScript/Reference/Operators/Property_accessors>`.
6+
7+
You can also determine whether a results collection has a certain key or value
8+
by using ``<dictionary>.@keys`` or ``<dictionary>.@values``. For instance, if
9+
you had a ``Person`` collection with a nested ``home`` dictionary, you could
10+
return all ``Person`` objects with a ``home`` with a ``"price"`` property by
11+
running the query: ``home.@keys = "price"``.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Sets allow you to perform math operations such as finding the union,
2+
intersection, or difference between two sets. To learn more about performing
3+
these operations, see the MDN docs for :mdn:`Implementing basic set operations
4+
<Web/JavaScript/Reference/Global_Objects/Set#implementing_basic_set_operations>`.
5+
6+
To determine if a set contains a particular value, pass the value to the
7+
``<Realm.Set>.has()`` method. The ``set.has()`` method will return true if the
8+
set contains the value specified.
9+
10+
.. literalinclude:: /examples/generated/node/data-types.snippet.check-if-set-has-items.js
11+
:language: javascript
12+
13+
To discover how many items are in a set, you can check the set's ``size``
14+
property.
15+
16+
.. literalinclude:: /examples/generated/node/data-types.snippet.check-set-size.js
17+
:language: javascript
18+
19+
To traverse a set, use the ``<Realm.Set>.forEach()`` method or alternative
20+
:mdn:`iteration method
21+
<Web/JavaScript/Reference/Global_Objects/Set#iteration_methods>`.
22+
23+
.. literalinclude:: /examples/generated/node/data-types.snippet.traverse-a-set.js
24+
:language: javascript
25+
26+
The order of the **Realm.Set** may be different from the order that the items
27+
were added.
28+
29+
You can track the set order by updating an array when a new value is added.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
You can query and iterate through a :ref:`RealmDictionary <sdks-dictionary-property-types>`
2+
property as you would a
3+
`Kotlin Map <https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/#kotlin.collections.Map>`__.
4+
5+
In the following example, we query a ``RealmDictionary`` property called
6+
``favoritePondsByForest``, which maps a ``String`` key (forest) to a
7+
``String`` value (pond).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
You can query and iterate through a :ref:`RealmList <sdks-list-property-types>`
2+
property as you would a
3+
`Kotlin List <https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/#kotlin.collections.List>`__.
4+
5+
In the following example, we query a ``RealmList`` property called
6+
``favoritePonds``.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
You can query and iterate through a :ref:`RealmSet <sdks-set-property-types>`
2+
property as you would a
3+
`Kotlin Set <https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-set/#kotlin.collections.Set>`__.
4+
5+
In the following example, we query a ``RealmSet`` property called
6+
``favoriteSnacks``.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
You can query a :objc-sdk:`RLMArray <Classes/RLMArray.html>` with the same
2+
predicates as :objc-sdk:`RLMResults <Classes/RLMResults.html>` and
3+
:objc-sdk:`RLMObject <Classes/RLMObject.html>`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
You can query a :objc-sdk:`RLMSet <Classes/RLMSet.html>` to check if
2+
it contains an element. If you are working with multiple sets, you can
3+
check for the intersection of two sets, or check whether one set is a subset
4+
of the other set.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
You can iterate and check the values of a realm :swift-sdk:`map <Classes/Map.html>`
2+
as you would a standard :apple:`Dictionary <documentation/swift/dictionary>`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
You can query a :swift-sdk:`List <Classes/List.html>` with the same predicates
2+
as a :swift-sdk:`Results <Structs/Results.html>` collection. Lists implement
3+
the :swift-sdk:`RealmCollection <Protocols/RealmCollection.html>` protocol,
4+
which provides access to common properties and operators such as:
5+
6+
- ``.count``
7+
- ``.first`` and ``.last``
8+
- ``.where`` query syntax
9+
- ``.sorted(by:)`` and ``.distinct(by:)``
10+
11+
Unlike Swift native collections, ``List`` is a reference type. A ``List`` is
12+
only immutable if the database it originates from is opened as read-only.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
You can query a :swift-sdk:`MutableSet <Classes/MutableSet.html>` to check if
2+
it contains an element. If you are working with multiple sets, you can
3+
check for the intersection of two sets, or check whether one set is a subset
4+
of the other set.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Sets allow you to perform math operations such as finding the union,
2+
intersection, or difference between two sets. To learn more about performing
3+
these operations, see the MDN docs for :mdn:`Implementing basic set operations
4+
<Web/JavaScript/Reference/Global_Objects/Set#implementing_basic_set_operations>`.
5+
6+
To determine if a set contains a particular value, pass the value to the
7+
``<Realm.Set>.has()`` method. The ``set.has()`` method will return true if the
8+
set contains the value specified.
9+
10+
To discover how many items are in a set, you can check the set's ``size``
11+
property.
12+
13+
To traverse a set, use the ``<Realm.Set>.forEach()`` method or alternative
14+
:mdn:`iteration method
15+
<Web/JavaScript/Reference/Global_Objects/Set#iteration_methods>`.
16+
17+
The order of the **Realm.Set** may be different from the order that the items
18+
were added.
19+
20+
You can track the set order by updating an array when a new value is added.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.. tabs-drivers::
2+
3+
tabs:
4+
- id: cpp-sdk
5+
content: |
6+
7+
.. literalinclude:: /examples/generated/cpp/crud.snippet.read-map-value.cpp
8+
:language: cpp
9+
10+
- id: csharp
11+
content: |
12+
13+
.. literalinclude:: /examples/MissingPlaceholders/example.cs
14+
:language: csharp
15+
:copyable: false
16+
17+
- id: dart
18+
content: |
19+
20+
.. literalinclude:: /examples/generated/flutter/data_types_test.snippet.map-work-with.dart
21+
:language: dart
22+
23+
- id: java
24+
content: |
25+
26+
.. literalinclude:: /examples/MissingPlaceholders/example.java
27+
:language: java
28+
:copyable: false
29+
30+
- id: java-kotlin
31+
content: |
32+
33+
.. literalinclude:: /examples/MissingPlaceholders/example-java-kotlin.kt
34+
:language: kotlin
35+
:copyable: false
36+
37+
- id: javascript
38+
content: |
39+
40+
.. literalinclude:: /examples/generated/node/data-types.snippet.query-a-dictionary.js
41+
:language: javascript
42+
43+
- id: kotlin
44+
content: |
45+
46+
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.read-realm-dictionary.kt
47+
:language: kotlin
48+
49+
- id: objectivec
50+
content: |
51+
52+
.. literalinclude:: /examples/MissingPlaceholders/example.m
53+
:language: objectivec
54+
:copyable: false
55+
56+
- id: swift
57+
content: |
58+
59+
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.map.swift
60+
:language: swift
61+
62+
- id: typescript
63+
content: |
64+
65+
.. literalinclude:: /examples/MissingPlaceholders/example.ts
66+
:language: typescript
67+
:copyable: false
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.. tabs-drivers::
2+
3+
tabs:
4+
- id: cpp-sdk
5+
content: |
6+
7+
.. literalinclude:: /examples/MissingPlaceholders/example.cpp
8+
:language: cpp
9+
:copyable: false
10+
11+
- id: csharp
12+
content: |
13+
14+
.. literalinclude:: /examples/MissingPlaceholders/example.cs
15+
:language: csharp
16+
:copyable: false
17+
18+
- id: dart
19+
content: |
20+
21+
.. literalinclude:: /examples/generated/flutter/data_types_test.snippet.realmlist-use.dart
22+
:language: dart
23+
24+
- id: java
25+
content: |
26+
27+
.. literalinclude:: /examples/MissingPlaceholders/example.java
28+
:language: java
29+
:copyable: false
30+
31+
- id: java-kotlin
32+
content: |
33+
34+
.. literalinclude:: /examples/MissingPlaceholders/example-java-kotlin.kt
35+
:language: kotlin
36+
:copyable: false
37+
38+
- id: javascript
39+
content: |
40+
41+
.. literalinclude:: /examples/MissingPlaceholders/example.js
42+
:language: javascript
43+
:copyable: false
44+
45+
- id: kotlin
46+
content: |
47+
48+
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.read-realm-list.kt
49+
:language: kotlin
50+
51+
- id: objectivec
52+
content: |
53+
54+
.. literalinclude:: /examples/MissingPlaceholders/example.m
55+
:language: objectivec
56+
:copyable: false
57+
58+
- id: swift
59+
content: |
60+
61+
.. literalinclude:: /examples/MissingPlaceholders/example.swift
62+
:language: swift
63+
:copyable: false
64+
65+
- id: typescript
66+
content: |
67+
68+
.. literalinclude:: /examples/MissingPlaceholders/example.ts
69+
:language: typescript
70+
:copyable: false
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.. tabs-drivers::
2+
3+
tabs:
4+
- id: cpp-sdk
5+
content: |
6+
7+
.. literalinclude:: /examples/generated/cpp/crud.snippet.read-set.cpp
8+
:language: cpp
9+
10+
- id: csharp
11+
content: |
12+
13+
.. literalinclude:: /examples/MissingPlaceholders/example.cs
14+
:language: csharp
15+
:copyable: false
16+
17+
- id: dart
18+
content: |
19+
20+
.. literalinclude:: /examples/generated/flutter/data_types_test.snippet.realm-set-examples.dart
21+
:language: dart
22+
23+
- id: java
24+
content: |
25+
26+
.. literalinclude:: /examples/MissingPlaceholders/example.java
27+
:language: java
28+
:copyable: false
29+
30+
- id: java-kotlin
31+
content: |
32+
33+
.. literalinclude:: /examples/MissingPlaceholders/example-java-kotlin.kt
34+
:language: kotlin
35+
:copyable: false
36+
37+
- id: javascript
38+
content: |
39+
40+
.. literalinclude:: /examples/generated/node/data-types.snippet.make-array-with-insertion-order-from-set.js
41+
:language: javascript
42+
43+
- id: kotlin
44+
content: |
45+
46+
.. literalinclude:: /examples/generated/kotlin/ReadTest.snippet.read-realm-set.kt
47+
:language: kotlin
48+
49+
- id: objectivec
50+
content: |
51+
52+
.. literalinclude:: /examples/MissingPlaceholders/example.m
53+
:language: objectivec
54+
:copyable: false
55+
56+
- id: swift
57+
content: |
58+
59+
.. literalinclude:: /examples/generated/code/start/ReadRealmObjects.snippet.set-collections.swift
60+
:language: swift
61+
62+
- id: typescript
63+
content: |
64+
65+
.. literalinclude:: /examples/MissingPlaceholders/example.ts
66+
:language: typescript
67+
:copyable: false

0 commit comments

Comments
 (0)