using sqlalchemy class models to generate queries #433
Answered
by
aminalaee
nbraun-wolf
asked this question in
Q&A
-
Hi, I am wondering how sqlalchemy model classes could be used to get a query to execute. In the example, the Table class is used. notes = sqlalchemy.Table(...)
query = notes.insert()
values = {"text": "example1", "completed": True}
await database.execute(query=query, values=values) But I am looking to do something like this from my model classes. class User(Model):
... Is there a way of doing that? |
Beta Was this translation helpful? Give feedback.
Answered by
aminalaee
Dec 2, 2021
Replies: 1 comment 1 reply
-
Hey, I think with SQLAlchemy 1.4 this should work: from sqlalchemy import select
query = select(User).where(User.name == 'spongebob')
await database.execute(query) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nbraun-wolf
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I think with SQLAlchemy 1.4 this should work: