From 74e6d7e752b7fe816d0f94815924286063ffbd3a Mon Sep 17 00:00:00 2001 From: RGBCube <78925721+RGBCube@users.noreply.github.com> Date: Sat, 15 Jan 2022 15:45:28 +0300 Subject: [PATCH] Update README.md --- README.md | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e8cfe41..8a5aeee 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ -# ClutterDB +# 🈷️ ClutterDB Extremely simple JSON database which behaves like a dict. 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. Add `from db import CluttterDB` to the top of your project. -# Docs +# 📄 Docs ## `db.set(key: str, value, *, pathmagic="")` 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)` 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()` @@ -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. Use with caution. -# Examples +# 📘 Examples +> Assume that the `db.json` file is empty ## `db.set()` +### Normal usage Code ```python from db import ClutterDB @@ -40,8 +43,25 @@ Output ``` {'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()` -#### Normal usage +### Normal usage Code ```python from db import ClutterDB @@ -58,7 +78,7 @@ Output ``` 123 ``` -#### Using without `default` kwarg +### Using without `default` kwarg Code ```python from db import ClutterDB @@ -73,7 +93,7 @@ Output ``` None ``` -#### Using with `default` kwarg +### Using with `default` kwarg Code ```python from db import ClutterDB