-
First Check
Commit to Help
Example Codefrom typing import Optional
from sqlmodel import SQLModel
class Model(SQLModel, table=true):
id: Optional[int] = Field(default=None, primary_key=True)
value: str DescriptionI need to get the query text of creating this table - how do I do that without creating a new sqlalchemy object to replace this? Operating SystemLinux Operating System DetailsNo response SQLModel Version0.0.14 Python Version3.12.2 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
riziles
Feb 19, 2024
Replies: 1 comment
-
@jochman , Try this: from sqlmodel import Field, SQLModel, create_engine
from sqlalchemy.schema import CreateTable
class Hero(SQLModel, table=True):
id: int = Field(default=None, primary_key=True)
name: str
secret_name: str
sqlite_file_name = "database.db"
sqlite_url = f"sqlite:///{sqlite_file_name}"
engine = create_engine(sqlite_url, echo=True)
print(CreateTable(Hero.__table__).compile(engine)) found it here: https://stackoverflow.com/questions/2128717/sqlalchemy-printing-raw-sql-from-create |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YuriiMotov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jochman , Try this:
found it here: https://stackoverflow.com/questions/2128717/sqlalchemy-printing-raw-sql-from-create