mirror of
https://github.com/RGBCube/JsonWrapper
synced 2025-07-27 19:57:44 +00:00
Update README.md
This commit is contained in:
parent
ee145f449b
commit
0f182fa45a
1 changed files with 28 additions and 29 deletions
57
README.md
57
README.md
|
@ -7,8 +7,9 @@ Clone [this](https://github.com/Clutter-Cluster/ClutterDB/blob/main/db.py) file
|
||||||
|
|
||||||
Add `from db import CluttterDB` to the top of your project.
|
Add `from db import CluttterDB` to the top of your project.
|
||||||
# Docs
|
# Docs
|
||||||
## `db.set(key: str, value)`
|
## `db.set(key: str, value, *, pathmagic="")`
|
||||||
Sets the key to the value in the JSON.
|
Sets the key to the value in the JSON.
|
||||||
|
if the `pathmagic` is given, it will spit it by the `+`'s and make dicts(or use existing ones) until it finishes, then it will set the value to the key in the last dict.
|
||||||
## `db.get(key: str, *, default=None)`
|
## `db.get(key: str, *, default=None)`
|
||||||
Returns the value of the key in the json, if the key isn't set in the json, it returns the default kwarg.
|
Returns the value of the key in the json, if the key isn't set in the json, it returns the default kwarg.
|
||||||
## `db.all()`
|
## `db.all()`
|
||||||
|
@ -22,41 +23,39 @@ Deletes everything in the JSON.
|
||||||
|
|
||||||
Use with caution.
|
Use with caution.
|
||||||
# Examples
|
# Examples
|
||||||
Code:
|
# `db.set("test", 123)`
|
||||||
|
Code
|
||||||
```python
|
```python
|
||||||
from db import ClutterDB
|
from db import ClutterDB
|
||||||
|
|
||||||
# initialization
|
db = ClutterDB("db.json")
|
||||||
db = ClutterDB("path/to/json/file.json")
|
|
||||||
|
|
||||||
# defining the "a" variable
|
db.set("test", 123)
|
||||||
# (this will overrride the previous "a" if it was defined before)
|
|
||||||
db.set("a", 12345)
|
data = db.all()
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
```
|
||||||
|
Output
|
||||||
|
`{'test': 123}`
|
||||||
|
# `db.rem("test")`
|
||||||
|
Code
|
||||||
|
```python
|
||||||
|
from db import ClutterDB
|
||||||
|
|
||||||
|
db = ClutterDB("db.json")
|
||||||
|
|
||||||
|
db.set("test", 123)
|
||||||
|
|
||||||
# another one for demonstration purposes
|
|
||||||
db.set("b", 123456)
|
|
||||||
|
|
||||||
# getting a variable
|
|
||||||
# (default kwarg will be returned if the key was not defined in the json)
|
|
||||||
data = db.get("a", default="a was not defined in the json")
|
|
||||||
|
|
||||||
# prints data
|
|
||||||
print(data)
|
|
||||||
|
|
||||||
# gets all json data
|
|
||||||
data = db.all()
|
data = db.all()
|
||||||
|
|
||||||
# prints data
|
|
||||||
print(data)
|
print(data)
|
||||||
|
|
||||||
# removes the "a" from the json
|
db.rem("test")
|
||||||
db.rem("a")
|
|
||||||
|
|
||||||
# nukes the json
|
data = db.all()
|
||||||
db.nuke()
|
|
||||||
```
|
print(data)```
|
||||||
Output:
|
Output
|
||||||
```
|
`{'test': 123}
|
||||||
12345
|
{}`
|
||||||
{'a': 12345, 'b': 123456}
|
|
||||||
```
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue