Skip to main content

A production-grade async MySQL ORM with LoopBack-style nested relation queries, typed model instances, and zero N+1.

Project description

🚀 Oceanic MySQL ORM Connector

A high-performance, asynchronous MySQL ORM for Python. Built for speed, deep relational integrity, and developer transparency.


📦 Core Features

  • Async First: Built on top of aiomysql for non-blocking I/O.
  • N+1 Prevention: Intelligent batch-loading for relations (no implicit lazy-loading penalties).
  • Relational Power: Supports One-to-One, One-to-Many, Many-to-Many (Through), and Self-referential models.
  • Additive Migrations: Safe, non-destructive schema synchronization.
  • Debug Echo: Real-time SQL monitoring with color-coded terminal output.

🏁 Initialization

from mysql_connector import MySQLConnector

connector = MySQLConnector(
    host="127.0.0.1",
    port=3306,
    user="root",
    password="yourpassword",
    database="your_db",
    echo=True  # Enables Query Debug Mode
)

await connector.connect()
await connector.migrate() # Synchronizes schema

📝 Model Definition

from mysql_connector import MySQLModel, Field, Relation

class User(MySQLModel):
    __table__ = "users"
    
    id    = Field(primary_key=True, auto_increment=True)
    name  = Field(nullable=False)
    email = Field(unique=True)
    
    # One-to-Many Relation
    posts = Relation("hasMany", target_model="Post", foreign_key="author_id")

class Post(MySQLModel):
    __table__ = "posts"
    
    id        = Field(primary_key=True)
    title     = Field()
    author_id = Field()

🔍 Query API

find(model_class, options)

Fetches a list of instances matching the criteria.

posts = await connector.find(Post, {
    "where": {"status": "published"},
    "order": ["id DESC"],
    "limit": 10,
    "include": ["author"] # Batch-loads authors
})

find_one(model_class, options)

Fetches a single instance or returns None.

find_by_id(model_class, pk_value, options)

Shortcut for fetching by primary key.

create(model_instance)

Inserts a new record and triggers before_create hooks.

update(model_instance)

Persists changes to an existing record.


🏗️ Relation Strategies

Type Direction Batch Strategy
belongsTo Child → Parent WHERE pk IN (...)
hasOne Parent → Child WHERE fk IN (...) LIMIT 1
hasMany Parent → Children WHERE fk IN (...)
hasManyThrough M2M Junction Query -> Target Query

🛠️ Schema Migration Policy (Safety First)

The Migrator follow an Additive-Only policy:

  • Missing Tables: Will be created automatically.
  • Missing Columns: Will be added (ALTER TABLE ADD COLUMN).
  • Extra Columns: Will be ignored. The ORM will never drop a column from your database, even if it is removed from models.py. This prevents accidental data loss during refactoring.

Scenario: Manual Column Removal If you wish to delete a column from the database, you must do so manually via SQL: ALTER TABLE table_name DROP COLUMN column_name;


📡 Debugging (Echo Mode)

When echo=True is passed to the constructor, the ORM prints formatted SQL to the console:

[ORM QUERY] SELECT * FROM users WHERE email = %s
[PARAMS]    ['alice@example.com']

This is essential for identifying inefficient queries during development.

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

oceanic_mysql_orm-1.0.5.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

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

oceanic_mysql_orm-1.0.5-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file oceanic_mysql_orm-1.0.5.tar.gz.

File metadata

  • Download URL: oceanic_mysql_orm-1.0.5.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for oceanic_mysql_orm-1.0.5.tar.gz
Algorithm Hash digest
SHA256 4f182c5cb5141d147b4fce852a8448c4ae53e66d31a5a9c6780bcec0ab9c7f01
MD5 6c73b13f4102cfd2f5e9dab79f6b2c9d
BLAKE2b-256 e65f57012abfed052916c06d0e3427d008397c3152b554190d17edb8b725ac97

See more details on using hashes here.

File details

Details for the file oceanic_mysql_orm-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for oceanic_mysql_orm-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 957815c60164728f113a324b7daa784568f6a63337d56bdef2756ef62cdfc300
MD5 b92a9e35adc5314292235851ccd2156a
BLAKE2b-256 4ff552eb8a79ca224b619da83423a432d9ff3b3845a747d40d7bf4ce94dbc760

See more details on using hashes here.

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