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
391a67816b
commit
74e6d7e752
1 changed files with 28 additions and 8 deletions
36
README.md
36
README.md
|
@ -1,15 +1,16 @@
|
||||||
# ClutterDB
|
# 🈷️ ClutterDB
|
||||||
Extremely simple JSON database which behaves like a dict.
|
Extremely simple JSON database which behaves like a dict.
|
||||||
|
|
||||||
This was made for ClutterBot (still in development).
|
This was made for ClutterBot (still in development).
|
||||||
# Usage
|
# 📥 Usage
|
||||||
Clone [this](https://github.com/Clutter-Cluster/ClutterDB/blob/main/db.py) file into your project folder.
|
Clone [this](https://github.com/Clutter-Cluster/ClutterDB/blob/main/db.py) file into your project folder.
|
||||||
|
|
||||||
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, *, pathmagic="")`
|
## `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.
|
|
||||||
|
if the `pathmagic` kwarg 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,8 +23,10 @@ Note that this will not do anything if the key isn't set in the JSON.
|
||||||
Deletes everything in the JSON.
|
Deletes everything in the JSON.
|
||||||
|
|
||||||
Use with caution.
|
Use with caution.
|
||||||
# Examples
|
# 📘 Examples
|
||||||
|
> Assume that the `db.json` file is empty
|
||||||
## `db.set()`
|
## `db.set()`
|
||||||
|
### Normal usage
|
||||||
Code
|
Code
|
||||||
```python
|
```python
|
||||||
from db import ClutterDB
|
from db import ClutterDB
|
||||||
|
@ -40,8 +43,25 @@ Output
|
||||||
```
|
```
|
||||||
{'test': 123}
|
{'test': 123}
|
||||||
```
|
```
|
||||||
|
### Using with `pathmagic` kwarg
|
||||||
|
Code
|
||||||
|
```python
|
||||||
|
from db import ClutterDB
|
||||||
|
|
||||||
|
db = ClutterDB("db.json")
|
||||||
|
|
||||||
|
db.set("test", 123, pathmagic="first+second+third")
|
||||||
|
|
||||||
|
data = db.all()
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
```
|
||||||
|
Output
|
||||||
|
```
|
||||||
|
{'first': {'second': {'third': {'test': 123}}}}
|
||||||
|
```
|
||||||
## `db.get()`
|
## `db.get()`
|
||||||
#### Normal usage
|
### Normal usage
|
||||||
Code
|
Code
|
||||||
```python
|
```python
|
||||||
from db import ClutterDB
|
from db import ClutterDB
|
||||||
|
@ -58,7 +78,7 @@ Output
|
||||||
```
|
```
|
||||||
123
|
123
|
||||||
```
|
```
|
||||||
#### Using without `default` kwarg
|
### Using without `default` kwarg
|
||||||
Code
|
Code
|
||||||
```python
|
```python
|
||||||
from db import ClutterDB
|
from db import ClutterDB
|
||||||
|
@ -73,7 +93,7 @@ Output
|
||||||
```
|
```
|
||||||
None
|
None
|
||||||
```
|
```
|
||||||
#### Using with `default` kwarg
|
### Using with `default` kwarg
|
||||||
Code
|
Code
|
||||||
```python
|
```python
|
||||||
from db import ClutterDB
|
from db import ClutterDB
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue