TableGroup `items` parameter initially holds just the names of the tables, but after parsing the whole document, PyDBMLParseResults class replaces them with references to actual tables.
| 7 | |
| 8 | |
| 9 | class TableGroup(DBMLObject): |
| 10 | ''' |
| 11 | TableGroup `items` parameter initially holds just the names of the tables, |
| 12 | but after parsing the whole document, PyDBMLParseResults class replaces |
| 13 | them with references to actual tables. |
| 14 | ''' |
| 15 | dont_compare_fields = ('database',) |
| 16 | |
| 17 | def __init__(self, |
| 18 | name: str, |
| 19 | items: List[Table], |
| 20 | comment: Optional[str] = None, |
| 21 | note: Optional[Note] = None, |
| 22 | color: Optional[str] = None): |
| 23 | self.database = None |
| 24 | self.name = name |
| 25 | self.items = items |
| 26 | self.comment = comment |
| 27 | self.note = note |
| 28 | self.color = color |
| 29 | |
| 30 | def __repr__(self): |
| 31 | """ |
| 32 | >>> tg = TableGroup('mygroup', ['t1', 't2']) |
| 33 | >>> tg |
| 34 | <TableGroup 'mygroup', ['t1', 't2']> |
| 35 | >>> t1 = Table('t1') |
| 36 | >>> t2 = Table('t2') |
| 37 | >>> tg.items = [t1, t2] |
| 38 | >>> tg |
| 39 | <TableGroup 'mygroup', ['t1', 't2']> |
| 40 | """ |
| 41 | |
| 42 | items = [i if isinstance(i, str) else i.name for i in self.items] |
| 43 | return f'<TableGroup {self.name!r}, {items!r}>' |
| 44 | |
| 45 | def __getitem__(self, key: int) -> Table: |
| 46 | return self.items[key] |
| 47 | |
| 48 | def __iter__(self): |
| 49 | return iter(self.items) |
no outgoing calls