add cli
This commit is contained in:
parent
85554e2169
commit
a21dbb08d4
8 changed files with 285 additions and 43 deletions
26
sqlmodel_base/hero/models.py
Normal file
26
sqlmodel_base/hero/models.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, validator
|
||||
from rich.console import Console
|
||||
from sqlalchemy import func
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
from sqlmodel_base.base import Base
|
||||
|
||||
console = Console()
|
||||
|
||||
|
||||
class Hero(Base, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
@validator("age")
|
||||
def validate_age(cls, v):
|
||||
if v is None:
|
||||
return v
|
||||
if v > 0:
|
||||
return v
|
||||
return abs(v)
|
||||
Loading…
Add table
Add a link
Reference in a new issue