Metadata-Version: 2.1
Name: sqlalchemy-sessionload
Version: 1.0.2
Summary: SQLAlchemy load option that loads only from persisted session instances
Keywords: sqlalchemy session loader
Author-Email: Jan Vollmer <jan@vllmr.dev>
License: MIT License
        
        Copyright (c) 2024 Jan Vollmer
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Plugins 
Project-URL: Source, https://github.com/jvllmr/sqlalchemy-sessionload
Requires-Python: >=3.8
Requires-Dist: sqlalchemy>=1.4
Description-Content-Type: text/markdown

# sqlalchemy-sessionload

![PyPI - Downloads](https://img.shields.io/pypi/dd/sqlalchemy-sessionload)
[![GitHub license](https://img.shields.io/github/license/jvllmr/sqlalchemy-sessionload)](https://github.com/jvllmr/sqlalchemy-sessionload/blob/dev/LICENSE)
[![Codecov](https://img.shields.io/codecov/c/github/jvllmr/sqlalchemy-sessionload/dev?style=plastic)](https://app.codecov.io/gh/jvllmr/sqlalchemy-sessionload/tree/dev)
[![Routine Checks](https://github.com/jvllmr/sqlalchemy-sessionload/actions/workflows/test.yaml/badge.svg)](https://github.com/jvllmr/sqlalchemy-sessionload/actions/workflows/test.yaml)

SQLAlchemy load option that loads from persisted session instances.

Supports SQLAlchemy 1.4

## Basic usage

SessionLoad is available for basic queries and relationship loading

Filters and Order By constructs are also supported.
If you miss something you are invited to contribute.

For installation the plugin has to be registered:

```python
from sqlalchemy_sessionload import SQLAlchemySessionLoad

Session = sessionmaker(...)
SQLAlchemySessionLoad(Session)
```

### Simple Query

```python
from sqlalchemy_sessionload import SessionLoad
from project.model import Message

# assignment is needed
# otherwise instances are not saved in session
all_messages = session.query(Message).all()

session_messages = session.query(Message).options(SessionLoad(Message)).all()
```

### Load relationship

Joined loading is currently only available with subqueryload.

```python
from sqlalchemy_sessionload import SessionRelationshipLoad
from project.model import Message, User
import sqlalchemy.orm as sa_orm

# assignment is needed
# otherwise instances are not saved in session
all_users = session.query(User).all()


# users connected to messages are now loaded from session
session_messages = (
    session.query(Message)
    .options(sa_orm.subqueryload(Message.user), SessionRelationshipLoad(Message.user))
    .all()
)
```

## Benchmark

A benchmark is available [here](https://jvllmr.github.io/sqlalchemy-sessionload/dev/bench)
