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.1.tar.gz
.
File metadata
- Download URL: sqlalchemy_sessionload-1.0.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.10.4 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9891616997da7892f099b875de12de60b17bacb14e7f3896a51e44192e812dda |
|
MD5 | a5e550ff1a3e9e6f0cd0275364670475 |
|
BLAKE2b-256 | 6ef801ceffd80f248bb9730bfac99813a389b54ba11ac03443baf04f3e7ac291 |
File details
Details for the file sqlalchemy_sessionload-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: sqlalchemy_sessionload-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.10.4 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 113efc37bd1a37fab3474b11097f5213f59be2a0e254c4ddbacce554ff7ae0d3 |
|
MD5 | 606ef18072f9f26806cd9c8006873c3c |
|
BLAKE2b-256 | b62fbad35913f8c4452ccf3cd8b349764f1f709b9eb77fd9dc4ad8e26cb079a1 |