def find_by_name(self, name): try: record = self.session\ .query(orm.Datum)\ .filter_by(name=name)\ .filter(orm.Datum.deleted_at > datetime.now())\ .first() if record is None: return None return self._datasource_record_to_model(record) except Exception: return domains.NotFoundError(param=name)
def _find_bucket_by_id(self, bucket_id): try: record = self.session \ .query(orm.Bucket) \ .filter_by(id=bucket_id) \ .filter(orm.Bucket.deleted_at > datetime.now()) \ .first() if record is None: return None return DataSourceRepository._bucket_record_to_model(record) except Exception: return domains.NotFoundError(param='Bucket ID', raw=bucket_id)
def _find_object_by_id(self, object_id): try: record = self.session \ .query(orm.Object) \ .filter_by(id=object_id) \ .filter(orm.Bucket.deleted_at > datetime.now()) \ .first() if record is None: return None return self._object_record_to_model(record) except Exception: return domains.NotFoundError(param='Object ID', raw=object_id)
def find_by_user_id(self, user_id): try: records = self.session \ .query(orm.Datum) \ .filter_by(user_id=user_id) \ .filter(orm.Datum.deleted_at > datetime.now()) if not records: return [] record_list = [self._datasource_record_to_model(record) for record in records] return record_list except Exception: return domains.NotFoundError(param=user_id)