models: load initial data from database
This commit is contained in:
parent
61f259ecfc
commit
0d80c686c7
1 changed files with 12 additions and 12 deletions
|
|
@ -4,14 +4,14 @@ import uuid
|
||||||
from sqlmodel import (
|
from sqlmodel import (
|
||||||
Field,
|
Field,
|
||||||
SQLModel,
|
SQLModel,
|
||||||
|
Session,
|
||||||
|
select,
|
||||||
|
Sequence,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
TeilchenDatum = tuple[int, str, str, str, str]
|
|
||||||
|
|
||||||
|
|
||||||
class TeilchenCreate(SQLModel):
|
class TeilchenCreate(SQLModel):
|
||||||
description: str | None
|
description: str | None
|
||||||
name: str = Field(index=True)
|
name: str = Field(index=True)
|
||||||
|
|
@ -57,12 +57,12 @@ async def make_teilchen_input(text: str) -> TeilchenCreate | None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def load_initial_data() -> list[TeilchenDatum]:
|
async def load_initial_data() -> Sequence[Teilchen]:
|
||||||
return [
|
from .database import engine
|
||||||
(0, "Name0", "Description0", "9000", "#tag0 #tag00 #tag000"),
|
|
||||||
(1, "Name1", "Description1", "9001", "#tag1 #tag11 #tag111"),
|
with Session(engine) as session:
|
||||||
(2, "Name2", "Description2", "9002", "#tag2 #tag22 #tag222"),
|
statement = select(
|
||||||
(3, "Name3", "Description3", "9003", "#tag3 #tag33 #tag333"),
|
Teilchen.id, Teilchen.name, Teilchen.description, Teilchen.number, Teilchen.tags
|
||||||
(4, "Name4", "Description4", "9004", "#tag4 #tag44 #tag444"),
|
)
|
||||||
(5, "Name5", "Description5", "9005", "#tag5 #tag55 #tag555"),
|
all_teilchen = session.exec(statement).all()
|
||||||
]
|
return all_teilchen
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue