def save(cls, model): """ Сохраняет модель в базу. @param model: Model """ data = cls.model_to_dict(model) model._id = DbClient.get_collection(cls._collection).save(data, manipulate=True)
def find(cls, filter): """ Ищет записи. @param filter: dict @return: list """ data = DbClient.get_collection(cls._collection).find(filter) return map(cls.dict_to_model, data)
def find_one(cls, filter): """ Ищет одну запись. @param filter: dict @return: Model """ data = DbClient.get_collection(cls._collection).find_one(filter) if data is None: return None return cls.dict_to_model(data)