# JsthonDb

## Contests
0. [How to download](#how-to-download)
1. [Requirements](#requirements)
2. [Example json file](#example-json-file)
3. [All methods usage examples](#all-methods-usage-examples)
+ [Creating empty JsthonDb](#creating-empty-jsthondb)
+ [create_table](#create_table)
+ [choose_table](#choose_table)
+ [add](#add)
+ [add_many](#add_many)
+ [take_all](#take_all)
+ [take_by_id](#take_by_id)
+ [take_with_function](#take_with_function)
+ [update_by_id](#update_by_id)
+ [update_with_function](#update_with_function)
+ [delete_by_id](#delete_by_id)
+ [delete_with_function](#delete_with_function)
+ [add_new_key](#add_new_key)
+ [add_new_keys](#add_new_keys)
+ [show_table](#show_table)
+ [clear_table](#clear_table)
+ [clear_db](#clear_db)
4. [Errors](#errors)
+ [UnknownKeyError](#unknownkeyerror)
+ [FunctionIsNotCallable](#functionisnotcallable)
+ [WrongIdsListWasGiven](#wrongidslistwasgiven)
+ [IdWasNotFound](#idwasnotfound)
+ [IdIsAlreadyUsed](#idisalreadyused)
+ [NotUniqueNameOfTable](#notuniquenameoftable)
+ [WrongFileName](#wrongfilename)
5. [Leave your feedback](#leave-your-feedback)
## How to download
```cli
git clone https://github.com/terribleMOTHMAN/JsthonDb
cd JsthonDb
python setup.py install
```
## Requirements
+ `uuid` >= 1.30
+ `ujson` >= 5.6.0
## Example json file
```json
{
"tvshows": {
"keys": [
],
"data": {
}
},
"films": {
"keys": [
],
"data": {
}
}
}
```
## All methods usage examples
### Creating empty JsthonDb
```python
from jsthon import JsthonDb
db = JsthonDb('main.json')
```
We created that empty file
```json
{
}
```
### create_table
Example usage (name field must be str)
```python
db.create_table('tvshows')
db.create_table('films')
```
```json
{
"tvshows": {
"keys": [
],
"data": {
}
},
"films": {
"keys": [
],
"data": {
}
}
}
```
You need to know that after using this method table that will be changed by the default methods will be films. Because it was created last
### choose_table
Example usage (table field must be str)
```python
db.choose_table('tvshows')
```
All the methods we will use will change the table 'tvshows' because we have chosen it
### add
Example usage (data field must be dict)
```python
id = db.add({'name': 'Breaking Bad', 'start': 2008})
print(id)
```
Output
```python
279161855443486914901758992112454064004
```
Also we can use our own id without generating it (id field must be string)
```python
id = db.add({'name': 'Mr. Robot', 'start': 2015}, "1")
print(id)
```
Output
```
1
```
### add_many
Example usage (data field must be list with elements that are dictionaries)
```python
added_values = db.add_many([{'name': 'Shameless', 'start': 2011}, {'name': 'The Boys', 'start': 2019}])
print(added_values)
```
Output
```python
{'227987855254015167042504673548582084559': {'name': 'Shameless', 'start': 2011}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019}}
```
Also we can use our own ids without generating it (id field must be tuple with ids that are strings). Also, each id must correspond to a value in the data field
```python
added_values = db.add_many([{'name': 'Scrubs', 'start': 2001}, {'name': 'How I Met Your Mother', 'start': 2005}], ("0", "2"))
print(added_values)
```
Output
```python
{'0': {'name': 'Scrubs', 'start': 2001}, '2': {'name': 'How I Met Your Mother', 'start': 2005}}
```
### take_all
Example usage
```python
all = db.take_all()
print(all)
```
Output
```python
{'279161855443486914901758992112454064004': {'name': 'Breaking Bad', 'start': 2008}, '1': {'name': 'Mr. Robot', 'start': 2015}, '227987855254015167042504673548582084559': {'name': 'Shameless', 'start': 2011}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019}, '0': {'name': 'Scrubs', 'start': 2001}, '2': {'name': 'How I Met Your Mother', 'start': 2005}}
```
### take_by_id
Example usage
```python
element = db.take_by_id("1")
print(element)
```
Output
```python
{'name': 'Mr. Robot', 'start': 2015}
```
### take_with_function
Example usage
```python
def func(data):
if data['start'] > 2010:
return True
print(db.take_with_function(func))
```
Output
```python
{'1': {'name': 'Mr. Robot', 'start': 2015}, '227987855254015167042504673548582084559': {'name': 'Shameless', 'start': 2011}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019}}
```
### update_by_id
Example usage
```python
updated_data = db.update_by_id("1", {'name': 'Better Call Saul'})
print(updated_data)
print(db.take_by_id("1"))
```
Output
```python
{'name': 'Better Call Saul', 'start': 2015}
{'name': 'Better Call Saul', 'start': 2015}
```
### update_with_function
Example usage
```python
def func(data):
if data['name'] == 'Shameless':
return True
updated_data = db.update_with_function(func, {'name': '$hameless'})
print(updated_data)
```
Output
```python
['227987855254015167042504673548582084559']
```
### delete_by_id
Example usage
```python
deleted_data = db.delete_by_id("227987855254015167042504673548582084559")
print(deleted_data)
```
Output
```python
{'name': '$hameless', 'start': 2011}
```
### delete_with_function
Example usage
```python
def func(data):
if data['start'] < 2015:
return True
deleted_data = db.delete_with_function(func)
print(deleted_data)
```
Output
```python
[{'name': 'Scrubs', 'start': 2001}, {'name': 'How I Met Your Mother', 'start': 2005}, {'name': 'Breaking Bad', 'start': 2008}]
```
### add_new_key
Example usage
```python
db.add_new_key('broadcast', True)
print(db.take_all())
```
Output
```python
{'1': {'name': 'Better Call Saul', 'start': 2015, 'broadcast': True}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019, 'broadcast': True}}
```
### add_new_keys
Example usage
```python
db.add_new_keys(['ratings', 'language'], ['good', 'english'])
print(db.take_all())
```
Output
```python
{'1': {'name': 'Better Call Saul', 'start': 2015, 'broadcast': True, 'ratings': 'good', 'language': 'english'}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019, 'broadcast': True, 'ratings': 'good', 'language': 'english'}}
```
### show_table
Example usage
```python
a = db.show_table()
print(a)
```
Output
```python
[['name', 'start', 'broadcast', 'ratings', 'language'], ['Better Call Saul', 2015, True, 'good', 'english'], ['The Boys', 2019, True, 'good', 'english']]
```
### clear_table
Example usage
```python
db.clear_table()
```
Json file
```json
{
"tvshows": {
"keys": [
],
"data": {
}
},
"films": {
"keys": [
],
"data": {
}
}
}
```
### clear_db
Example usage
```python
db.clear_db()
```
Json file
```json
{
}
```
## Errors
### UnknownKeyError
It's raised when key was unrecognised or missed
### FunctionIsNotCallable
It's raised when function was given to the method is not callable or is not function
### WrongIdsListWasGiven
It's raised when idswas given to the method have wrong type
### IdWasNotFound
It's raised when id was not found in the table
### IdIsAlreadyUsed
It's raised when id was given to the methon is not unique in the table
### NotUniqueNameOfTable
It's raised when name of table that was given is not unique
### WrongFileName
It's raised when wrong filename was given to a class
## Leave your feedback
I need your review! It will be pleasure for me ^_^
[Survey](https://ru.surveymonkey.com/r/LDR7NHY)
Raw data
{
"_id": null,
"home_page": "https://github.com/terribleMOTHMAN/JsthonDb",
"name": "jsthon",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "terribleMOTHMAN",
"author_email": "paradox.smirnoff@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/1b/32/f607cec3b3fc71353b69e60956473b4ebfedf17d34972e7d5898ec2c0cc7/jsthon-0.4.1.tar.gz",
"platform": null,
"description": "# JsthonDb\n\n\n## Contests\n0. [How to download](#how-to-download)\n1. [Requirements](#requirements) \n2. [Example json file](#example-json-file) \n3. [All methods usage examples](#all-methods-usage-examples)\n + [Creating empty JsthonDb](#creating-empty-jsthondb)\n + [create_table](#create_table)\n + [choose_table](#choose_table)\n + [add](#add)\n + [add_many](#add_many)\n + [take_all](#take_all)\n + [take_by_id](#take_by_id)\n + [take_with_function](#take_with_function)\n + [update_by_id](#update_by_id)\n + [update_with_function](#update_with_function)\n + [delete_by_id](#delete_by_id)\n + [delete_with_function](#delete_with_function)\n + [add_new_key](#add_new_key)\n + [add_new_keys](#add_new_keys)\n + [show_table](#show_table)\n + [clear_table](#clear_table)\n + [clear_db](#clear_db)\n4. [Errors](#errors)\n + [UnknownKeyError](#unknownkeyerror)\n + [FunctionIsNotCallable](#functionisnotcallable)\n + [WrongIdsListWasGiven](#wrongidslistwasgiven)\n + [IdWasNotFound](#idwasnotfound)\n + [IdIsAlreadyUsed](#idisalreadyused)\n + [NotUniqueNameOfTable](#notuniquenameoftable)\n + [WrongFileName](#wrongfilename)\n5. [Leave your feedback](#leave-your-feedback)\n\n## How to download\n```cli\ngit clone https://github.com/terribleMOTHMAN/JsthonDb\ncd JsthonDb\npython setup.py install\n```\n\n## Requirements \n+ `uuid` >= 1.30\n+ `ujson` >= 5.6.0\n\n## Example json file\n```json\n\n{\n \"tvshows\": {\n \"keys\": [\n\n ],\n \"data\": {\n\n }\n },\n \"films\": {\n \"keys\": [\n\n ],\n \"data\": {\n\n }\n }\n}\n\n```\n\n## All methods usage examples\n### Creating empty JsthonDb\n```python\nfrom jsthon import JsthonDb\n\ndb = JsthonDb('main.json')\n```\nWe created that empty file\n```json\n{\n\n}\n```\n### create_table\nExample usage (name field must be str)\n```python\ndb.create_table('tvshows')\ndb.create_table('films')\n```\n```json\n{\n \"tvshows\": {\n \"keys\": [\n\n ],\n \"data\": {\n\n }\n },\n \"films\": {\n \"keys\": [\n\n ],\n \"data\": {\n\n }\n }\n}\n```\nYou need to know that after using this method table that will be changed by the default methods will be films. Because it was created last\n### choose_table\nExample usage (table field must be str)\n```python\ndb.choose_table('tvshows')\n```\nAll the methods we will use will change the table 'tvshows' because we have chosen it\n### add\nExample usage (data field must be dict)\n```python\nid = db.add({'name': 'Breaking Bad', 'start': 2008})\nprint(id)\n```\nOutput\n```python\n279161855443486914901758992112454064004\n```\nAlso we can use our own id without generating it (id field must be string)\n```python\nid = db.add({'name': 'Mr. Robot', 'start': 2015}, \"1\")\nprint(id)\n```\nOutput\n```\n1\n```\n### add_many\nExample usage (data field must be list with elements that are dictionaries)\n```python\nadded_values = db.add_many([{'name': 'Shameless', 'start': 2011}, {'name': 'The Boys', 'start': 2019}])\nprint(added_values)\n```\nOutput\n```python\n{'227987855254015167042504673548582084559': {'name': 'Shameless', 'start': 2011}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019}}\n```\nAlso we can use our own ids without generating it (id field must be tuple with ids that are strings). Also, each id must correspond to a value in the data field\n```python\nadded_values = db.add_many([{'name': 'Scrubs', 'start': 2001}, {'name': 'How I Met Your Mother', 'start': 2005}], (\"0\", \"2\"))\nprint(added_values)\n```\nOutput\n```python\n{'0': {'name': 'Scrubs', 'start': 2001}, '2': {'name': 'How I Met Your Mother', 'start': 2005}}\n```\n\n### take_all\nExample usage\n```python\nall = db.take_all()\nprint(all)\n```\nOutput\n```python\n{'279161855443486914901758992112454064004': {'name': 'Breaking Bad', 'start': 2008}, '1': {'name': 'Mr. Robot', 'start': 2015}, '227987855254015167042504673548582084559': {'name': 'Shameless', 'start': 2011}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019}, '0': {'name': 'Scrubs', 'start': 2001}, '2': {'name': 'How I Met Your Mother', 'start': 2005}}\n```\n\n### take_by_id\nExample usage\n```python\nelement = db.take_by_id(\"1\")\nprint(element)\n```\nOutput\n```python\n{'name': 'Mr. Robot', 'start': 2015}\n```\n\n### take_with_function\nExample usage\n```python\ndef func(data):\n if data['start'] > 2010:\n return True\n\nprint(db.take_with_function(func))\n```\nOutput\n```python\n{'1': {'name': 'Mr. Robot', 'start': 2015}, '227987855254015167042504673548582084559': {'name': 'Shameless', 'start': 2011}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019}}\n```\n\n### update_by_id\nExample usage\n```python\nupdated_data = db.update_by_id(\"1\", {'name': 'Better Call Saul'})\nprint(updated_data)\nprint(db.take_by_id(\"1\"))\n```\nOutput\n```python\n{'name': 'Better Call Saul', 'start': 2015}\n{'name': 'Better Call Saul', 'start': 2015}\n```\n\n### update_with_function\nExample usage\n```python\ndef func(data):\n if data['name'] == 'Shameless':\n return True\n\nupdated_data = db.update_with_function(func, {'name': '$hameless'})\nprint(updated_data)\n```\nOutput\n```python\n['227987855254015167042504673548582084559']\n```\n\n### delete_by_id\nExample usage\n```python\ndeleted_data = db.delete_by_id(\"227987855254015167042504673548582084559\")\nprint(deleted_data)\n```\nOutput\n```python\n{'name': '$hameless', 'start': 2011}\n```\n\n### delete_with_function\nExample usage\n```python\ndef func(data):\n if data['start'] < 2015:\n return True\n\n\ndeleted_data = db.delete_with_function(func)\nprint(deleted_data)\n```\nOutput\n```python\n[{'name': 'Scrubs', 'start': 2001}, {'name': 'How I Met Your Mother', 'start': 2005}, {'name': 'Breaking Bad', 'start': 2008}]\n```\n\n### add_new_key\nExample usage\n```python\ndb.add_new_key('broadcast', True)\nprint(db.take_all())\n```\nOutput\n```python\n{'1': {'name': 'Better Call Saul', 'start': 2015, 'broadcast': True}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019, 'broadcast': True}}\n```\n\n### add_new_keys\nExample usage\n```python\ndb.add_new_keys(['ratings', 'language'], ['good', 'english'])\nprint(db.take_all())\n```\nOutput\n```python\n{'1': {'name': 'Better Call Saul', 'start': 2015, 'broadcast': True, 'ratings': 'good', 'language': 'english'}, '334561175396969661937858438600623257934': {'name': 'The Boys', 'start': 2019, 'broadcast': True, 'ratings': 'good', 'language': 'english'}}\n```\n\n### show_table\nExample usage\n```python\na = db.show_table()\nprint(a)\n```\nOutput\n```python\n[['name', 'start', 'broadcast', 'ratings', 'language'], ['Better Call Saul', 2015, True, 'good', 'english'], ['The Boys', 2019, True, 'good', 'english']]\n```\n\n### clear_table\nExample usage\n```python\ndb.clear_table()\n```\nJson file\n```json\n{\n \"tvshows\": {\n \"keys\": [\n\n ],\n \"data\": {\n\n }\n },\n \"films\": {\n \"keys\": [\n\n ],\n \"data\": {\n\n }\n }\n}\n```\n\n### clear_db\nExample usage\n```python\ndb.clear_db()\n```\nJson file\n```json\n{\n\n}\n```\n## Errors\n### UnknownKeyError\nIt's raised when key was unrecognised or missed\n\n### FunctionIsNotCallable\nIt's raised when function was given to the method is not callable or is not function\n\n### WrongIdsListWasGiven\nIt's raised when idswas given to the method have wrong type\n\n### IdWasNotFound\nIt's raised when id was not found in the table\n\n### IdIsAlreadyUsed\nIt's raised when id was given to the methon is not unique in the table\n\n### NotUniqueNameOfTable\nIt's raised when name of table that was given is not unique\n\n### WrongFileName\nIt's raised when wrong filename was given to a class\n\n## Leave your feedback\nI need your review! It will be pleasure for me ^_^\n\n[Survey](https://ru.surveymonkey.com/r/LDR7NHY)\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Easy to use, fast, productive json database for python",
"version": "0.4.1",
"project_urls": {
"Homepage": "https://github.com/terribleMOTHMAN/JsthonDb"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1b32f607cec3b3fc71353b69e60956473b4ebfedf17d34972e7d5898ec2c0cc7",
"md5": "92f18ed579c5269a0efc26cef846cbfe",
"sha256": "39a7cd686ec0e7720e3c4d66c5045dfae3b235a4400bba91246a2541b65846c7"
},
"downloads": -1,
"filename": "jsthon-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "92f18ed579c5269a0efc26cef846cbfe",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6513,
"upload_time": "2023-09-23T13:50:44",
"upload_time_iso_8601": "2023-09-23T13:50:44.676636Z",
"url": "https://files.pythonhosted.org/packages/1b/32/f607cec3b3fc71353b69e60956473b4ebfedf17d34972e7d5898ec2c0cc7/jsthon-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-23 13:50:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "terribleMOTHMAN",
"github_project": "JsthonDb",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "uuid",
"specs": [
[
">=",
"1.30"
]
]
},
{
"name": "ujson",
"specs": [
[
">=",
"5.6.0"
]
]
}
],
"lcname": "jsthon"
}