{"id":26558365,"url":"https://github.com/rhosocial/python-activerecord-mysql","last_synced_at":"2026-04-12T20:02:21.397Z","repository":{"id":282358205,"uuid":"936983323","full_name":"rhosocial/python-activerecord-mysql","owner":"rhosocial","description":"A MySQL backend implementation that brings MySQL's robust features and performance optimizations to the ActiveRecord pattern while maintaining its elegant Pythonic interface.","archived":false,"fork":false,"pushed_at":"2026-03-27T04:10:03.000Z","size":698,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-03-27T15:53:58.448Z","etag":null,"topics":["activerecord","database","mysql","orm","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhosocial.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-22T04:04:12.000Z","updated_at":"2026-03-22T07:22:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"b45bd3c3-b1d5-454d-ad5c-509f22e5552a","html_url":"https://github.com/rhosocial/python-activerecord-mysql","commit_stats":null,"previous_names":["rhosocial/python-activerecord-mysql"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/rhosocial/python-activerecord-mysql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhosocial%2Fpython-activerecord-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhosocial%2Fpython-activerecord-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhosocial%2Fpython-activerecord-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhosocial%2Fpython-activerecord-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhosocial","download_url":"https://codeload.github.com/rhosocial/python-activerecord-mysql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhosocial%2Fpython-activerecord-mysql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31292789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T21:15:39.731Z","status":"ssl_error","status_checked_at":"2026-04-01T21:15:34.046Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","database","mysql","orm","python"],"created_at":"2025-03-22T12:36:35.956Z","updated_at":"2026-04-01T23:03:50.220Z","avatar_url":"https://github.com/rhosocial.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rhosocial-activerecord-mysql ($\\rho_{\\mathbf{AR}\\text{-mysql}}$)\n\n[![PyPI version](https://badge.fury.io/py/rhosocial-activerecord-mysql.svg)](https://badge.fury.io/py/rhosocial-activerecord-mysql)\n[![Python](https://img.shields.io/pypi/pyversions/rhosocial-activerecord-mysql.svg)](https://pypi.org/project/rhosocial-activerecord-mysql/)\n[![Tests](https://github.com/rhosocial/python-activerecord-mysql/actions/workflows/test.yml/badge.svg)](https://github.com/rhosocial/python-activerecord-mysql/actions)\n[![Coverage Status](https://codecov.io/gh/rhosocial/python-activerecord-mysql/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rhosocial/python-activerecord-mysql/tree/main)\n[![Apache 2.0 License](https://img.shields.io/github/license/rhosocial/python-activerecord-mysql.svg)](https://github.com/rhosocial/python-activerecord-mysql/blob/main/LICENSE)\n[![Powered by vistart](https://img.shields.io/badge/Powered_by-vistart-blue.svg)](https://github.com/vistart)\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/rhosocial/python-activerecord/main/docs/images/logo.svg\" alt=\"rhosocial ActiveRecord Logo\" width=\"200\"/\u003e\n    \u003ch3\u003eMySQL Backend for rhosocial-activerecord\u003c/h3\u003e\n    \u003cp\u003e\u003cb\u003eProduction-Ready MySQL Support · Sync \u0026 Async · Native Driver Integration\u003c/b\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n\u003e **Note**: This is a backend implementation for [rhosocial-activerecord](https://github.com/rhosocial/python-activerecord). It cannot be used standalone.\n\n## Why This Backend?\n\n### 1. MySQL-Specific Optimizations\n\n| Feature | This Backend | Generic Solutions |\n|---------|-------------|-------------------|\n| **Full-Text Search** | Native `MATCH ... AGAINST` | LIKE-based workarounds |\n| **JSON Operations** | `JSON_EXTRACT`, `-\u003e\u003e`, `-\u003e` | Serialize/deserialize overhead |\n| **Upsert** | `ON DUPLICATE KEY UPDATE` | Manual check-then-insert |\n| **Connection Pooling** | Built-in with mysql-connector | External pooling required |\n\n### 2. True Sync-Async Parity\n\nSame API surface for both sync and async operations:\n\n```python\n# Sync\nusers = User.query().where(User.c.age \u003e= 18).all()\n\n# Async - just add await\nusers = await User.query().where(User.c.age \u003e= 18).all()\n```\n\n### 3. Built for Production\n\n- **Connection pooling** with configurable pool sizes\n- **Transaction support** with proper isolation levels\n- **Error mapping** from MySQL error codes to Python exceptions\n- **Type adapters** for MySQL-specific data types\n\n## Quick Start\n\n### Installation\n\n```bash\npip install rhosocial-activerecord-mysql\n```\n\n### Basic Usage\n\n```python\nfrom rhosocial.activerecord.model import ActiveRecord\nfrom rhosocial.activerecord.backend.impl.mysql import MySQLBackend\nfrom rhosocial.activerecord.backend.impl.mysql.config import MySQLConnectionConfig\nfrom typing import Optional\n\nclass User(ActiveRecord):\n    __table_name__ = \"users\"\n    id: Optional[int] = None\n    name: str\n    email: str\n\n# Configure\nconfig = MySQLConnectionConfig(\n    host=\"localhost\",\n    port=3306,\n    database=\"myapp\",\n    username=\"user\",\n    password=\"password\"\n)\nUser.configure(config, MySQLBackend)\n\n# Use\nuser = User(name=\"Alice\", email=\"alice@example.com\")\nuser.save()\n\n# Query with MySQL full-text search\nresults = User.query().where(\n    \"MATCH(name, email) AGAINST(? IN BOOLEAN MODE)\",\n    (\"+Alice\",)\n).all()\n```\n\n\u003e 💡 **AI Prompt**: \"Show me how to use JSON operations in MySQL with this backend\"\n\n## MySQL-Specific Features\n\n### Full-Text Search\n\nNative MySQL full-text search support:\n\n```python\n# Boolean mode full-text search\nArticle.query().where(\n    \"MATCH(title, content) AGAINST(? IN BOOLEAN MODE)\",\n    (\"+python -java\",)\n).all()\n\n# Natural language mode\nArticle.query().where(\n    \"MATCH(title, content) AGAINST(?)\",\n    (\"database optimization\",)\n).all()\n```\n\n### JSON Operations\n\nQuery JSON columns using MySQL's native JSON functions:\n\n```python\n# Extract JSON value\nUser.query().where(\"settings-\u003e\u003e'$.theme' = ?\", (\"dark\",)).all()\n\n# JSON contains\nProduct.query().where(\"JSON_CONTAINS(tags, ?)\", ('\"featured\"',)).all()\n```\n\n### Upsert (ON DUPLICATE KEY UPDATE)\n\nEfficient insert-or-update operations:\n\n```python\n# Will update on duplicate key\nUser.insert_or_update(\n    name=\"Alice\",\n    email=\"alice@example.com\",\n    update_fields=[\"name\"]  # Only update name on conflict\n)\n```\n\n## Requirements\n\n- **Python**: 3.8+ (including 3.13t/3.14t free-threaded builds)\n- **Core**: `rhosocial-activerecord\u003e=1.0.0`\n- **Driver**: `mysql-connector-python\u003e=9.0.0`\n\n## Get Started with AI Code Agents\n\nThis project supports AI-assisted development. Clone and open in your preferred tool:\n\n```bash\ngit clone https://github.com/rhosocial/python-activerecord-mysql.git\ncd python-activerecord-mysql\n```\n\n### Example AI Prompts\n\n- \"How do I configure connection pooling for MySQL?\"\n- \"Show me the differences between MySQL and PostgreSQL backends\"\n- \"How do I use MySQL-specific JSON operators?\"\n- \"Create a model with a FULLTEXT index\"\n\n### For Any LLM\n\nFeed the documentation files in `docs/` to your preferred LLM for context-aware assistance.\n\n## Testing\n\n\u003e ⚠️ **CRITICAL**: Tests MUST run serially. Do NOT use `pytest -n auto` or parallel execution.\n\n```bash\n# Run all tests\nPYTHONPATH=src pytest tests/\n\n# Run specific feature tests\nPYTHONPATH=src pytest tests/rhosocial/activerecord_mysql_test/feature/basic/\nPYTHONPATH=src pytest tests/rhosocial/activerecord_mysql_test/feature/query/\n```\n\nSee the [Testing Documentation](https://github.com/rhosocial/python-activerecord/blob/main/.claude/testing.md) for details.\n\n## Documentation\n\n- **[Getting Started](docs/en_US/getting_started/)** — Installation and configuration\n- **[MySQL Features](docs/en_US/mysql_specific_features/)** — MySQL-specific capabilities\n- **[Type Adapters](docs/en_US/type_adapters/)** — Data type handling\n- **[Transaction Support](docs/en_US/transaction_support/)** — Transaction management\n\n## Comparison with Other Backends\n\n| Feature | MySQL | PostgreSQL | SQLite |\n|---------|-------|------------|--------|\n| **Full-Text Search** | ✅ Native | ✅ Native | ⚠️ FTS5 extension |\n| **JSON Type** | ✅ JSON | ✅ JSONB | ⚠️ JSON1 extension |\n| **Arrays** | ❌ | ✅ Native | ❌ |\n| **Upsert** | ✅ ON DUPLICATE KEY | ✅ ON CONFLICT | ✅ ON CONFLICT |\n| **Returning** | ❌ | ✅ RETURNING | ✅ RETURNING |\n\n\u003e 💡 **AI Prompt**: \"When should I choose MySQL over PostgreSQL for my project?\"\n\n## Contributing\n\nWe welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n## License\n\n[Apache License 2.0](LICENSE) — Copyright © 2026 [vistart](https://github.com/vistart)\n\n---\n\n\u003cdiv align=\"center\"\u003e\n    \u003cp\u003e\u003cb\u003eBuilt with ❤️ by the rhosocial team\u003c/b\u003e\u003c/p\u003e\n    \u003cp\u003e\u003ca href=\"https://github.com/rhosocial/python-activerecord-mysql\"\u003eGitHub\u003c/a\u003e · \u003ca href=\"https://docs.python-activerecord.dev.rho.social/backends/mysql.html\"\u003eDocumentation\u003c/a\u003e · \u003ca href=\"https://pypi.org/project/rhosocial-activerecord-mysql/\"\u003ePyPI\u003c/a\u003e\u003c/p\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhosocial%2Fpython-activerecord-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhosocial%2Fpython-activerecord-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhosocial%2Fpython-activerecord-mysql/lists"}