from sqlalchemy.orm import Session from typing import Optional from mooc.models.account import AccountWechats from mooc.schemas.account import AccountWechatsCreate, AccountWechatsUpdate class CRUDAccountWechats: def create(self, db: Session, obj_in: AccountWechatsCreate) -> AccountWechats: db_obj = AccountWechats(**obj_in.dict()) db.add(db_obj) db.commit() db.refresh(db_obj) return db_obj def get(self, db: Session, acid: int) -> Optional[AccountWechats]: return db.query(AccountWechats).filter(AccountWechats.acid == acid).first() def update( self, db: Session, *, db_obj: AccountWechats, obj_in: AccountWechatsUpdate ) -> AccountWechats: for field, value in obj_in.dict(exclude_unset=True).items(): setattr(db_obj, field, value) db.add(db_obj) db.commit() db.refresh(db_obj) return db_obj def delete(self, db: Session, acid: int) -> None: obj = db.query(AccountWechats).filter(AccountWechats.acid == acid).first() if obj: db.delete(obj) db.commit() account_wechats = CRUDAccountWechats()