Examples

Database

The Database is compatible with dictionary where is Python built-in class, except only for some of setters.

So you can use them as dictionary-like, including useful CRUD methods and more.

>>> from json_as_db import Database
>>> db = Database()
>>> db.add([
...   { "id": 1001, "type": "Regular" },
...   { "id": 1002, "type": "Chocolate" }
... ])
["aT7kM2pW8L7JisSkNjpAhr", "RUJGcVBFANvNRReXa8U3En"]
>>> db.get("aT7kM2pW8L7JisSkNjpAhr")
{"id": 1001, "type": "Regular"}
>>> db.count()
2
>>> db.all()
[{"id": 1001, "type": "Regular"}, {"id": 1002, "type": "Chocolate"}]
>>> db.save('path/dir/file.json')

Moreover, Database provides and supports many operations. Please see the following examples.