Metadata-Version: 2.4
Name: mybatis-plus-py
Version: 0.2.0
Summary: Python implementation of MyBatis-Plus: generic CRUD, fluent query builder, Pydantic-driven entity mapping, multi-dialect support, and pluggable middleware chain.
Author: mybatis-plus-py contributors
License: Apache-2.0
Project-URL: Homepage, https://github.com/mybatis-plus-py/mybatis-plus-py
Project-URL: Repository, https://github.com/mybatis-plus-py/mybatis-plus-py
Keywords: mybatis,orm,database,sql,query-builder,crud
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0
Requires-Dist: sqlparse>=0.5.0
Provides-Extra: postgres
Requires-Dist: psycopg2-binary>=2.9; extra == "postgres"
Provides-Extra: postgres-prod
Requires-Dist: psycopg2>=2.9; extra == "postgres-prod"
Provides-Extra: mysql
Requires-Dist: pymysql>=1.1; extra == "mysql"
Provides-Extra: async-sqlite
Requires-Dist: aiosqlite>=0.20; extra == "async-sqlite"
Provides-Extra: async-postgres
Requires-Dist: asyncpg>=0.29; extra == "async-postgres"
Provides-Extra: async-mysql
Requires-Dist: aiomysql>=0.2; extra == "async-mysql"
Provides-Extra: async-all
Requires-Dist: aiosqlite>=0.20; extra == "async-all"
Requires-Dist: asyncpg>=0.29; extra == "async-all"
Requires-Dist: aiomysql>=0.2; extra == "async-all"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: mypy>=1.8; extra == "dev"
Requires-Dist: ruff>=0.3; extra == "dev"
Requires-Dist: aiosqlite>=0.20; extra == "dev"
Dynamic: license-file

# mybatis-plus-py

Python implementation of MyBatis-Plus: Pydantic-driven entity mapping, generic CRUD repositories, fluent query builder, multi-dialect support (SQLite / PostgreSQL / MySQL), Druid-style connection pool, and MyBatis-Plus style SQL interceptor pipeline.

## Quick Start

```bash
pip install mybatis-plus-py
# with database driver extras
pip install mybatis-plus-py[postgres]  # or [mysql]
```

```python
from pydantic import BaseModel
from mybatis_plus import entity, Field, Query, BaseRepository, SQLiteDataSource, EntitySession, SqlExecutor

@entity(table="users")
class User(BaseModel):
    id: int = Field(primary_key=True, auto_increment=True)
    name: str
    age: int = Field(default=18)

ds = SQLiteDataSource(":memory:")
session = EntitySession(SqlExecutor(ds))
session.create_table(User)
session.insert(User(name="Alice", age=30))

# Fluent query
adults = session.select_list(User, Query().gt("age", 18))

# Repository
repo = BaseRepository(User, session)
page = repo.select_page(Query().order_by("id"), page=1, size=10)
```

## Database Support

| Database | Driver | Datasource |
|----------|--------|------------|
| SQLite | stdlib `sqlite3` | `SQLiteDataSource` |
| PostgreSQL | `psycopg2` | `PostgresDataSource` |
| MySQL | `pymysql` | `MySQLDataSource` |

## Key Features

- **Entity mapping** — `@entity()` + `Field()` with primary keys, auto-increment, version, soft delete, auto-fill
- **Fluent query builder** — `Query().eq("name", "Tom").gt("age", 18).order_by("id")`
- **Generic CRUD** — `BaseRepository[T]` with insert, update, delete, select, pagination
- **Chain wrappers** — `ChainQuery(User, session).eq("age", 18).list()`
- **SQL interceptors** — MyBatis-Plus style `InnerInterceptor` / `MybatisPlusInterceptor` pipeline with `PaginationInnerInterceptor`
- **Connection pool** — Druid-style pool with ExceptionSorter, ValidConnectionChecker, RemoveAbandoned, PreparedStatementPool
- **Middleware** — Tenant, logic delete, optimistic lock, auto-fill, block attack, dynamic table name

## Architecture

```
Entity API / Repository / Chain / ActiveRecord
        -> EntitySession
        -> SqlBuilder + EntityMetaRegistry
        -> SqlExecutor
        -> MybatisPlusInterceptor + StatementHandler
        -> ParameterHandler / ResultSetHandler
        -> DataSource / Dialect
```

## License

Apache-2.0
