LuisLuii / FastAPIQuickCRUD

Generate CRUD methods in FastApi from an SQLAlchemy schema
https://pypi.org/project/fastapi-quickcrud/
MIT License
252 stars 32 forks source link

Use tree-like API for foreign keys. #9

Closed aebrahim closed 2 years ago

aebrahim commented 2 years ago

This is such a cool package, but I ended up not using it because I wanted my API to look like this. I thought I would just leave it as a suggestion.

Suppose I have this in sqlalchemy:

import sqlalchemy as sa

class Account(Base):
    __tablename__ = "account"
    id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)

class BlogPost(Base):
    __tablename__ = "blog_post"
    id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
    account_id = sa.Column(sa.Integer, sa.ForeignKey("account.id"), nullable=False)

class BlogComment(Base)
    __tablename__ = "blog_comment"
    id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
    blog_id = sa.Column(sa.Integer, sa.ForeignKey("blog_post.id"), nullable=False)

I might want routes like this:

GET /account/<account_id>/post/
{ list of blog posts by the author }
POST /account/<account_id>/post/
# creates a new blog post for the author
GET /post/<post_id>/comment
{ list of comments on the blog post }
GET /account<account_id>/post/<post_id>/comment
{ list of comments on the blog post - not sure how this is compared to the one above }

Anyways, just a thought!

LuisLuii commented 2 years ago

Hi aebrahim, Thanks so much for your contribution and suggestion, the suggestion is great. I will plan to enhance the package with your suggestion. And will update here

LuisLuii commented 2 years ago

Let discuss this feature in #11, Thanks