Metadata-Version: 2.1
Name: DBDictionary
Version: 0.1.0
Summary: A dictionary-like interface for using databases
Author: shashstormer
Project-URL: GitHub, https://github.com/shashstormer/db_dict
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Database
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: pymongo

# Dict DB

## Description :
This is a module which has been designed to make it easier to work with databases 
in python using a dictionary like interface.

## Installation :
`pip install ...`

## Usage MongoDB :

```python
from DBDictionary import MongoDB_Dict

my_db_dict = MongoDB_Dict("my_db_name", "my_collection_name", "my_key_field", "my_connection_string")
# The connection string is optional and will default to 
# "mongodb://localhost:27017/"  if not provided here and not in the ENV var also
my_db_dict["my_key"] = {"my_key_field": "my_key",
                        "other data": "my_value"}  # This will insert a new document into the collection
your_value = my_db_dict["my_key"]  # This will return "my_value", the value in the database
print(your_value)  # This will print {"my_key_field": "my_key", "other data": "my_value"}
del my_db_dict["my_key"]  # This will delete the document from the collection
# now trying to retrive the value will raise a KeyError ,
# but you can use the "get" method like you do in a dictionary as usual
your_value = my_db_dict.get("my_key", "default_value")  # This will return "default_value"
print(your_value)  # This will print "default_value"
your_value = my_db_dict["my_key"]  # This will raise a KeyError

# editing and updating a document :
your_value["other data"] = "my_new_value"  # This will edit the value in the memory
my_db_dict.update(your_value)  # This will update the document in the database

# When you edit a dictionary like this :
my_db_dict["my_key"][
    "other data"] = "my_new_value"  # This will have no effect on the database and any changes will be lost
```
