Lightweight query access-pattern declaration for ORMs
Project description
query-patterns
Declare query-access patterns in code and verify matching DB indexes. Supports SQLAlchemy and Django, both schema-based and database introspection modes.
What it does
- Collects all @query_pattern declarations from your Python modules
- Extracts index definitions from:
- SQLAlchemy
- ORM schema (MetaData)
- Actual DB (Inspector)
- Django
- ORM schema (Model._meta.indexes)
- Actual DB (connection.introspection)
- SQLAlchemy
- Compares (table, columns) tuples
- Reports:
- [OK] — index exists
- [MISSING] — index missing
- Can be integrated into CI to enforce index coverage
Example output
- [OK] users('email',)
- [MISSING] orders('user_id',)
Install
pip install query-patterns
Declare a pattern
from query_patterns import query_pattern
class Repo:
@query_pattern(table="users", columns=["email"])
def find(self, email): ...
1. SQLAlchemy Command
# Reads indexes from MetaData
query-patterns sqlalchemy \
--metadata myapp.db.metadata \
--module myapp.repo
# Auto-discover modules
query-patterns sqlalchemy \
--metadata myapp.db.metadata
# Reads actual indexes from the database
query-patterns sqlalchemy \
--source db \
--engine-url postgresql://user:pass@localhost/mydb \
--module myapp.repo
2. Django Command
# Reads Model._meta.indexes from installed apps
query-patterns django \
--settings config.settings \
--module myapp.repo
# Auto-discover modules
query-patterns django \
--settings config.settings
# Reads actual DB indexes using Django introspection
query-patterns django \
--source db \
--settings config.settings \
--module myapp.repo
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
query_patterns-0.1.4.tar.gz
(11.4 kB
view details)
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 query_patterns-0.1.4.tar.gz.
File metadata
- Download URL: query_patterns-0.1.4.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5eb5cd904ac73545d173b3c966b7dafa5239f2b373f36fa7bd59577913359a1
|
|
| MD5 |
264e5634457b16b55ce46bcf4d5acbe0
|
|
| BLAKE2b-256 |
d5144ce5d810e9baeebf3f590c9bb898dec63ff2d2263c6c95ec9fb787ae842c
|
File details
Details for the file query_patterns-0.1.4-py3-none-any.whl.
File metadata
- Download URL: query_patterns-0.1.4-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e68f1a31bb45a173cbd8bd8e180c195902a5c14e9f67540855f110d8941b1e4d
|
|
| MD5 |
d801aad023781cb88fcf1826a36a6188
|
|
| BLAKE2b-256 |
86a2adf1e3af237b664d357810df0eaf6e2985a3f0abd35f0e958ce50c0af259
|