Skip to main content

A library to interact with MySQL

Project description

Shiba-Py-Mysql

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:

pip install shiba-py-mysql
from shiba import ShibaConnection

# Create a connection to the MySQL database
connection = 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()
# 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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shiba_mysql-1.0.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shiba_mysql-1.0.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file shiba_mysql-1.0.0.tar.gz.

File metadata

  • Download URL: shiba_mysql-1.0.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for shiba_mysql-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e33d3f2ae7380de3e2aba297538a23ee61b5a1c3ad12ee9f46b1d235136ed032
MD5 765e5e7b3deacb5d7a796d31c6c5025c
BLAKE2b-256 79102cc593226c593d2757608d656cdd24238a9041758dd56515b68463e17e9c

See more details on using hashes here.

File details

Details for the file shiba_mysql-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: shiba_mysql-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for shiba_mysql-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 612b45ae70a63edf8702e1b4fbf32f56f751444f036608ca3eb8ed11f981ceb0
MD5 06cf69a7fc75c43c04316bca0f0c3747
BLAKE2b-256 4df8744b03f96613ecde2d48f4e390c3413fecefea73205f595673175900da93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page