import time from typing import List from app import models, schemas from sqlalchemy.orm import Session def create_constant(db: Session,item: schemas.ConstantCreate): db_item = models.Constant(**item.dict()) db.add(db_item) db.commit() db.refresh(db_item) return db_item def get_constant_list(db: Session, type: str): res: List[models.Constant] = db.query(models.Constant).filter(models.Constant.type == type).all() return [r.value for r in res] def find_and_update(db: Session, type: str, value: str): res: List[models.Constant] = db.query(models.Constant)\ .filter(models.Constant.type == type)\ .filter(models.Constant.value == value).all() if len(res) == 0: db_item = models.Constant(**{ 'type': type, 'value': value }) db.add(db_item) db.commit() db.refresh(db_item)