sqlmodel
sqlmodel copied to clipboard
.exec() with text() does not provide auto-suggestion methods
First Check
- [X] I added a very descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the SQLModel documentation, with the integrated search.
- [X] I already searched in Google "How to X in SQLModel" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to SQLModel but to Pydantic.
- [X] I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
- [X] I commit to help with one of those options 👆
Example Code
from typing import Any, List
from fastapi import APIRouter, Depends
from sqlmodel import Session, select, text, SQLModel
from pydantic import BaseModel
from app.api.deps import get_session_legacy
router = APIRouter(prefix="/")
class Test(BaseModel):
hello: str
@router.get("/data", response_model=List[Test])
async def get_data(
db: Session = Depends(get_session_legacy)
):
sql = text(
"""
SELECT 'hi' AS "hello"
"""
)
result = db.exec(sql).all()
for res in result:
logger.info(f"response: {res}")
return result
Description
When using db.exec(select(Hero)) you can use auto-suggestion in vscode to see the methods that belong to exec().
However when using db.exec(text("SELECT * FROM hero")) then there are no suggestions following the exec().
Wanted Solution
I want to see the suggestions: db.exec(text()).[one(), all(), scalars(), etc...]
Wanted Code
from typing import Any, List
from fastapi import APIRouter, Depends
from sqlmodel import Session, select, text, SQLModel
from pydantic import BaseModel
from app.api.deps import get_session_legacy
router = APIRouter(prefix="/")
class Test(BaseModel):
hello: str
@router.get("/data", response_model=List[Test])
async def get_data(
db: Session = Depends(get_session_legacy)
):
sql = text(
"""
SELECT 'hi' AS "hello"
"""
)
result = db.exec(sql).[all(), one(), scallars()... etc]
for res in result:
logger.info(f"response: {res}")
return result
Alternatives
No response
Operating System
Linux
Operating System Details
wsl2 on windows, vscode
SQLModel Version
0.0.6
Python Version
3.10
Additional Context
No response
It's issue incorrect, i think, because of https://github.com/tiangolo/sqlmodel/blob/main/sqlmodel/init.py#L77
So, you must send it to sqlalchemy or sqlalchemy_stubs.