SQLAlchemy load option that loads only from persisted session instances
Project description
sqlalchemy-sessionload
SQLAlchemy load option that loads from persisted session instances.
The goal of this load option is to achieve performance gains in specific use-cases by not querying the database or serializing new objects and reading from cache instead. This means that you as a user need to make sure before that all of the objects you expect to find within a query are already present the session store. Use with care!
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy_sessionload-1.1.0.post2.tar.gz.
File metadata
- Download URL: sqlalchemy_sessionload-1.1.0.post2.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.26.0 CPython/3.10.18 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5e6eba38387914babf6d95f9e01114ffd69a28172e3c58bd9bb0f43ee869e66
|
|
| MD5 |
5e3a27babc941242428abda2dfff7483
|
|
| BLAKE2b-256 |
c8c4824f88d7d86a2c2ec1218b97be60b8bdebe537accb3ae3d5f1f624ef22ae
|
File details
Details for the file sqlalchemy_sessionload-1.1.0.post2-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_sessionload-1.1.0.post2-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.26.0 CPython/3.10.18 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9a9aa519c30798c4bb069b2bdb3eae412c40f2f3b769239c518084c9ea1624e
|
|
| MD5 |
28f7aafada9a5f82f8c51b21d062a7cc
|
|
| BLAKE2b-256 |
c7187b005891b03cf6801e4967226b63e28f617e21d50b242b1d018ab2ca9642
|