feat: added script filling_example_timers
This commit is contained in:
@@ -12,7 +12,7 @@ class BaseNumBehavior:
|
||||
|
||||
|
||||
class TimeTomatoInput(TextInput, BaseNumBehavior):
|
||||
"""Класс для поля ввода колличества помидорово"""
|
||||
"""Класс для поля ввода колличества помидоров"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
52
kawai_focus/database/seed_examples.py
Normal file
52
kawai_focus/database/seed_examples.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from sqlalchemy import insert
|
||||
|
||||
from kawai_focus.schemas import TimerModel
|
||||
from kawai_focus.database.session import db
|
||||
from kawai_focus.database.models import Timer
|
||||
|
||||
|
||||
examples_data = [
|
||||
TimerModel(
|
||||
title='Timer mini example',
|
||||
pomodoro_time=10,
|
||||
break_time=3,
|
||||
break_long_time=15,
|
||||
count_pomodoro=2
|
||||
),
|
||||
TimerModel(
|
||||
title='Timer max example',
|
||||
pomodoro_time=90,
|
||||
break_time=10,
|
||||
break_long_time=40,
|
||||
count_pomodoro=8
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def new_timer(data: TimerModel) -> TimerModel:
|
||||
"""Функция для создания нового таймера"""
|
||||
|
||||
with db.get_session() as session:
|
||||
query = insert(Timer).values(**data.model_dump()).returning(Timer)
|
||||
result = session.execute(query)
|
||||
|
||||
new_timer = result.scalar_one()
|
||||
session.commit()
|
||||
|
||||
return TimerModel.model_validate(obj=new_timer, from_attributes=True)
|
||||
|
||||
|
||||
def filling_example_temers(data: list[TimerModel]) -> None:
|
||||
"""Заполняет базу данных образцами таймеров"""
|
||||
|
||||
for timer_model in data:
|
||||
with db.get_session() as session:
|
||||
query = insert(Timer).values(**timer_model.model_dump()).returning(Timer)
|
||||
session.execute(query)
|
||||
session.commit()
|
||||
|
||||
|
||||
def main_filling_data():
|
||||
"""Главная функция заполнения данных бд"""
|
||||
|
||||
filling_example_temers(data=examples_data)
|
||||
@@ -28,3 +28,4 @@ build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
kawai-focus = "kawai_focus.main:main"
|
||||
filling_example_timers = "kawai_focus.database.seed_examples:main_filling_data"
|
||||
Reference in New Issue
Block a user