Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/core/models.py
Show All 18 Lines | |||||
class ModelBase(SQLBase, metaclass=ABCSQLMeta): | class ModelBase(SQLBase, metaclass=ABCSQLMeta): | ||||
"""a common repository""" | """a common repository""" | ||||
__abstract__ = True | __abstract__ = True | ||||
__tablename__ = AbstractAttribute | __tablename__ = AbstractAttribute | ||||
uid = AbstractAttribute('Column(<uid_type>, primary_key=True)') | uid = AbstractAttribute('Column(<uid_type>, primary_key=True)') | ||||
# The value used for sorting, segmenting, or api query paging, | |||||
# because uids aren't always sequential. | |||||
indexable = AbstractAttribute('Column(<indexable_type>, index=True)') | |||||
name = Column(String, index=True) | name = Column(String, index=True) | ||||
full_name = Column(String, index=True) | full_name = Column(String, index=True) | ||||
html_url = Column(String) | html_url = Column(String) | ||||
origin_url = Column(String) | origin_url = Column(String) | ||||
origin_type = Column(String) | origin_type = Column(String) | ||||
description = Column(String) | description = Column(String) | ||||
last_seen = Column(DateTime, nullable=False) | last_seen = Column(DateTime, nullable=False) | ||||
task_id = Column(Integer) | task_id = Column(Integer) | ||||
origin_id = Column(Integer) | origin_id = Column(Integer) | ||||
def __init__(self, uid=None, indexable=None, name=None, full_name=None, | def __init__(self, uid=None, name=None, full_name=None, | ||||
html_url=None, origin_url=None, origin_type=None, | html_url=None, origin_url=None, origin_type=None, | ||||
description=None, task_id=None, origin_id=None): | description=None, task_id=None, origin_id=None): | ||||
self.uid = uid | self.uid = uid | ||||
self.last_seen = datetime.now() | self.last_seen = datetime.now() | ||||
if indexable is not None: | |||||
self.indexable = indexable | |||||
if name is not None: | if name is not None: | ||||
self.name = name | self.name = name | ||||
if full_name is not None: | if full_name is not None: | ||||
self.full_name = full_name | self.full_name = full_name | ||||
if html_url is not None: | if html_url is not None: | ||||
self.html_url = html_url | self.html_url = html_url | ||||
if origin_url is not None: | if origin_url is not None: | ||||
self.origin_url = origin_url | self.origin_url = origin_url | ||||
if origin_type is not None: | if origin_type is not None: | ||||
self.origin_type = origin_type | self.origin_type = origin_type | ||||
if description is not None: | if description is not None: | ||||
self.description = description | self.description = description | ||||
if task_id is not None: | if task_id is not None: | ||||
self.task_id = task_id | self.task_id = task_id | ||||
if origin_id is not None: | if origin_id is not None: | ||||
self.origin_id = origin_id | self.origin_id = origin_id | ||||
class IndexingModelBase(ModelBase, metaclass=ABCSQLMeta): | |||||
__abstract__ = True | |||||
__tablename__ = AbstractAttribute | |||||
# The value used for sorting, segmenting, or api query paging, | |||||
# because uids aren't always sequential. | |||||
indexable = AbstractAttribute('Column(<indexable_type>, index=True)') | |||||
def __init__(self, uid=None, name=None, full_name=None, | |||||
html_url=None, origin_url=None, origin_type=None, | |||||
description=None, task_id=None, origin_id=None, | |||||
indexable=None): | |||||
super().__init__( | |||||
uid=uid, name=name, full_name=full_name, html_url=html_url, | |||||
origin_url=origin_url, origin_type=origin_type, | |||||
description=description, task_id=task_id, origin_id=origin_id) | |||||
if indexable is not None: | |||||
self.indexable = indexable |