def create(request: schemas.User, db: session): new_user = models.User(name=request.name, email=request.email, password=Hash.bcrypt(request.password)) db.add(new_user) db.commit() db.refresh(new_user) return new_user
def pillboxes_create(how_many: int, db: session) -> list[dict]: for _ in range(how_many): pillbox_model = models.Pillbox() db.add(pillbox_model) db.commit() db.refresh(pillbox_model) yield pillbox_model
def create_task(db: session, task: schemas.TaskCreate): db_task = models.Task(**task.dict(), added=datetime.now()) db.add(db_task) db.commit() db.refresh(db_task) db_task.notes_path = f"notes/{db_task.id}_{db_task.name.replace(' ', '_')}.md" db.add(db_task) db.commit() db.refresh(db_task) return db_task
async def create_stock(stock_request: StockRequest, background_tasks: BackgroundTasks , db: session = Depends(get_db)): stock = Stock() stock.symbol = stock_request.symbol db.add(stock) db.commit() background_tasks.add_task(fetch_stock_data, stock.id) return { "code": "success", "message": "stock was added to the database" }
def update_task(db: session, task_id: int, task: schemas.TaskCreate): updated = db.query(models.Task).filter(models.Task.id == task_id).update( task.dict()) if (updated == 0): db_task = models.Task(**task.dict(), added=datetime.now()) db.add(db_task) db.commit() db.refresh(db_task) db_task.notes_path = f"notes/{db_task.id}_{db_task.name.replace(' ', '_')}.md" db.add(db_task) db.commit() return db_task db.commit() return get_task(db, task_id)
def doctors_create(doctor: schemas.DoctorCreateIn, db: session) -> dict: password = pg.generate() doctor_model = models.Doctor( first_name=doctor.first_name, last_name=doctor.last_name, email=doctor.email, phone_number=doctor.phone_number, hashed_password=hashing.get_password_hash(password), ) db.add(doctor_model) db.commit() db.refresh(doctor_model) doctor_model.__dict__['password'] = password return doctor_model
def patients_create(patient: schemas.PatientCreateIn, db: session) -> dict: password = pg.generate() patient_model = models.Patient( first_name=patient.first_name, last_name=patient.last_name, email=patient.email, phone_number=patient.phone_number, hashed_password=hashing.get_password_hash(password), doctor_id=patient.doctor_id) db.add(patient_model) db.commit() db.refresh(patient_model) patient_model.__dict__['password'] = password return patient_model
def _extractCountMetric(self, dbsession: session, contractAddress: str, rootNode: solcast.nodes.NodeBase) -> bool: try: cmResult: CountMetric = CountMetricCalculator( contract_addr=contractAddress, contract_path=os.path.join( self.contract_root_path, contractAddress + "." + self.contract_src_path_skeleton.split(".")[1]), rootNode=rootNode).getCountMetrics() except Exception as e: logger.error( "|_____Extracting CountMetric for Contract:{contract} ERROR: {emsg}" .format(contract=contractAddress, emsg=e)) return False else: # dbsession.add(cmResult) dbsession.commit() dbsession.flush() return True
def initialize_db(my_session: session, load_data: bool = True): """ Args: load_data (): Load the default date (false for tests) Returns: """ db.Base.metadata.drop_all(db.engine, checkfirst=True) db.Base.metadata.create_all(db.engine, checkfirst=True) if load_data: load_all(my_session) # Setup the default ingredient_unit unit_group = data.IngredientUnit(name="Internal group unit", cldr=False, factor=None, type_=data.IngredientUnit.UnitType.GROUP) my_session.add(unit_group) my_session.commit() data.IngredientUnit.update_unit_dict(my_session)
def create(request: schemas.Blog, db: session): new_blog = models.Blog(title=request.title, body=request.body, user_id=1) db.add(new_blog) db.commit() db.refresh(new_blog) return new_blog
def load_values(db_session: session, module=None): """ Plain and boring. Just a version number """ meta = Meta(1) db_session.add(meta) db_session.commit()