| 302 | |
| 303 | @dataclass |
| 304 | class TableGroupBlueprint(Blueprint): |
| 305 | name: str |
| 306 | items: List[str] |
| 307 | comment: Optional[str] = None |
| 308 | note: Optional[NoteBlueprint] = None |
| 309 | color: Optional[str] = None |
| 310 | |
| 311 | def build(self) -> 'TableGroup': |
| 312 | if not self.parser: |
| 313 | raise RuntimeError('Parser is not set') |
| 314 | items = [] |
| 315 | for table_name in self.items: |
| 316 | components = table_name.split('.') |
| 317 | schema, table = components if len(components) == 2 else ('public', components[0]) |
| 318 | table_obj = self.parser.locate_table(schema, table) |
| 319 | if table_obj in items: |
| 320 | raise ValidationError(f'Table "{table}" is already in group "{self.name}"') |
| 321 | items.append(table_obj) |
| 322 | return TableGroup( |
| 323 | name=self.name, |
| 324 | items=items, |
| 325 | comment=self.comment, |
| 326 | note=self.note.build() if self.note else None, |
| 327 | color=self.color |
| 328 | ) |
no outgoing calls