sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

Intellisense autocomplete does not show for `in_` in VSCode

Open taranlu-houzz opened this issue 3 years ago • 3 comments

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 Optional

from sqlmodel import Field, Session, SQLModel, create_engine, select


class Hero(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str
    secret_name: str
    age: Optional[int] = None


hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
hero_2 = Hero(name="Beep", secret_name="B")

engine = create_engine("sqlite:///database.db", echo=True)


SQLModel.metadata.create_all(engine)


with Session(engine) as session:
    session.add(hero_1)
    session.add(hero_2)

    session.commit()

    session.refresh(hero_1)
    session.refresh(hero_2)

    print(f"{hero_1=}")
    print(f"{hero_2=}")

    hero_names = [
        "Beep",
        "Boop",
        "Deadpond",
        "Zorf",
    ]
    db_statement = select(Hero).where(Hero.name.in_(hero_names))
    db_data = session.exec(db_statement).all()

    print(f"{db_data=}")

Description

  • When trying to figure out how to generate a proper IN clause, I noticed that VSCode intellisense does not show an autocomplete option for the in_() function on a model field (although it does still appear to work as expected).
  • In the example code I posted, when I type: Hero.name.i, the in_ function does not show up.
  • This really confused me, because I am new to slqmodel and slqalchemy, and I was trying to figure out how to generate an IN clause.
  • The sqlmodel documentation also does not mention how to do this currently. I think it might be a good idea to add, since it is such a common use case.

Operating System

macOS

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

3.10.2

Additional Context

I do have a fair number of VSCode extensions, but I don't think that is the issue, since I do get autocomplete for everything else from sqlmodel.

taranlu-houzz avatar Apr 04 '22 17:04 taranlu-houzz

I guess this is because in_ is really more on the sqlalchemy side of things, but I wonder if it could be handled like or_ to help improve discovery?

taranlu-houzz avatar Apr 04 '22 17:04 taranlu-houzz

sqlmodel provides a function col() to change SQLModel attrs to Column, so you just need to change your code like this:

from sqlmodel import col

db_statement = select(Hero).where(col(Hero.name).in_(hero_names))

Whitroom avatar May 21 '22 01:05 Whitroom

Still have error: E1101: Instance of 'FieldInfo' has no 'in_' member (no-member)

tulinev avatar Jun 23 '23 16:06 tulinev