1
Fork 0
mirror of https://github.com/RGBCube/JsonWrapper synced 2026-01-20 12:11:09 +00:00
No description
Find a file
2022-01-15 15:27:43 +03:00
db.py pathmagic 2022-01-15 15:20:57 +03:00
README.md Update README.md 2022-01-15 15:27:43 +03:00

ClutterDB

Extremely simple JSON database which behaves like a dict.

This was made for ClutterBot (still in development).

Usage

Clone this file into your project folder.

Add from db import CluttterDB to the top of your project.

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.

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()

Returns all the JSON data.

db.rem(key: str)

Removes the key and value pair from the JSON.

Note that this will not do anything if the key isn't set in the JSON.

db.nuke()

Deletes everything in the JSON.

Use with caution.

Examples

db.set("test", 123)

Code

from db import ClutterDB

db = ClutterDB("db.json")

db.set("test", 123)

data = db.all()

print(data)

Output {'test': 123}

db.rem("test")

Code

from db import ClutterDB

db = ClutterDB("db.json")

db.set("test", 123)

data = db.all()

print(data)

db.rem("test")

data = db.all()

print(data)

Output {'test': 123} {}