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:
```json
{
"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
```python
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:
```python
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.
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Ms-Shoshany/mysql-database",
"name": "mysql-database",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "hanna",
"author_email": "channashosh@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/31/3b/b126c9f71d4a98e238cbd2f0649c66759e71479d351c9f33cf01bdd8799b/mysql_database-0.1.9.tar.gz",
"platform": null,
"description": "\r\n\r\n\r\nA lightweight and dynamic wrapper around `mysql.connector` to simplify MySQL database interactions with schema-driven table creation, automatic connection handling, and Python object mapping.\r\n\r\n---\r\npip install mysql-database\r\n---\r\n\r\n## \ud83d\udcc1 Project Structure\r\n\r\nYour project must include a `schemas/` folder (or custom path) containing JSON schema files for each database.\r\n\r\nExample:\r\n\r\n```\r\nschemas/\r\n\u2514\u2500\u2500 mydatabase.json\r\n```\r\nin this case the database name will be 'mydatabase'\r\n\r\nEach file should follow this format:\r\n\r\n```json\r\n{\r\n \"users\": {\r\n \"name\": \"VARCHAR(255)\",\r\n \"email\": \"VARCHAR(255)\",\r\n \"active\": \"BOOLEAN\"\r\n },\r\n \r\n \"products\": {\r\n \"title\": \"VARCHAR(255)\",\r\n \"price\": \"FLOAT\",\r\n \"users_id\": \"INT\"\r\n }\r\n}\r\n```\r\nto use FOREIGN KEY create an INT column <foreign_table>_id:\r\n for example in the schema above\r\n users_id will be assosiated with the table users\r\n---\r\n\r\n## \ud83d\ude80 Usage Example\r\n\r\n```python\r\nfrom mysql_database import Database, DatabaseCreds\r\n\r\n# Define credentials\r\ncreds = DatabaseCreds(\r\n host=\"localhost\",\r\n user=\"root\",\r\n password=\"yourpassword\",\r\n port=3306\r\n)\r\n\r\n# Initialize database (auto-creates DB and tables if they don't exist)\r\ndb = Database(name=\"mydatabase\", creds=creds)\r\n\r\n# Add object\r\nuser_id = db.add_object(\"users\", {\r\n \"name\": \"Alice\",\r\n \"email\": \"alice@example.com\",\r\n \"active\": True\r\n})\r\n\r\n# Get list of user objects\r\nusers = db.get_list_of_objects(\"users\")\r\n\r\n# Get user by ID\r\nuser = db.get_object_by_id(\"users\", user_id)\r\n\r\n# Update user\r\ndb.update_object(\"users\", user_id, {\"active\": False})\r\n\r\n# Delete user\r\ndb.delete_object(\"users\", user_id)\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udd0d Advanced Usage\r\n\r\n### Get filtered list of objects:\r\n\r\n```python\r\ndb.get_filtered_list_of_objects(\r\n object_type=\"users\",\r\n filter=\"alice\",\r\n include_columns=['name', 'email']\r\n as_dict=True\r\n)\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udcc4 License\r\n\r\nMIT License. See `LICENSE` file for details.\r\n\r\n```\r\n\r\n---\r\n\r\nLet me know if you'd like to add badges (PyPI version, license, etc.) to the top of the README.\r\n```\r\n",
"bugtrack_url": null,
"license": null,
"summary": "easy calls to mysql databases",
"version": "0.1.9",
"project_urls": {
"Homepage": "https://github.com/Ms-Shoshany/mysql-database"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "dc57e02b44afb373cb16da0c79047b596395ec7988a381ecf8d88f6a38282eda",
"md5": "643ed8855aac3c65e906bf1ea095f11d",
"sha256": "62ee6dce950fd18c092e1bd5d41d13b807c489c93a403dc764f5b08205a392ac"
},
"downloads": -1,
"filename": "mysql_database-0.1.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "643ed8855aac3c65e906bf1ea095f11d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5533,
"upload_time": "2025-07-12T04:53:44",
"upload_time_iso_8601": "2025-07-12T04:53:44.900148Z",
"url": "https://files.pythonhosted.org/packages/dc/57/e02b44afb373cb16da0c79047b596395ec7988a381ecf8d88f6a38282eda/mysql_database-0.1.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "313bb126c9f71d4a98e238cbd2f0649c66759e71479d351c9f33cf01bdd8799b",
"md5": "fc82fa6ae8f3a5291f4c3e1edbd021dd",
"sha256": "55401cd21dd2d4dbc19d4a53d9e6c177489b4c85bc65cf831acf8da32985e466"
},
"downloads": -1,
"filename": "mysql_database-0.1.9.tar.gz",
"has_sig": false,
"md5_digest": "fc82fa6ae8f3a5291f4c3e1edbd021dd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 4765,
"upload_time": "2025-07-12T04:53:46",
"upload_time_iso_8601": "2025-07-12T04:53:46.114214Z",
"url": "https://files.pythonhosted.org/packages/31/3b/b126c9f71d4a98e238cbd2f0649c66759e71479d351c9f33cf01bdd8799b/mysql_database-0.1.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-12 04:53:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Ms-Shoshany",
"github_project": "mysql-database",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "mysql-database"
}