Skip to content

Commit 61a7352

Browse files
committed
πŸš€ Updated README.md!
1 parent db26b5e commit 61a7352

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

β€Ž.config/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{"students": {
2+
"Alex": 96,
3+
"Simon": 99,
4+
"Sofia": 89
5+
}}

β€ŽREADME.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,42 @@ storage.put("theme", "dark");
3535

3636
#### Note: DataStorage.getStorage() **auto-constructs** the path if it doesn't already exist
3737

38+
### Querying nested data
39+
DataStorage also allows you to directly access nested objects without needing to use a builder
40+
form or caching multiple objects.
41+
42+
To do so, you just need to call `DataStorage.query()` that requires the ordered arrangement of the hierarchy.
43+
44+
Example:
45+
```java
46+
47+
public class Preferences {
48+
public static void save(){
49+
HashMap<String, Integer> map = new HashMap<>();
50+
map.put("Simon", 99);
51+
map.put("Alex", 96);
52+
map.put("Sofia", 89);
53+
54+
DataStorage storage = DataStorage.getStorage(".config", "settings.json");
55+
storage.put("students", map); // Auto-Save
56+
57+
System.out.println(storage.query("students", "Simon"));
58+
// Displays 99
59+
60+
61+
DataStorage storage2 = DataStorage.getStorage(".config", "settings.json");
62+
storage2.put("teachers", 18); // Auto-Save
63+
// storage2 is the same storage object with no object redundancy 😎
64+
65+
}
66+
67+
public static void main(String[] args) {
68+
save();
69+
}
70+
}
71+
72+
```
73+
3874
# ![](https://img.icons8.com/3d-fluency/48/null/smartphone-tablet.png) Handling Multiple References
3975

4076
Now, if there are multiple cases requesting the reference to the same DataStorage object, so instead of

0 commit comments

Comments
Β (0)