Code Monkey home page Code Monkey logo

shiba-py-mysql's Introduction

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-mysql
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()
# 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.

shiba-py-mysql's People

Contributors

ropinoo avatar shibaropinoo avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.