Exemplo n.º 1
0
 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
Exemplo n.º 2
0
    def string_to_metadata(string):
        temp_metadata = MetaData()
        tb_datas = string.split(";")
        tb_datas.remove("")

        for data in tb_datas:
            tb_name = data.split(",")[0].lower()
            columns_data = data.split(",")[1:]

            table = Table(tb_name, temp_metadata)
            for column_data in columns_data:
                args = re.findall(r"[A-Z][^A-Z]+", column_data)
                c = Column(args[0].lower(),
                           ColumnTool.get_type(args[1].upper()))

                if "Nullable" in args:
                    c.nullable = True
                else:
                    c.nullable = False
                if "Unique" in args:
                    c.unique = True
                else:
                    c.unique = False

                table.append_column(c)

        return temp_metadata
Exemplo n.º 3
0
    def strings_to_metadata(table_str):
        temp_metadata = MetaData()
        
        for table_name, data in table_str.items():
            table = Table(table_name, temp_metadata)

            columns_datas = data.split(",")
            for column_data in columns_datas:
                args = re.findall(r"[A-Z][^A-Z]+", column_data)
                c = Column(args[0].lower(),
                           ColumnTool.get_type(args[1].upper()))
                
                if "Nullable" in args:
                    c.nullable = True
                else:
                    c.nullable = False
                if "Unique" in args:
                    c.unique = True
                else:
                    c.unique = False
                
                table.append_column(c)
        
        return temp_metadata