def _getattr(attribute): types = { 'varchar': VARCHAR(length=255), 'int': BIGINT, 'date': DATETIME, 'dec': DECIMAL, 'text': LONGTEXT, 'raw': VARCHAR(length=255) } out_attrib = Column(attribute.name, types[attribute.data_type]) out_attrib.label(attribute.name+'_') if attribute.required: out_attrib.nullable = False else: out_attrib.nullable = True if attribute.ref_object: out_attrib.referrer = attribute.ref_object out_attrib.referrer_name = attribute.ref_object_label else: out_attrib.referrer = None out_attrib.referrer_name = None if attribute.values_to_select: out_attrib.values_to_select = dict([ el.split(':') for el in attribute.values_to_select.split('|') ]) else: out_attrib.values_to_select = None return out_attrib
def make_sqla_column_compatible(self, sqla_col: Column, label: Optional[str] = None) -> Column: """Takes a sqlalchemy column object and adds label info if supported by engine. :param sqla_col: sqlalchemy column instance :param label: alias/label that column is expected to have :return: either a sql alchemy column or label instance if supported by engine """ label_expected = label or sqla_col.name db_engine_spec = self.database.db_engine_spec if db_engine_spec.allows_column_aliases: label = db_engine_spec.make_label_compatible(label_expected) sqla_col = sqla_col.label(label) sqla_col._df_label_expected = label_expected return sqla_col