easy calls to mysql databases
Project description
A lightweight and dynamic wrapper around mysql.connector to simplify MySQL database interactions with schema-driven table creation, automatic connection handling, and Python object mapping.
pip install mysql-database
📁 Project Structure
Your project must include a schemas/ folder (or custom path) containing JSON schema files for each database.
Example:
schemas/
└── mydatabase.json
in this case the database name will be 'mydatabase'
Each file should follow this format:
{
"users": {
"name": "VARCHAR(255)",
"email": "VARCHAR(255)",
"active": "BOOLEAN"
},
"products": {
"title": "VARCHAR(255)",
"price": "FLOAT",
"users_id": "INT"
}
}
to use FOREIGN KEY create an INT column <foreign_table>_id: for example in the schema above users_id will be assosiated with the table users
🚀 Usage Example
from mysql_database import Database, DatabaseCreds
# Define credentials
creds = DatabaseCreds(
host="localhost",
user="root",
password="yourpassword",
port=3306
)
# Initialize database (auto-creates DB and tables if they don't exist)
db = Database(name="mydatabase", creds=creds)
# Add object
user_id = db.add_object("users", {
"name": "Alice",
"email": "alice@example.com",
"active": True
})
# Get list of user objects
users = db.get_list_of_objects("users")
# Get user by ID
user = db.get_object_by_id("users", user_id)
# Update user
db.update_object("users", user_id, {"active": False})
# Delete user
db.delete_object("users", user_id)
🔍 Advanced Usage
Get filtered list of objects:
db.get_filtered_list_of_objects(
object_type="users",
filter="alice",
include_columns=['name', 'email']
as_dict=True
)
📄 License
MIT License. See LICENSE file for details.
---
Let me know if you'd like to add badges (PyPI version, license, etc.) to the top of the README.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mysql_database-0.1.10.tar.gz.
File metadata
- Download URL: mysql_database-0.1.10.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fd0cdc366b2b4a9868f8efcc45291a83ba83997c1682a94de52735984e72047
|
|
| MD5 |
2a86f34749a3c7ff469f5daa522b990f
|
|
| BLAKE2b-256 |
f8dcad49e6571e6987345126c9ac87ad1e60b51092909a9bf75717dd91d6dd5e
|
File details
Details for the file mysql_database-0.1.10-py3-none-any.whl.
File metadata
- Download URL: mysql_database-0.1.10-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
451a7f368c78aac0c7157e7baa4c468e78469499a525cbc205da505a9ab89432
|
|
| MD5 |
c482883d408520962da09de8f2a65013
|
|
| BLAKE2b-256 |
d1860d48cce14a40be3154b9db39ae6f4c1c27fea6c3d758e70a7a7d8996fd25
|