Skip to main content

MySQL backend implementation for rhosocial-activerecord, providing a robust and optimized MySQL database support.

Project description

rhosocial-activerecord-mysql ($\rho_{\mathbf{AR}\text{-mysql}}$)

PyPI version Python Tests Coverage Status License Powered by vistart

rhosocial ActiveRecord Logo

MySQL backend implementation for rhosocial-activerecord, providing a robust and optimized MySQL database support.

Overview

This package provides MySQL backend support for the rhosocial-activerecord ORM framework. It enables seamless integration with MySQL databases while leveraging all the features of the ActiveRecord pattern implementation.

Note: This is a backend implementation only and requires the main rhosocial-activerecord package to function properly.

Features

This project is still under development and features are subject to change. Please stay tuned for the latest changes.

  • 🚀 Optimized MySQL-specific query generation
  • 🔒 Full support for MySQL's unique features
  • 📦 Connection pooling support (optional)
  • 🔄 Comprehensive transaction management
  • 🔍 Advanced query capabilities specific to MySQL
  • 🔌 Simple configuration and setup

Requirements

  • Python 3.8+
  • rhosocial-activerecord 1.0.0+
  • mysql-connector-python 9.0.0+

Installation

pip install rhosocial-activerecord-mysql

Important: This package is a MySQL backend implementation for rhosocial-activerecord and cannot work independently. You must install and use it together with the main package.

For detailed usage of the main ActiveRecord framework, please refer to the rhosocial-activerecord documentation.

Usage

from rhosocial.activerecord.model import ActiveRecord
from rhosocial.activerecord.backend.impl.mysql.backend import MySQLBackend
from rhosocial.activerecord.backend.typing import ConnectionConfig
from datetime import datetime
from typing import Optional

class User(ActiveRecord):
    __table_name__ = 'users'
    
    id: int
    name: str
    email: str
    created_at: datetime
    deleted_at: Optional[datetime] = None

# Configure with MySQL backend
User.configure(
    ConnectionConfig(
        host='localhost',
        port=3306,
        database='myapp',
        user='dbuser',
        password='dbpassword'
    ),
    backend_class=MySQLBackend
)

# Create a table (if not exists)
User.create_table_if_not_exists()

# Create a new user
user = User(name='John Doe', email='john@example.com', created_at=datetime.now())
user.save()

# Query users
active_users = User.query() \
    .where('deleted_at IS NULL') \
    .order_by('created_at DESC') \
    .all()

# Update user
user.name = 'Jane Doe'
user.save()

# Delete user (soft delete if implemented)
user.delete()

Advanced MySQL Features

This backend supports MySQL-specific features and optimizations:

# Using MySQL fulltext search
results = User.query() \
    .where('MATCH(name, email) AGAINST(? IN BOOLEAN MODE)', ('+John -Doe', )) \
    .all()

# Using MySQL JSON operations
results = User.query() \
    .where('settings->>"$.notifications" = ?', ('enabled', )) \
    .all()

# Batch insert with ON DUPLICATE KEY UPDATE
User.batch_insert_or_update([user1, user2, user3])

Documentation

Complete documentation is available at python-activerecord MySQL Backend

Contributing

We welcome and value all forms of contributions! For details on how to contribute, please see our Contributing Guide.

License

license

Copyright © 2025 vistart

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rhosocial_activerecord_mysql-1.0.0.dev4.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file rhosocial_activerecord_mysql-1.0.0.dev4.tar.gz.

File metadata

File hashes

Hashes for rhosocial_activerecord_mysql-1.0.0.dev4.tar.gz
Algorithm Hash digest
SHA256 e00803998d857330ca352d03e865096d54dee8ddb08ed3ab468183ca82bbdb2f
MD5 e84556a8d6c34999b857086fae57cefe
BLAKE2b-256 08c3e3522fc44efa449fe0dddd19300151ddd5674a7504bac78a60ab3284e468

See more details on using hashes here.

Provenance

The following attestation bundles were made for rhosocial_activerecord_mysql-1.0.0.dev4.tar.gz:

Publisher: publish.yml on rhosocial/python-activerecord-mysql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rhosocial_activerecord_mysql-1.0.0.dev4-py3-none-any.whl.

File metadata

File hashes

Hashes for rhosocial_activerecord_mysql-1.0.0.dev4-py3-none-any.whl
Algorithm Hash digest
SHA256 a84270eb773ef1a863b3ecd156d2846d6b1049f4b456f0f0f4406d3570a49e92
MD5 78e4de893b52b85b39927ff04dcc16c8
BLAKE2b-256 26fbbb3a8836c8f5d31e1ee0da1f40846c482380ee4a974d63ec349eee811194

See more details on using hashes here.

Provenance

The following attestation bundles were made for rhosocial_activerecord_mysql-1.0.0.dev4-py3-none-any.whl:

Publisher: publish.yml on rhosocial/python-activerecord-mysql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page