run module
- run.HTMLToDict(text)
This is an analogue function to csvToDict, but instead of getting a file as an input, it’s just a string (HTML text). The structure of the string should be the same as if it were a CSV
See csvToDict to have a full description of how this works.
- Parameters:
text –
Each row of the text represents an attribute, the table where it belongs to, and eventually the parent (in case of a foreign key). The expected (correct) way to indicate this information is:
table name,attribute,SQL-type definition- Returns:
3 dictionaries as a 3-tuple. These dictionaries are
tables: tables and attributes information
{
TABLE NAME 1: [(ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT), (…)]}relationships_uml: foreign key relationships, for UML output
{
FOREIGN KEY: [(PARENT TABLE,CHILD TABLE)]relationships_sql: foreign key relationships, for SQL output
{
CHILD TABLE: [(FOREIGN KEY,PARENT TABLE)]- Return type:
tuple
- run.csvToDict(file) tuple
Starting point of the program. Takes a CSV file where each line contains:
table name,attribute,SQL-type definitionand transforms this into a dictionary with the structure:{TABLE NAME 1: [(ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT), (…)]}If foreign keys are present, the CSV line should state the parent table to which the foreign key refers, between brackets:
i.e:
SQL-type definition= ‘integer foreign key (PARENT TABLE)’If so, two additional dictionaries are populated by this function to represent the relationships in a useful way for the rest of the code.
- Parameters:
file (head-less CSV file) –
Each row of the file represents an attribute, the table where it belongs to, and eventually the parent (in case of a foreign key). The expected (correct) way to indicate this information is:
table name,attribute,SQL-type definition- Returns:
3 dictionaries as a 3-tuple. These dictionaries are
tables: tables and attributes information
{
TABLE NAME 1: [(ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT), (…)]}relationships_uml: foreign key relationships, for UML output
{
FOREIGN KEY: [(PARENT TABLE,CHILD TABLE)]relationships_sql: foreign key relationships, for SQL output
{
CHILD TABLE: [(FOREIGN KEY,PARENT TABLE)]- Return type:
tuple
- run.dictToSql(tables: dict, relations: dict, fname: str) str
Reads the dictionary of the table’s information and generates an SQL script to create the tables with the references with minimal code.
- Parameters:
tables (Dictionary) –
dictionary with the tables’ data
{
TABLE NAME 1: [(ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT), (…)]}relations (Dictionary) –
if foreign keys are defined, this is the dictionary that holds the relationships information:
{
CHILD TABLE: [(ATTRIBUTE X,FATHER TABLE 1)]}fname (String) – name of the file with the CSV information (also used as the name for the output file)
- Returns:
SQL script to generate the database with sqlite3
- Return type:
String
- run.dictToUml(tables: dict, relations: dict, fname: str) str
Reads the dictionary of the table’s information and generates a plantUML-ready file for it’s visualization.
- Parameters:
tables (Dictionary) –
dictionary with the tables’ data
{
TABLE NAME 1: [(ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT), (…)]}relations (Dictionary) –
if foreign keys are defined, this is the dictionary that holds the relationships information:
{
ATTRIBUTE X: [(FATHER TABLE 1,CHILD TABLE 1)]}fname (String) – name of the file with the CSV information (also used as the name for the output file)
- Returns:
UML script to sketch the database
- Return type:
String
- run.identifyType(data: str) tuple
Core function of the script. Reads the 3rd column of the CSV line (the so called
SQL-type definition) and breaks it down in 3:att_class,col_typeand -if exists-parent(only in case of foreign keys).- Parameters:
data (String) – SQL-type attribute definition string.
- Returns:
3 strings in a tuple.
att_class: the tag for the type of attribute:’col’ stands for “column”, a standard non-key attribute
’pk’ stands for “primary key”
’fk (PARENT)’ stands for “foreign key”, where PARENT is the table to which this key makes reference to.
col_type: SQLite code to declare an attribute (uppercase)parent: when the line corresponds to a foreign key, this output corresponds to the parent table’s name.
- Return type:
tuple
- run.polishSQL(raw_list: list) list
Takes a list consisting of each of the SQL script lines and transforms it into a list of tuples with the form (name, pk/fk/col, type), where type is the SQL script code to define the column’s data type.
- Parameters:
raw_list (list) – list of the database’s attributes read from the SQL script.
- Returns:
list of tuples, where each tuple is composed by:
(
ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT)- Return type:
list
- run.polishUML(raw_list: list) list
Takes a list consisting of each of the UML text lines and transforms it into a list of tuples with the form (name, pk/fk/col, type), where type is the SQL script code to define the column’s data type.
- Parameters:
raw_list (list) – list of the database’s attributes read from the UML script.
- Returns:
list of tuples, where each tuple is composed by:
(
ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT)- Return type:
list
- run.runHTML(text)
Execute the program through an HTML call from the UI
- Parameters:
text (String) –
Each row of the text represents an attribute, the table where it belongs to, and eventually the parent (in case of a foreign key). The expected (correct) way to indicate this information is:
table name,attribute,SQL-type definition- Returns:
output= python terminal outputumlOutput= the UML code (string) generated- Return type:
tuple (2 strings)
- run.sqlToDict(file) dict
Reads an SQL script file and transforms it into a dictionary with the required format to be used to create a UML/SQL file.
- Parameters:
file (sqlite3 script) – SQL script file (minimum statements)
- Returns:
dictionary with the tables’ data
{
TABLE NAME 1: [(ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT), (…)]}- Return type:
dict
- run.umlToDict(file) dict
Reads an UML script file and transforms it into a dictionary with the required format to be used to create a UML/SQL file.
- Parameters:
file (UML script) – UML script file (see formatStrings for structure info)
- Returns:
dictionary with the tables’ data
{
TABLE NAME 1: [(ATTRIBUTE X,ATTRIBUTE'S X TYPE,SQL SCRIPT), (…)]}- Return type:
dict