from models import Product, Session import uuid class ProductManager: def __init__(self, parent=None): super().__init__() def create(self, info): data = { "id": str(uuid.uuid4()), "info": info } ok, res = Session.addByClass(Product, data) if ok: return str(res["id"]) return "" def update(self, id, info): data = {"info": info} ok,res = Session.updateById(Product, id, data) return ok def delete(self, id): if isinstance(id, str): ok,res = Session.deleteById(Product, id) return ok else: ok,res = Session.deleteByIds(Product, id) return ok def getInfos(self, ids): ok,res = Session.queryByIds(Product, ids) if ok: return res else: return [] def getInfo(self, id = "all"): if id == "all": ok,res = Session.queryByAll(Product) if ok: return res else: return [] else: ok,res = Session.queryById(Product, id) if ok: return res else: return None productManager = ProductManager()