Skip to content

Commit 0fa4b5b

Browse files
authored
Add files via upload
1 parent 8cb329c commit 0fa4b5b

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ than JSON or TOML --- without the complexity of a database.
3232
- Human-readable aligned format
3333
- Atomic file saves (corruption protection)
3434
- Custom type registry
35-
- Supports `datetime`, `date`, `time`, and `Path` natively
35+
- Supports `datetime`, `date`, `time`, `Path` and `Optional` natively
3636
- Safe variable handling with deep copy
3737

3838
**NEW in v2:**
@@ -99,7 +99,7 @@ user = data.section("user123") # for simplicity user always refers to this secti
9999

100100
user.set("name", str, "Steve")
101101
user.set("score", int, 42)
102-
user.set("tags", list[str], ["admin", "tester"])
102+
user.set("roles", list[str], ["admin", "tester"])
103103
user.set("prefs", dict[int, str], {1: "dark", 2: "light"})
104104

105105
data.save("botdata.rdm")
@@ -181,8 +181,8 @@ user.set("items", list[int], [1]) # [1]
181181
user.extend("items", 2) # [1, 2]
182182
user.extend("items", [3, 4]) # [1, 2, 3, 4]
183183

184-
user.set("tags", set[str], {"a"}) # {"a"}
185-
user.extend("tags", "b") # {"a", "b"}
184+
user.set("roles", set[str], {"a"}) # {"a"}
185+
user.extend("roles", "b") # {"a", "b"}
186186

187187
user.set("settings", dict[str,int], {"a":1}) # {"a": 1}
188188
user.extend("settings", {"b":2}) # {"a": 1, "b": 2}
@@ -218,6 +218,7 @@ user.delete("score") # key, value and type of "score" will be deleted entirely f
218218
- `float`
219219
- `bool`
220220
- `None`
221+
- `Optional[T]`
221222
- `list[T]`
222223
- `set[T]`
223224
- `tuple[T]`
@@ -243,19 +244,31 @@ class Color:
243244
def __init__(self, hex_code: str):
244245
self.hex = hex_code
245246

247+
#using lambda, where 'v' is the stored value
246248
rheelDM.TypeRegistry.register(
247249
"Color",
248250
Color,
249-
lambda v: f'"{v.hex}"',
250-
lambda v: Color(v.strip('"'))
251+
lambda v: f'#{v.hex}',
252+
lambda v: Color(v[1:])
253+
)
254+
255+
#using callables (functions)
256+
def serialize_color(v): ...
257+
def deserialize_color(v): ...
258+
259+
rheelDM.TypeRegistry.register(
260+
"Color",
261+
Color,
262+
serialize_color, # do not call them here,
263+
deserialize_color # just pass the callable
251264
)
252265
```
253266

254267
Now you can use it like any native type:
255268

256269
``` python
257270
# same with TempObj and set()
258-
data.section("settings").set("theme", Color, Color("#ff8800"))
271+
data.section("settings").set("theme", Color, Color("ff8800"))
259272
```
260273

261274
------------------------------------------------------------------------
@@ -277,12 +290,14 @@ JSON cannot store:
277290
- Union types
278291
- Nested generics
279292
- `int` as `dict`-keys
280-
- `None` (stores it as `null`)
293+
- `NoneType` (stores it as `null`)
294+
- `Optional`
281295

282296
TOML cannot store:
283297
- `Path`
284298
- `set`
285-
- `None`
299+
- `NoneType`
300+
- `Optional`
286301
- `int` as `dict`-keys
287302

288303
RDM can store all of these, even the most complex and custom types.

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "Rheel-Data-Management"
3-
version = "2.1"
3+
version = "2.3"
44
authors = [
55
{ name="CoCo_R", email="coco_snow@myyahoo.com" },
66
]
@@ -19,5 +19,4 @@ requires = ["hatchling >= 1.26"]
1919
build-backend = "hatchling.build"
2020

2121
[tool.hatch.build.targets.wheel]
22-
23-
packages = ["src/rheelDM"]
22+
packages = ["src/rheelDM"]

0 commit comments

Comments
 (0)