init
This commit is contained in:
23
web/commons/models/mixin/es_source.py
Normal file
23
web/commons/models/mixin/es_source.py
Normal file
@@ -0,0 +1,23 @@
|
||||
class EsSourceMixin:
|
||||
__table__ = None
|
||||
__tablename__ = ''
|
||||
|
||||
def to_es(self):
|
||||
primary_key_name = [str(i.name) for i in self.__table__.columns if i.primary_key][0]
|
||||
es_data = {
|
||||
'meta': {
|
||||
'id': '{}/{}'.format(self.__tablename__, getattr(self, primary_key_name)),
|
||||
},
|
||||
'table': self.__tablename__,
|
||||
'create_time': self.now() * 1000,
|
||||
}
|
||||
return es_data
|
||||
|
||||
@classmethod
|
||||
def get_es_data(cls):
|
||||
for item in cls.query.yield_per(500):
|
||||
yield item.to_es()
|
||||
|
||||
@classmethod
|
||||
def es_join_str(cls, str_list):
|
||||
return ' '.join(str(i or '') for i in str_list if i)
|
Reference in New Issue
Block a user