https://github.com/sunshine-database/sunshine
Lightweight json-database library for Python
https://github.com/sunshine-database/sunshine
database db json json-database python python3 sunshine
Last synced: 3 months ago
JSON representation
Lightweight json-database library for Python
- Host: GitHub
- URL: https://github.com/sunshine-database/sunshine
- Owner: Sunshine-Database
- Created: 2023-04-26T16:00:14.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-15T20:22:47.000Z (almost 2 years ago)
- Last Synced: 2025-03-12T06:47:06.700Z (7 months ago)
- Topics: database, db, json, json-database, python, python3, sunshine
- Language: Python
- Homepage: https://pypi.org/project/SunshineDB/
- Size: 159 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sunshine

Lightweight json-database library for Python
## Installing database library
```bash
pip install SunshineDB
```## Class
Sunshine - database management class.
Has the following set of methods:
```Python
0. push()
1. all()
2. get()
3. update()
4. contains()
5. delete()
6. drop()
7. backup()
```
## Creating database
You just need to create an instance of the Sunshine-class, passing the path to the json-file as an argument.For example,
```Python
from SunshineDB import Sunshinedatabase: Sunshine = Sunshine('../databases/database.json')
```
## Methods
Method examples will be given using the database variable we set.
## Quick Methods
* ### [0. Sunshine.push](https://github.com/Sunshine-Database/Sunshine#push)
* ### [1. Sunshine.all](https://github.com/Sunshine-Database/Sunshine#all)
* ### [2. Sunshine.get](https://github.com/Sunshine-Database/Sunshine#get)
* ### [3. Sunshine.update](https://github.com/Sunshine-Database/Sunshine#update)
* ### [4. Sunshine.contains](https://github.com/Sunshine-Database/Sunshine#contains)
* ### [5. Sunshine.delete](https://github.com/Sunshine-Database/Sunshine#delete)
* ### [6. Sunshine.drop](https://github.com/Sunshine-Database/Sunshine#drop)
* ### [7. Sunshine.backup](https://github.com/Sunshine-Database/Sunshine#backup)### push()
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.
```Python
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
```### all()
Returns all database objects.
```Python
data: list[dict[str, any]] = database.all()print(data)
# output >>
# [
# {
# 'id': 22104564398807,
# 'name': 'Bertram Gilfoyle',
# 'job': 'Pied Piper Inc.',
# 'occupation': 'Vice President Of Architecture'
# }
# ]
```### get()
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.
```Python
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)
```### update()
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.
```Python
database.update(
22104564398807,
{
'occupation' : 'Network engineer'
}
)
# changed to >>
# [
# {
# 'id': 22104564398807,
# 'name': 'Bertram Gilfoyle',
# 'job': 'Pied Piper Inc.',
# 'occupation': 'Network engineer'
# }
# ]
```### contains()
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.```Python
data: bool = database.contains('name', 'Bertram Gilfoyle')
print(data)
# output >> True
# ^^^^
# contains-method returns booleandata: bool = database.contains('name', 'Dinesh Chugtai')
print(data)
# output >> False
```### delete()
Removes the object with the given __ID__ from the database.
Requires one argument:
* id (__14-digit integer__) - numeric identifier,
```Python
database.delete(22104564398807)# database-file >>
# {
# "data": []
# }
```### drop()
Removes all objects from the database.
```Python
database.drop()# database-file >>
# {
# "data": []
# }
```### backup()
Creates a database backup at the given __path__.
Requires one argument:
* path (__string__) - path to the folder where the backup-file will be saved.
```Python
database.backup('../databases/backups/')
```
## Author
```
_ _ _ _ _
__| | ___| || | ___ _ _| | |_
/ _` |/ _ \ || |_ / _ \| | | | | __|
| (_| | __/__ _| (_) | |_| | | |_
\__,_|\___| |_| \___/ \__,_|_|\__|
```## __Thank you a lot!__