Declare indexes while keeping Pydantic and SQLModel logic separated #1001
Unanswered
choucavalier
asked this question in
Questions
Replies: 1 comment
-
Just curious - why would you like to separate your Pydantic logic and SQLModel logic? Non-table SQLModel classes (i.e., without Adapted to your example, this would look like the following: from typing import Optional
from sqlmodel import Field, SQLModel
class MyType(SQLModel):
some_attr: Optional[str] = Field(index=True)
some_other_attr: int = None
class MyTypeSQL(MyType, table=True):
id: Optional[int] = Field(default=None, primary_key=True) If using SQLite (for example), this code would create the following table: CREATE TABLE mytypesql (
some_attr VARCHAR,
some_other_attr INTEGER NOT NULL,
id INTEGER NOT NULL,
PRIMARY KEY (id)
);
CREATE INDEX ix_mytypesql_some_attr ON mytypesql (some_attr); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Example Code
Description
How can I declare
some_other_attr
as a field that should be used for indexing, while still keeping the pydantic and SQLModel logic separated?Beta Was this translation helpful? Give feedback.
All reactions