Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jvllmr/sqlalchemy-sessionload
SQLAlchemy load option that loads from persisted session instances. SQLAlchemy 1.4 supported
https://github.com/jvllmr/sqlalchemy-sessionload
loader plugin sqlalchemy sqlalchemy-orm-queries
Last synced: about 2 months ago
JSON representation
SQLAlchemy load option that loads from persisted session instances. SQLAlchemy 1.4 supported
- Host: GitHub
- URL: https://github.com/jvllmr/sqlalchemy-sessionload
- Owner: jvllmr
- License: mit
- Created: 2023-12-15T18:22:38.000Z (about 1 year ago)
- Default Branch: dev
- Last Pushed: 2024-11-04T22:00:18.000Z (about 2 months ago)
- Last Synced: 2024-11-04T23:17:12.646Z (about 2 months ago)
- Topics: loader, plugin, sqlalchemy, sqlalchemy-orm-queries
- Language: Python
- Homepage:
- Size: 271 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
Awesome Lists containing this project
README
# 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 SQLAlchemySessionLoadSession = 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)