tortoise / tortoise/tortoise-orm

CTE Support

Open
#819 22 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Is your feature request related to a problem? Please describe.
CTE is a feature that is integrated into other ORMs such as sqlalchemy. It allows to represent hierarchies, which are common for things like categories.

https://tortoise-orm.readthedocs.io/en/latest/examples/basic.html?highlight=recursive#recursive-relations is not exactly what I'm looking for, as it doesn't seem to be usable with QuerySet.

Describe the solution you'd like
Some simple way of using CTEs. It could be by directly specifying an option within the Meta of the model.

Describe alternatives you've considered
Direct query, which goes against the idea of using an ORM

Additional context

EDIT

Sqlalchemy CTE:
https://docs.sqlalchemy.org/en/14/core/selectable.html#sqlalchemy.sql.expression.cte

and some examples:

https://gist.github.com/cairabbit/d64fccf7cf2abe180e69c843706f46c7
https://stackoverflow.com/questions/34847869/sqlalchemy-using-a-cte-from-a-subquery-w-from-clause-specified-as-literal-te

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue identifies QuerySet as the desired integration point and links SQLAlchemy's CTE API and examples, but names no repository files or tests. Start by reviewing QuerySet usage and the linked CTE references; done criteria would need a defined CTE API and coverage for hierarchical queries.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sql
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.