Skip to main content

PyWithMySQL

PyWithMySQL is a simple and easy-to-use Python library for working with MySQL databases. It provides methods for connecting to the database, performing CRUD operations, and handling MySQL queries efficiently.

Installation You can install the library using pip:

pip install pywithmysql==0.1.7 Features Easy connection setup with MySQL Supports basic CRUD operations (Create, Read, Update, Delete) Flexible and extensible methods Error handling for database operations

Usage Here is a quick example of how to use the library:

from pywithmysql.settings import SettingsTable
from pywithmysql.config import DataBaseConfig

# Define your database configuration
config = DataBaseConfig(
    host="localhost",
    port=3306,
    user="root",
    password="password",
    db_name="test_db"
)

# Initialize the settings table with the table name
table = SettingsTable(config, "users")

# Connect to the database
table.connect()

# Create a new entry in the table
table.create(names=["name", "age"], values=["'Alice'", "30"])

# Read all entries from the table
rows = table.read_all()
for row in rows:
    print(row)

# Update an entry
table.update_data(names=("age",), values=("31",), id=1)

# Delete an entry by id
table.delete_for_id(id=1)

# Disconnect from the database
table.disconnect()

Creating a Table

To create a table, use the Table class along with the Column class to define columns. Here’s a code example:

from pywithmysql.table import Table, Column
from pywithmysql.types import IntegerField, CharField
from pywithmysql.config import DataBaseConfig

# Database connection settings
config = DataBaseConfig(
    host="localhost",
    port=3306,
    user="user",
    password="password",
    db_name="db_name"
)

# Initialize Table
table = Table(
    "users",
    config,
    Column("username", CharField, max_length=45, nullable=False, unique=True),
    Column("age", IntegerField, default=18),
    Column("email", CharField, max_length=100, unique=True, nullable=False),
    Column("phone_number", CharField, unique=True)

)

# Create the table
table.create_table()

Methods

connect() Establishes a connection to the MySQL database using the provided configuration.

create(names: list, values: list) Inserts a new row into the table. You must provide column names and their corresponding values.

read_all() Fetches all rows from the table.

update_data(names: tuple, values: tuple, id: int) Updates specific fields for a row with the given id.

delete_for_id(id: int) Deletes a row from the table based on the provided id.

disconnect() Closes the connection to the MySQL database.

License

This project is licensed under the MIT License.

Metadata

Release files for pywithmysql 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pywithmysql 0.1.9
File Size Uploaded Provenance Actions
pywithmysql-0.1.9.tar.gz 7.3 kB Without provenance Details for pywithmysql-0.1.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pywithmysql 0.1.9
File Interpreter ABI Platform Actions
pywithmysql-0.1.9-py3-none-any.whl Python 3 none any Details for pywithmysql-0.1.9-py3-none-any.whl

Total release size: 15.8 kB

Release files / pywithmysql-0.1.9.tar.gz

Download URL pywithmysql-0.1.9.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9b159486c921f70bc07134cccea4a358b77679e49c60dff4d90a0ca70eec57b9
BLAKE2b-256 checksum
How to use checksums
5d187543d5dd2c5de8dcad493b76afa263d2223a033ba87a7471c684514205fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.4

Release files / pywithmysql-0.1.9-py3-none-any.whl

Download URL pywithmysql-0.1.9-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f371df330c1ed7c902bcfef22ce4e9b1cba631321da3019a491c76e2802e484
BLAKE2b-256 checksum
How to use checksums
3710ecccb06e197d92e2486077ba0128273b24ddbd9892cbbc285d203208ac8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.4

Security for pywithmysql 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page