nsidnev/fastapi-realworld-example-app

queries.pyi / aiosql

stealthrabbi opened this issue · 1 comments

I'm attempting to create a new table entity, and writing a repository to query the database.

  1. I was trying to figure out how to update env.py to support auto-generation with alembic, but wasn't sure where the "base metadata" lives, or how to specify it exactly. Do I need a file that imports all the models in app/models/domain?
  2. queries.py references queries.pyi. The readme doesn't specify how to use aiosql, so I'm not sure what to do with it exactly. Is it required for doing queries?
  1. This project doesn't use sqlalchemy for anything other than migrations, so you simply can't automatically generate migrations with alembic. If you want this to be possible, then you'll have to change the way this project works with the database or use wrappers around pydantic and sqlalchemy or something similar.
  2. queries.py is a simple module that defines a holder for raw SQL queries from app/db/queries/sql. The files from this folder are parsed by aiosql and as a result create dynamic functions for the corresponding queries from the files. Unfortunately, aiosql cannot generate typing for these modules (simply because it all works at runtime), so there is a corresponding to query.py module called query.pyi that simply defines the typings for functions generated through aiosql. If you want to know more about aiosql, check its documentation for a better explanation of this.

FIY. A little more information on your questions can be found in this issue.