# Shiba-Py-Mysql
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/ShibaRoPinoo/Shiba-Py-Mysql/blob/main/LICENSE)
Shiba-Py-Mysql is a lightweight Python library that provides a convenient interface for interacting with MySQL databases using the `pymysql` library. It simplifies common database administration tasks such as creating databases, selecting databases, creating tables, and performing basic CRUD operations.
## Features
- Easy database creation and selection.
- Table creation with support for different column types.
- Retrieving data from tables with support for JSON fields.
## Installation
You can install Shiba-Py-Mysql using pip:
```shell
pip install shiba-mysql
```
```python
import shiba as s
# Create a connection to the MySQL database
connection = s.ShibaConnection(host='localhost', port=3306, user='myuser', password='mypassword')
# Create a new database
connection.create_database('my_database')
# Select the database
connection.use_database('my_database')
# Create a table
table_builder = connection.create_table('users')
table_builder.increments('id')
table_builder.string('name', 20)
table_builder.integer('age')
table_builder.text('languages')
table_builder.text('settings')
table_builder.build()
```
```python
# Insert data into the table
data_single = {
"name": "John",
"age": 30,
"languages": json.dumps(["Python", "JavaScript", "Java"]),
"settings": json.dumps({"theme": "dark", "notifications": True})
}
data_list = [
{
"name": "Alice",
"age": 25,
"languages": json.dumps(["Python", "C++"]),
"settings": json.dumps({"theme": "light", "notifications": False})
},
{
"name": "Bob",
"age": 35,
"languages": json.dumps(["JavaScript", "TypeScript"]),
"settings": json.dumps({"theme": "dark", "notifications": True})
}
]
cx.table('users').insert(data_single)
cx.table('users').insert(data_list)
x = cx.table("users").get()
for e in x:
for k, v in e.items():
if k == "languages":
languages = json.loads(v)
languages_str = ", ".join(languages)
print(f"Languages: {languages_str}")
elif k == "settings":
settings_str = json.loads(v)
print(f"Settings\n Theme: {settings_str['theme']}\n Notifications: {settings_str['notifications']}")
else:
print(f"{k}: {str(v)}")
```
## LICENSE
This project is under the [MIT License](https://github.com/ShibaRoPinoo/Shiba-Py-Mysql/blob/main/LICENSE).
Change log
==========
1.0.0 (14/07/2023)
------------------
- FIRST RELEASE
-- CREATE MODEL
=========
1.1.0 (15/07/2023)
------------------
- SECODN RELEASE
-- ADD METHOD TABLE BUILDER: BINARY
-- ADD METHOD TABLE BUILDER: BOOLEAN
-- ADD METHOD TABLE BUILDER: CHAR
-- ADD METHOD TABLE BUILDER: TIME
-- ADD METHOD TABLE BUILDER: DATE
-- ADD METHOD TABLE BUILDER: DATETIME
-- ADD METHOD TABLE BUILDER: ENUM
-- ADD METHOD TABLE BUILDER: FOREIGN KEY
-- BUG FIX TABLE BUILDER: PRIMARY KEY
Raw data
{
"_id": null,
"home_page": "https://github.com/ShibaRoPinoo/Shiba-Py-Mysql",
"name": "shiba-mysql",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "mysql,database,SQL,data access,ORM",
"author": "Rodrigo Pino",
"author_email": "ro.pinoo18@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e0/eb/04dcccfdd9734d5e39327f68dff71785e49c325ba269c9f4aa6109aaf5aa/shiba_mysql-1.1.1.tar.gz",
"platform": null,
"description": "# Shiba-Py-Mysql\r\n\r\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/ShibaRoPinoo/Shiba-Py-Mysql/blob/main/LICENSE)\r\n\r\nShiba-Py-Mysql is a lightweight Python library that provides a convenient interface for interacting with MySQL databases using the `pymysql` library. It simplifies common database administration tasks such as creating databases, selecting databases, creating tables, and performing basic CRUD operations.\r\n\r\n## Features\r\n\r\n- Easy database creation and selection.\r\n- Table creation with support for different column types.\r\n- Retrieving data from tables with support for JSON fields.\r\n\r\n## Installation\r\n\r\nYou can install Shiba-Py-Mysql using pip:\r\n\r\n```shell\r\npip install shiba-mysql\r\n```\r\n\r\n```python\r\n\r\nimport shiba as s\r\n\r\n# Create a connection to the MySQL database\r\nconnection = s.ShibaConnection(host='localhost', port=3306, user='myuser', password='mypassword')\r\n\r\n# Create a new database\r\nconnection.create_database('my_database')\r\n\r\n# Select the database\r\nconnection.use_database('my_database')\r\n\r\n# Create a table\r\ntable_builder = connection.create_table('users')\r\ntable_builder.increments('id')\r\ntable_builder.string('name', 20)\r\ntable_builder.integer('age')\r\ntable_builder.text('languages')\r\ntable_builder.text('settings')\r\ntable_builder.build()\r\n```\r\n\r\n```python\r\n# Insert data into the table\r\ndata_single = {\r\n \"name\": \"John\",\r\n \"age\": 30,\r\n \"languages\": json.dumps([\"Python\", \"JavaScript\", \"Java\"]),\r\n \"settings\": json.dumps({\"theme\": \"dark\", \"notifications\": True})\r\n}\r\n\r\ndata_list = [\r\n {\r\n \"name\": \"Alice\",\r\n \"age\": 25,\r\n \"languages\": json.dumps([\"Python\", \"C++\"]),\r\n \"settings\": json.dumps({\"theme\": \"light\", \"notifications\": False})\r\n },\r\n {\r\n \"name\": \"Bob\",\r\n \"age\": 35,\r\n \"languages\": json.dumps([\"JavaScript\", \"TypeScript\"]),\r\n \"settings\": json.dumps({\"theme\": \"dark\", \"notifications\": True})\r\n }\r\n]\r\n\r\ncx.table('users').insert(data_single)\r\ncx.table('users').insert(data_list)\r\n\r\nx = cx.table(\"users\").get()\r\nfor e in x:\r\n for k, v in e.items():\r\n if k == \"languages\":\r\n languages = json.loads(v)\r\n languages_str = \", \".join(languages)\r\n print(f\"Languages: {languages_str}\")\r\n elif k == \"settings\":\r\n settings_str = json.loads(v)\r\n print(f\"Settings\\n Theme: {settings_str['theme']}\\n Notifications: {settings_str['notifications']}\")\r\n else:\r\n print(f\"{k}: {str(v)}\")\r\n```\r\n\r\n## LICENSE\r\n\r\nThis project is under the [MIT License](https://github.com/ShibaRoPinoo/Shiba-Py-Mysql/blob/main/LICENSE).\r\n\r\nChange log\r\n\r\n==========\r\n1.0.0 (14/07/2023)\r\n------------------\r\n- FIRST RELEASE\r\n-- CREATE MODEL\r\n\r\n=========\r\n1.1.0 (15/07/2023)\r\n------------------\r\n- SECODN RELEASE\r\n-- ADD METHOD TABLE BUILDER: BINARY\r\n-- ADD METHOD TABLE BUILDER: BOOLEAN\r\n-- ADD METHOD TABLE BUILDER: CHAR\r\n-- ADD METHOD TABLE BUILDER: TIME\r\n-- ADD METHOD TABLE BUILDER: DATE\r\n-- ADD METHOD TABLE BUILDER: DATETIME\r\n-- ADD METHOD TABLE BUILDER: ENUM\r\n\r\n-- ADD METHOD TABLE BUILDER: FOREIGN KEY\r\n-- BUG FIX TABLE BUILDER: PRIMARY KEY\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library to interact with MySQL",
"version": "1.1.1",
"project_urls": {
"Homepage": "https://github.com/ShibaRoPinoo/Shiba-Py-Mysql"
},
"split_keywords": [
"mysql",
"database",
"sql",
"data access",
"orm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4987f92f061dca8edac4c8555379cff9af90f331cd43b66d174109f0c235910b",
"md5": "b6a7b3b633ab8fca206a6cb78fd05579",
"sha256": "9d38562330d341e96518a1b6e34116d4d4f181b3184012df3f02db5ee3a59dfc"
},
"downloads": -1,
"filename": "shiba_mysql-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b6a7b3b633ab8fca206a6cb78fd05579",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 13941,
"upload_time": "2023-07-16T01:32:02",
"upload_time_iso_8601": "2023-07-16T01:32:02.143161Z",
"url": "https://files.pythonhosted.org/packages/49/87/f92f061dca8edac4c8555379cff9af90f331cd43b66d174109f0c235910b/shiba_mysql-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e0eb04dcccfdd9734d5e39327f68dff71785e49c325ba269c9f4aa6109aaf5aa",
"md5": "7f3a9033f130617e7d19aaa3a9004908",
"sha256": "c4353ee3fe7dcc42871906e71a711ac3b74f0c966481a9a91ba889f2f2f26f6c"
},
"downloads": -1,
"filename": "shiba_mysql-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "7f3a9033f130617e7d19aaa3a9004908",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7323,
"upload_time": "2023-07-16T01:32:04",
"upload_time_iso_8601": "2023-07-16T01:32:04.363990Z",
"url": "https://files.pythonhosted.org/packages/e0/eb/04dcccfdd9734d5e39327f68dff71785e49c325ba269c9f4aa6109aaf5aa/shiba_mysql-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-16 01:32:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ShibaRoPinoo",
"github_project": "Shiba-Py-Mysql",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "shiba-mysql"
}