pip install SunshineDB
0. push()
1. all()
2. get()
3. update()
4. contains()
5. delete()
6. drop()
7. backup()
You just need to create an instance of the Sunshine-class, passing the path to the json-file as an argument.
For example,
from SunshineDB import Sunshine
database: Sunshine = Sunshine('../databases/database.json')
Adds an object with the given fields to the database.
Requires one argument:
- data_to_push (dictionary[string, any]) - the key-value dictionary to be added to the database.
Returns ID.
identifier: int = database.push(
{
'name' : 'Bertram Gilfoyle',
'job' : 'Pied Piper Inc.',
'occupation' : 'Vice President Of Architecture'
}
)
print(identifier)
# output >> 22104564398807
# ^^^^^^^^^^^^^^
# ID is 14-digit integer
Returns all database objects.
data: list[dict[str, any]] = database.all()
print(data)
# output >>
# [
# {
# 'id': 22104564398807,
# 'name': 'Bertram Gilfoyle',
# 'job': 'Pied Piper Inc.',
# 'occupation': 'Vice President Of Architecture'
# }
# ]
Returns a database object using a query, or returns the number of given elements in the first one up to the number specified in the count argument.
Requires two arguments:
- query (dictionary[string, any]) - a key-value dictionary that will be used to select elements,
- count (integer) - the number of requested elements.
You cannot use both arguments together.
data: list[dict[str, any]] = database.get(
query = {
'job' : 'Pied Piper Inc.'
}
)
print(data)
# output >>
# [
# {
# 'id': 22104564398807,
# 'name': 'Bertram Gilfoyle',
# 'job': 'Pied Piper Inc.',
# 'occupation': 'Vice President Of Architecture'
# }
# ]
# And the same will be displayed if you call the get-method like this
data: list[dict[str, any]] = database.get(count = 1)
Updates a database object with an ID.
Requires two arguments:
- id (14-digit integer) - numeric identifier,
- data_to_update (dictionary[string, any]) - the key-value dictionary that will be updated in the database object.
database.update(
22104564398807,
{
'occupation' : 'Network engineer'
}
)
# changed to >>
# [
# {
# 'id': 22104564398807,
# 'name': 'Bertram Gilfoyle',
# 'job': 'Pied Piper Inc.',
# 'occupation': 'Network engineer'
# }
# ]
Checks by query, if an element is contained in the database.
Requires two arguments:
- key (string),
- value (any).
These arguments will be searched in the database.
Returns boolean.
data: bool = database.contains('name', 'Bertram Gilfoyle')
print(data)
# output >> True
# ^^^^
# contains-method returns boolean
data: bool = database.contains('name', 'Dinesh Chugtai')
print(data)
# output >> False
Removes the object with the given ID from the database.
Requires one argument:
- id (14-digit integer) - numeric identifier,
database.delete(22104564398807)
# database-file >>
# {
# "data": []
# }
Removes all objects from the database.
database.drop()
# database-file >>
# {
# "data": []
# }
Creates a database backup at the given path.
Requires one argument:
- path (string) - path to the folder where the backup-file will be saved.
database.backup('../databases/backups/')
_ _ _ _ _
__| | ___| || | ___ _ _| | |_
/ _` |/ _ \ || |_ / _ \| | | | | __|
| (_| | __/__ _| (_) | |_| | | |_
\__,_|\___| |_| \___/ \__,_|_|\__|