MCPcopy Create free account
hub / github.com/Vanderhoof/PyDBML / Table

Class Table

pydbml/_classes/table.py:20–158  ·  view source on GitHub ↗

Class representing table.

Source from the content-addressed store, hash-verified

18
19
20class Table(SQLObject, DBMLObject):
21 '''Class representing table.'''
22
23 required_attributes = ('name', 'schema')
24 dont_compare_fields = ('database',)
25
26 def __init__(self,
27 name: str,
28 schema: str = 'public',
29 alias: Optional[str] = None,
30 columns: Optional[Iterable[Column]] = None,
31 indexes: Optional[Iterable[Index]] = None,
32 note: Optional[Union[Note, str]] = None,
33 header_color: Optional[str] = None,
34 comment: Optional[str] = None,
35 abstract: bool = False,
36 properties: Union[Dict[str, str], None] = None
37 ):
38 self.database: Optional[Database] = None
39 self.name = name
40 self.schema = schema
41 self.columns: List[Column] = []
42 for column in columns or []:
43 self.add_column(column)
44 self.indexes: List[Index] = []
45 for index in indexes or []:
46 self.add_index(index)
47 self.alias = alias if alias else None
48 self.note = Note(note)
49 self.header_color = header_color
50 self.comment = comment
51 self.abstract = abstract
52 self.properties = properties if properties else {}
53
54 @property
55 def note(self):
56 return self._note
57
58 @note.setter
59 def note(self, val: Note) -> None:
60 self._note = val
61 val.parent = self
62
63 @property
64 def full_name(self) -> str:
65 return f'{self.schema}.{self.name}'
66
67 def _has_composite_pk(self) -> bool:
68 return sum(c.pk for c in self.columns) > 1
69
70 def add_column(self, c: Column) -> None:
71 '''
72 Adds column to self.columns attribute and sets in this column the
73 `table` attribute.
74 '''
75 if not isinstance(c, Column):
76 raise TypeError('Columns must be of type Column')
77 c.table = self

Callers 15

test_add_tableMethod · 0.90
test_add_table_aliasMethod · 0.90
test_add_table_badMethod · 0.90
test_delete_tableMethod · 0.90
test_add_referenceMethod · 0.90
test_delete_referenceMethod · 0.90
test_add_table_groupMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_add_tableMethod · 0.72
test_add_table_aliasMethod · 0.72
test_add_table_badMethod · 0.72
test_delete_tableMethod · 0.72
test_add_referenceMethod · 0.72
test_delete_referenceMethod · 0.72
test_add_table_groupMethod · 0.72