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

Class Column

pydbml/_classes/column.py:17–94  ·  view source on GitHub ↗

Class representing table column.

Source from the content-addressed store, hash-verified

15
16
17class Column(SQLObject, DBMLObject):
18 '''Class representing table column.'''
19
20 required_attributes = ('name', 'type')
21 dont_compare_fields = ('table',)
22
23 def __init__(self,
24 name: str,
25 type: Union[str, Enum],
26 unique: bool = False,
27 not_null: bool = False,
28 pk: bool = False,
29 autoinc: bool = False,
30 default: Optional[Union[str, int, bool, float, Expression]] = None,
31 note: Optional[Union[Note, str]] = None,
32 comment: Optional[str] = None,
33 properties: Union[Dict[str, str], None] = None
34 ):
35 self.name = name
36 self.type = type
37 self.unique = unique
38 self.not_null = not_null
39 self.pk = pk
40 self.autoinc = autoinc
41 self.comment = comment
42 self.note = Note(note)
43 self.properties = properties if properties else {}
44
45 self.default = default
46 self.table: Optional['Table'] = None
47
48 def __eq__(self, other: object) -> bool:
49 if other is self:
50 return True
51 if not isinstance(other, self.__class__):
52 return False
53 self_table = self.table.full_name if self.table else None
54 other_table = other.table.full_name if other.table else None
55 if self_table != other_table:
56 return False
57 return super().__eq__(other)
58
59 @property
60 def note(self):
61 return self._note
62
63 @note.setter
64 def note(self, val: Note) -> None:
65 self._note = val
66 val.parent = self
67
68 def get_refs(self) -> List['Reference']:
69 '''
70 get all references related to this column (where this col is col1 in)
71 '''
72 if not self.table:
73 raise TableNotFoundError('Table for the column is not set')
74 return [ref for ref in self.table.get_refs() if self in ref.col1]

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_deleteMethod · 0.90
simple_columnFunction · 0.90
complex_columnFunction · 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_deleteMethod · 0.72
simple_columnFunction · 0.72
complex_columnFunction · 0.72