Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/e-gov/cursor-prompts/sqlalchemy-data-accessgit clone --depth 1 https://github.com/e-gov/cursor-promptsWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.01197 | $0.01197 |
| Opus 5 | $0.00598 | $0.00598 |
| Sonnet 5 | $0.00239 | $0.00239 |
| Haiku 4.5 | $0.00120 | $0.00120 |
Grade A, and why
sqlalchemy-data-access scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 75 lines — stays where its author put it; the contents beside it link to each section on GitHub.
SQLAlchemy 2.0 Async Data Access
Context
- Applies to database access in services and helpers using
AsyncSession(see your project’s database module andget_db/ session dependency). - SQL injection, parameterized access, least privilege DB users:
mdc:rules/common/security.mdc(Input Validation — ORMs/parameterization). This rule is the SQLAlchemy 2.0 async expression of those requirements in this repo. - Migrations vs runtime: schema changes via Alembic as separate deploy steps —
mdc:rules/common/component-technical-standards.mdc(Database & Data Management).
Core style (SQLAlchemy 2.0)
- Use
select()withawait session.execute(...), thenscalar_one(),scalar_one_or_none(),scalars().all(), orawait session.scalar(select(...))as appropriate. - Use
session.get(Model, pk)for primary-key lookups when you want identity-map behavior. - Do not use legacy
Session.query()on async sessions. - Prefer ORM entities and
Columnexpressions inwhere/order_by; build dynamic filters by composingsqlalchemy.and_/or_andConditionobjects — not by concatenating SQL.
Parameter binding and dynamic SQL
- Never concatenate raw SQL with user-controlled strings — see
mdc:rules/common/security.mdc. Use Core/ORM expressions so values are bound as parameters. - For LIKE / ILIKE with untrusted fragments, bind literals safely, for example:
column.ilike(func.concat("%", literal(user_fragment), "%"))
(pattern often lives in a small helper such as_author_filteron a service module).
- For dynamic ORDER BY, use an allowlist of column attributes (like
SORTABLE_FIELDS+getattr(Model, field)), not raw strings from the client.
Reads and shape of queries
- Pagination: Prefer
limit/offset(or keyset pagination for very large tables). Run a separatecount()query when the API needs total hits, as in paged list endpoints — avoid loading the full table to count rows. - Counts:
select(func.count()).select_from(Model).where(...)(orfunc.count(Model.id)) rather thanlen((await session.scalars(select(Model))).all()). - Columns: Use
select(Model.col1, Model.col2)when you intentionally need a narrow projection; map rows explicitly. - N+1: If you add relationships, load them in the same round trip with
selectinload()/joinedload()on the outerselect(), or use a single statement with joins — do not access unloaded collections in a loop without an eager-load strategy. - Large result sets: Never load unbounded
all()for user-facing endpoints withoutlimit. For batch jobs that scan many rows, use chunked queries (keyset/limitloops) or SQLAlchemy streaming APIs supported by your installed version, and keep transactions short.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 75 lines · 1,197 tokens per session scan A 773e41377d4e
sqlalchemy-data-access is a cursor rule published in the GitHub repository e-gov/cursor-prompts (34 stars, last pushed 4mo ago), licensed MIT. It adds 1,197 tokens to every session, about $0.0060 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other cursor rules, from other repositories
angular-20
This rule provides comprehensive best practices and coding standards for Angular development, focusing on modern TypeScript, standalone components, signals, and performance optimizations.
dev-standard
Apache Superset development standards and guidelines for Cursor IDE.
typescript
Changes to these high-fan-out internals can affect every message, delta, element, or rerun. Keep work in them minimal, and benchmark changes with representative stress-test apps.
coolify-ai-docs
Master reference to all Coolify AI documentation in .ai/ directory.
python_lib
Tips and guidelines specific to the development of the Streamlit Python library, not applicable to scripts and e2e tests.
specs
This directory contains product and tech specs for Streamlit features.