def get_schmea_str_and_examples()

in route.py [0:0]


def get_schmea_str_and_examples(schema_dict): 
    schmea_str = ""
    tables = list(schema_dict['tables'].keys())
    examples = {}
    for table in tables:
        if ' ' in table:
            table_str = f'CREATE TABLE "{table}" ('
        else:
            table_str = f"CREATE TABLE {table} ("
        table_dict = schema_dict['tables'][table]
 
        pk_str = '' 
        example = []
        for cls in table_dict.keys():
            try:
                cls_ = f'"{cls}"' if ' ' in cls else cls
                table_str += f"{cls_} {table_dict[cls][0]}, "
                if table_dict[cls][1]: 
                    pk_str += cls_+', '
                example.append(table_dict[cls][2])
            except Exception as e:
                print(e)
        example_str = []
        
        try:
            for i, v in enumerate(example[0]):
                example_str.append(tuple([e[i] for e in example]))
        except Exception as e:
            print(e)

        examples[table] = example_str 
       
        if pk_str != '':
            table_str += f"PRIMARY KEY({pk_str[:-2]}), "
 
        fk_str = ''
        for fk in schema_dict['foreign_keys']:
            if fk[0] == table and fk[2] in tables:
                if fk[3] in schema_dict['tables'][fk[2]].keys():
                    fk = [f'"{f}"' if ' ' in f else f for f in fk ]
                    fk_str += f'FOREIGN KEY ({fk[1]}) REFERENCES {fk[2]}({fk[3]}), '
        if fk_str != '':
            table_str += fk_str 

        schmea_str += table_str[:-2] +'); ' 

    schmea_str = schmea_str[:-1]  

    e_s = ''
    for key in examples.keys():
        e_s += f"{key}: " + str(examples[key])+'\n'
    
    return schmea_str, e_s[:-1]