Contains information about a table in a database.
| 73 | |
| 74 | |
| 75 | class DatabaseTable(object): |
| 76 | """Contains information about a table in a database.""" |
| 77 | |
| 78 | def __init__(self): |
| 79 | self.original_table_name = None |
| 80 | self.table_name_wordpieces = list() |
| 81 | self.table_columns = list() |
| 82 | self.matches_to_utterance = None |
| 83 | |
| 84 | def to_json(self): |
| 85 | return { |
| 86 | 'original_table_name': self.original_table_name, |
| 87 | 'table_name_wordpieces': [ |
| 88 | wordpiece.to_json() for wordpiece in self.table_name_wordpieces |
| 89 | ], |
| 90 | 'table_columns': [column.to_json() for column in self.table_columns], |
| 91 | 'matches_to_utterance': self.matches_to_utterance |
| 92 | } |
| 93 | |
| 94 | def from_json(self, dictionary): |
| 95 | """Converts from a JSON dictionary to a DatabaseTable object.""" |
| 96 | self.original_table_name = dictionary['original_table_name'] |
| 97 | self.table_name_wordpieces = [ |
| 98 | Wordpiece().from_json(wordpiece) |
| 99 | for wordpiece in dictionary['table_name_wordpieces'] |
| 100 | ] |
| 101 | self.table_columns = [ |
| 102 | TableColumn().from_json(column) |
| 103 | for column in dictionary['table_columns'] |
| 104 | ] |
| 105 | self.matches_to_utterance = dictionary['matches_to_utterance'] |
| 106 | |
| 107 | return self |
| 108 | |
| 109 | def __str__(self): |
| 110 | return json.dumps(self.to_json()) |
| 111 | |
| 112 | |
| 113 | def column_is_primary_key(column): |
no outgoing calls
no test coverage detected
searching dependent graphs…