Metadata-Version: 2.4
Name: flaxon-sqlalchemy
Version: 0.1.0
Summary: Async SQLAlchemy integration for Flaxon applications
Author: Aldane Hutchinson
License: MIT
Project-URL: Repository, https://github.com/aldanedev-create/flaxon-sqlalchemy
Project-URL: Issues, https://github.com/aldanedev-create/flaxon-sqlalchemy/issues
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: AsyncIO
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Database
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: flaxon>=0.2.0
Requires-Dist: sqlalchemy>=2.0
Provides-Extra: postgresql
Requires-Dist: asyncpg>=0.29; extra == "postgresql"
Provides-Extra: sqlite
Requires-Dist: aiosqlite>=0.20; extra == "sqlite"
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Dynamic: license-file

# Flaxon SQLAlchemy

`flaxon-sqlalchemy` gives a Flaxon application one async SQLAlchemy engine and
session factory. It owns the engine lifecycle and exposes the integration as
`app.state.sqlalchemy`.

## Install

```bash
pip install "flaxon-sqlalchemy[postgresql]"
# or: pip install "flaxon-sqlalchemy[sqlite]"
```

Use an async SQLAlchemy URL, such as `postgresql+asyncpg://…` or
`sqlite+aiosqlite:///./app.db`.

## Use

```python
from flaxon import Flaxon
from flaxon_sqlalchemy import SQLAlchemyPlugin
from sqlalchemy import text

app = Flaxon("store")
await app.plugins.load_plugin(
    SQLAlchemyPlugin("postgresql+asyncpg://user:password@localhost/store")
)


@app.get("/orders")
async def list_orders():
    async with app.state.sqlalchemy.session() as session:
        result = await session.execute(text("SELECT id FROM orders"))
        return {"orders": list(result.scalars())}
```

The plugin connects during Flaxon's startup lifecycle and disposes its engine
during shutdown. Do not construct URLs with unescaped passwords; load them
from a secret manager or environment variable.

This package provides connection lifecycle and session access. Define models,
migrations, and transaction boundaries in your application.
