SQLAlchemy load option that loads only from persisted session instances
Project description
sqlalchemy-sessionload
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:
from sqlalchemy_sessionload import SQLAlchemySessionLoad
Session = sessionmaker(...)
SQLAlchemySessionLoad(Session)
Simple Query
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.
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sqlalchemy_sessionload-1.0.2.tar.gz
.
File metadata
- Download URL: sqlalchemy_sessionload-1.0.2.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.9.3 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7192497d8db62a0ced3460e400ecb911e16ee03f4e67dfc94485489c732421c6 |
|
MD5 | 9d25198d88a303c9d10430a1650d2a4a |
|
BLAKE2b-256 | 26b57a81caca119318f24f53d6e2c4addeaba17c12730c623d68d6525dec0945 |
File details
Details for the file sqlalchemy_sessionload-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: sqlalchemy_sessionload-1.0.2-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.9.3 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e6e54c2756544e5981cfe4023fa42d122d0873add5658c2a498c97b768ad5d4 |
|
MD5 | 896ecd4a3eca0484e7e640205a4bf4a9 |
|
BLAKE2b-256 | a32477c21aee44335eb78171579494872a3d27f1b9668bad5a3c193a27b84288 |