-
-
Notifications
You must be signed in to change notification settings - Fork 783
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
First Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn't find it.
- I searched the SQLModel documentation, with the integrated search.
- I already searched in Google "How to X in SQLModel" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to SQLModel but to Pydantic.
- I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
- I commit to help with one of those options π
Example Code
from sqlmodel import Field, Session, SQLModel, create_engine, select
class Hero(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str
sqlite_file_name = "database.db"
sqlite_url = f"sqlite:///{sqlite_file_name}"
engine = create_engine(sqlite_url, echo=True)
def create_db_and_tables():
SQLModel.metadata.create_all(engine)
def create_heroes():
hero_1 = Hero(name="Deadpond")
hero_2 = Hero(name="Spider-Boy")
hero_3 = Hero(name="Rusty-Man")
with Session(engine) as session: #
session.add(hero_1) #
session.add(hero_2)
session.add(hero_3)
session.commit()
row_counts = session.exec(select(Hero)).count() # HERE! How can I get the row counts? In my code I had where as well.
print(f"row_counts: {row_counts}")
def main():
create_db_and_tables()
create_heroes()
if __name__ == "__main__":
main()Description
- How can I get the count or row counts of the query?
Operating System
Linux
Operating System Details
Ubuntu 21.10
SQLModel Version
0.0.6
Python Version
3.10.2
Additional Context
None
UPocekfanqie03 and JacobFV
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested