This is used to store info about the table.
| 70 | |
| 71 | @dataclass |
| 72 | class TableMeta: |
| 73 | """ |
| 74 | This is used to store info about the table. |
| 75 | """ |
| 76 | |
| 77 | tablename: str = "" |
| 78 | columns: list[Column] = field(default_factory=list) |
| 79 | default_columns: list[Column] = field(default_factory=list) |
| 80 | non_default_columns: list[Column] = field(default_factory=list) |
| 81 | array_columns: list[Array] = field(default_factory=list) |
| 82 | email_columns: list[Email] = field(default_factory=list) |
| 83 | foreign_key_columns: list[ForeignKey] = field(default_factory=list) |
| 84 | primary_key: Column = field(default_factory=Column) |
| 85 | json_columns: list[Union[JSON, JSONB]] = field(default_factory=list) |
| 86 | secret_columns: list[Column] = field(default_factory=list) |
| 87 | auto_update_columns: list[Column] = field(default_factory=list) |
| 88 | tags: list[str] = field(default_factory=list) |
| 89 | help_text: Optional[str] = None |
| 90 | _db: Optional[Engine] = None |
| 91 | m2m_relationships: list[M2M] = field(default_factory=list) |
| 92 | schema: Optional[str] = None |
| 93 | |
| 94 | # Records reverse foreign key relationships - i.e. when the current table |
| 95 | # is the target of a foreign key. Used by external libraries such as |
| 96 | # Piccolo API. |
| 97 | _foreign_key_references: list[ForeignKey] = field(default_factory=list) |
| 98 | |
| 99 | def get_formatted_tablename( |
| 100 | self, include_schema: bool = True, quoted: bool = True |
| 101 | ) -> str: |
| 102 | """ |
| 103 | Returns the tablename, in the desired format. |
| 104 | |
| 105 | :param include_schema: |
| 106 | If ``True``, the Postgres schema is included. For example, |
| 107 | 'my_schema.my_table'. |
| 108 | :param quote: |
| 109 | If ``True``, the name is wrapped in double quotes. For example, |
| 110 | '"my_schema"."my_table"'. |
| 111 | |
| 112 | """ |
| 113 | components = [self.tablename] |
| 114 | if include_schema and self.schema: |
| 115 | components.insert(0, self.schema) |
| 116 | |
| 117 | if quoted: |
| 118 | return ".".join(f'"{i}"' for i in components) |
| 119 | else: |
| 120 | return ".".join(components) |
| 121 | |
| 122 | @property |
| 123 | def foreign_key_references(self) -> list[ForeignKey]: |
| 124 | foreign_keys: list[ForeignKey] = list(self._foreign_key_references) |
| 125 | lazy_column_references = LAZY_COLUMN_REFERENCES.for_tablename( |
| 126 | tablename=self.tablename |
| 127 | ) |
| 128 | foreign_keys.extend(lazy_column_references) |
| 129 |
no outgoing calls
no test coverage detected