forked from mongodb/docs-realm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9825da
commit b1ec047
Showing
5 changed files
with
254 additions
and
59 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...ce/examples/generated/flutter/read_write_data_test.snippet.filter-nested-collections.dart
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,49 @@ | ||
realm.write(() { | ||
realm.addAll([ | ||
(Team(ObjectId(), 'Janitorial Staff', | ||
eventLog: RealmValue.from({ | ||
'1': { | ||
'date': DateTime.utc(5622, 8, 18, 12, 30, 0), | ||
'type': ['work_order', 'maintenance'], | ||
'summary': 'leaking pipes in control room', | ||
'priority': 'high', | ||
}, | ||
'2': { | ||
'date': DateTime.utc(5622, 9, 18, 12, 30, 0), | ||
'type': ['maintenance'], | ||
'summary': 'trash compactor jammed', | ||
'priority': 'low', | ||
'comment': 'this is the second time this week' | ||
} | ||
}))), | ||
(Team(ObjectId(), 'IT', | ||
eventLog: RealmValue.from({ | ||
'1': { | ||
'date': DateTime.utc(5622, 9, 20, 12, 30, 0), | ||
'type': ['hardware', 'repair'], | ||
'summary': 'lightsaber damage to server room', | ||
'priority': 'high', | ||
} | ||
}))) | ||
]); | ||
|
||
final teams = realm.all<Team>(); | ||
// Use [bracket notation] to query values at the specified path | ||
final teamsWithHighPriorityEvents = | ||
teams.query("eventLog[*].priority == 'high'"); | ||
print(teamsWithHighPriorityEvents.length); // prints `2` | ||
|
||
final teamsWithMaintenanceEvents = | ||
teams.query("eventLog[*].type[FIRST] == 'maintenance'"); | ||
print(teamsWithMaintenanceEvents.length); // prints `1` | ||
|
||
// Use @keys to query map keys | ||
final eventsWithComments = | ||
teams.query("eventLog[*].@keys == 'comment'"); | ||
print(eventsWithComments.length); // prints `1` | ||
|
||
// Use @type to query the collection type | ||
final teamsWithEventsAsLists = | ||
teams.query("eventLog[*].type.@type == 'list'"); | ||
print(teamsWithEventsAsLists.length); // prints `2` | ||
}); |
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
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