simplejsoncsvdb
is a lightweight Python package providing a DataBase
class for key-value storage. This documentation aims to help users understand how to use the package effectively.
You can install the package using pip
:
pip install simplejsoncsvdb
from simplejsoncsvdb import DataBase
# Create a database instance
my_database = DataBase("example_database")
# Add an entry to the database
my_database.add_entry("key1", {"name": "John", "age": 30, "city": "New York"})
# Retrieve an entry from the database
entry = my_database.get_entry("key1")
print(entry)
# Update an entry in the database
my_database.update_entry("key1", {"name": "John Doe", "age": 31, "city": "San Francisco"})
# Delete an entry from the database
my_database.del_entry("key1")
# Convert JSON data to CSV
my_database.json2csv()
# Clear all entries in the database
my_database.clear()
Suppose you want to filter entries based on a specific key-value pair. Here's how you can achieve this using the get_all_entries
method with a filter:
# Filter entries where 'age' is 30
filtered_entries = my_database.filter('age', 30)
print(filtered_entries)
Suppose you want to retrieve all entries from the database and order them by the 'name' attribute. Here's how you can use the get_all_entries
method with sorting:
# Retrieve all entries sorted by the 'name' attribute
sorted_entries = my_database.get_all_entries(order_by='name')
print(sorted_entries)