# Sunshine
![Sunshine Logo](https://github.com/Sunshine-Database/Sunshine/blob/main/sources/sunshine.png?raw=true)
<h2>Lightweight json-database library for Python</h2>
<br>
## Installing database library
```bash
pip install SunshineDB
```
## Class
<h3>Sunshine - database management class. </h3>
<h3>Has the following set of methods: </h3>
```Python
0. push()
1. all()
2. get()
3. update()
4. contains()
5. delete()
6. drop()
7. backup()
```
<br>
<br>
## 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 Sunshine
database: Sunshine = Sunshine('../databases/database.json')
```
<br>
## Methods
<h3>Method examples will be given using the database variable we set. </h3>
### push()
Adds an object with the given fields to the database. <br>
Requires one argument:
* data_to_push (__dictionary[string, any]__) - the key-value dictionary to be added to the database.
Returns ID.
<br>
```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. <br>
<br>
```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. <br>
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.
<br>
```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__. <br>
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.
<br>
```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. <br>
Requires two arguments:
* key (__string__),
* value (__any__).
These arguments will be searched in the database.
Returns boolean.
<br>
```Python
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
```
### delete()
Removes the object with the given __ID__ from the database. <br>
Requires one argument:
* id (__14-digit integer__) - numeric identifier,
<br>
```Python
database.delete(22104564398807)
# database-file >>
# {
# "data": []
# }
```
### drop()
Removes all objects from the database.
<br>
```Python
database.drop()
# database-file >>
# {
# "data": []
# }
```
### backup()
Creates a database backup at the given __path__. <br>
Requires one argument:
* path (__string__) - path to the folder where the backup-file will be saved.
<br>
```Python
database.backup('../databases/backups/')
```
<br>
<br>
<br>
## Author
```
_ _ _ _ _
__| | ___| || | ___ _ _| | |_
/ _` |/ _ \ || |_ / _ \| | | | | __|
| (_| | __/__ _| (_) | |_| | | |_
\__,_|\___| |_| \___/ \__,_|_|\__|
```
## __Thank you a lot!__
<br>
## How to reach me
<a href="https://t.me/de4oult">
<img src="https://img.shields.io/badge/-Telegram-informational?style=for-the-badge&logo=telegram" alt="Telegram Badge" height="30" />
</a>
<img src="https://img.shields.io/badge/-kayra.dist@gmail.com-informational?style=for-the-badge&logo=gmail" alt="Gmail Badge" height="30" />
Raw data
{
"_id": null,
"home_page": "https://github.com/Sunshine-Database/Sunshine",
"name": "SunshineDB",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": "",
"keywords": "sunshine,database,json,json-database,db,async",
"author": "de4oult",
"author_email": "kayra.dist@email.com",
"download_url": "https://files.pythonhosted.org/packages/ed/1f/6db4541760f99a691070ae09bac65eb62d5e426ce640e9939171b90872e0/SunshineDB-1.5.tar.gz",
"platform": null,
"description": "# Sunshine\n\n![Sunshine Logo](https://github.com/Sunshine-Database/Sunshine/blob/main/sources/sunshine.png?raw=true)\n\n<h2>Lightweight json-database library for Python</h2>\n\n<br>\n\n## Installing database library\n```bash\npip install SunshineDB\n```\n\n## Class\n<h3>Sunshine - database management class. </h3>\n\n<h3>Has the following set of methods: </h3>\n\n```Python\n0. push()\n1. all()\n2. get()\n3. update()\n4. contains()\n5. delete()\n6. drop()\n7. backup()\n```\n\n<br>\n<br>\n\n## Creating database\nYou just need to create an instance of the Sunshine-class, passing the path to the json-file as an argument.\n\nFor example,\n```Python\nfrom SunshineDB import Sunshine\n\ndatabase: Sunshine = Sunshine('../databases/database.json')\n```\n\n<br>\n\n## Methods\n<h3>Method examples will be given using the database variable we set. </h3>\n\n### push()\nAdds an object with the given fields to the database. <br>\nRequires one argument:\n* data_to_push (__dictionary[string, any]__) - the key-value dictionary to be added to the database.\n\nReturns ID.\n<br>\n\n```Python\nidentifier: int = database.push(\n {\n 'name' : 'Bertram Gilfoyle',\n 'job' : 'Pied Piper Inc.',\n 'occupation' : 'Vice President Of Architecture'\n }\n)\n\nprint(identifier) \n# output >> 22104564398807 \n# ^^^^^^^^^^^^^^\n# ID is 14-digit integer\n```\n\n### all()\nReturns all database objects. <br>\n<br>\n\n```Python\ndata: list[dict[str, any]] = database.all()\n\nprint(data)\n# output >> \n# [\n# {\n# 'id': 22104564398807, \n# 'name': 'Bertram Gilfoyle', \n# 'job': 'Pied Piper Inc.', \n# 'occupation': 'Vice President Of Architecture'\n# }\n# ]\n```\n\n### get()\nReturns 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. <br>\nRequires two arguments:\n* query (__dictionary[string, any]__) - a key-value dictionary that will be used to select elements,\n* count (__integer__) - the number of requested elements.\n\nYou cannot use both arguments together.\n<br>\n\n```Python\ndata: list[dict[str, any]] = database.get(\n query = {\n 'job' : 'Pied Piper Inc.'\n }\n)\n\nprint(data)\n# output >> \n# [\n# {\n# 'id': 22104564398807, \n# 'name': 'Bertram Gilfoyle', \n# 'job': 'Pied Piper Inc.', \n# 'occupation': 'Vice President Of Architecture'\n# }\n# ]\n\n# And the same will be displayed if you call the get-method like this\ndata: list[dict[str, any]] = database.get(count = 1)\n```\n\n### update()\nUpdates a database object with an __ID__. <br>\nRequires two arguments:\n* id (__14-digit integer__) - numeric identifier,\n* data_to_update (__dictionary[string, any]__) - the key-value dictionary that will be updated in the database object.\n\n<br>\n\n```Python\ndatabase.update(\n 22104564398807, \n {\n 'occupation' : 'Network engineer'\n }\n)\n# changed to >> \n# [\n# {\n# 'id': 22104564398807, \n# 'name': 'Bertram Gilfoyle', \n# 'job': 'Pied Piper Inc.', \n# 'occupation': 'Network engineer'\n# }\n# ]\n```\n\n### contains()\nChecks by query, if an element is contained in the database. <br>\nRequires two arguments:\n* key (__string__),\n* value (__any__).\n\nThese arguments will be searched in the database.\n \nReturns boolean.\n<br>\n\n```Python\ndata: bool = database.contains('name', 'Bertram Gilfoyle')\nprint(data)\n# output >> True\n# ^^^^\n# contains-method returns boolean\n\ndata: bool = database.contains('name', 'Dinesh Chugtai')\nprint(data)\n# output >> False\n```\n\n### delete()\nRemoves the object with the given __ID__ from the database. <br>\nRequires one argument:\n* id (__14-digit integer__) - numeric identifier,\n\n<br>\n\n```Python\ndatabase.delete(22104564398807)\n\n# database-file >>\n# {\n# \"data\": []\n# }\n```\n\n### drop()\nRemoves all objects from the database. \n\n<br>\n\n```Python\ndatabase.drop()\n\n# database-file >>\n# {\n# \"data\": []\n# }\n```\n\n### backup()\nCreates a database backup at the given __path__. <br>\nRequires one argument:\n* path (__string__) - path to the folder where the backup-file will be saved.\n\n<br>\n\n```Python\ndatabase.backup('../databases/backups/')\n```\n\n<br>\n<br>\n<br>\n\n## Author\n```\n _ _ _ _ _ \n __| | ___| || | ___ _ _| | |_ \n / _` |/ _ \\ || |_ / _ \\| | | | | __|\n| (_| | __/__ _| (_) | |_| | | |_ \n \\__,_|\\___| |_| \\___/ \\__,_|_|\\__|\n```\n\n## __Thank you a lot!__\n\n<br>\n\n## How to reach me\n<a href=\"https://t.me/de4oult\">\n <img src=\"https://img.shields.io/badge/-Telegram-informational?style=for-the-badge&logo=telegram\" alt=\"Telegram Badge\" height=\"30\" />\n</a>\n<img src=\"https://img.shields.io/badge/-kayra.dist@gmail.com-informational?style=for-the-badge&logo=gmail\" alt=\"Gmail Badge\" height=\"30\" />\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Lightweight json-database library for Python",
"version": "1.5",
"project_urls": {
"Homepage": "https://github.com/Sunshine-Database/Sunshine"
},
"split_keywords": [
"sunshine",
"database",
"json",
"json-database",
"db",
"async"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "985acfa9cdbfc879d74367cc3e0cd3d0bcf0289f30587fc1363b72ed5a121382",
"md5": "067de59ef2b5152c412048b1b65b9a69",
"sha256": "57184584882ca0fbc6a4aec98c05ef8fce04d901769a57954dbd7462d83f9b11"
},
"downloads": -1,
"filename": "SunshineDB-1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "067de59ef2b5152c412048b1b65b9a69",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 6421,
"upload_time": "2023-05-31T21:05:04",
"upload_time_iso_8601": "2023-05-31T21:05:04.506071Z",
"url": "https://files.pythonhosted.org/packages/98/5a/cfa9cdbfc879d74367cc3e0cd3d0bcf0289f30587fc1363b72ed5a121382/SunshineDB-1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ed1f6db4541760f99a691070ae09bac65eb62d5e426ce640e9939171b90872e0",
"md5": "2c96dbadb08db256c3f4f9130658afee",
"sha256": "e9e7369844f7bd49f136d6358caecb7a53f0a6116b44baa8cbe882f327f8e8c7"
},
"downloads": -1,
"filename": "SunshineDB-1.5.tar.gz",
"has_sig": false,
"md5_digest": "2c96dbadb08db256c3f4f9130658afee",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 5430,
"upload_time": "2023-05-31T21:05:06",
"upload_time_iso_8601": "2023-05-31T21:05:06.897411Z",
"url": "https://files.pythonhosted.org/packages/ed/1f/6db4541760f99a691070ae09bac65eb62d5e426ce640e9939171b90872e0/SunshineDB-1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-31 21:05:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Sunshine-Database",
"github_project": "Sunshine",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "sunshinedb"
}