| 141 | |
| 142 | |
| 143 | class ItemType(str, Enum): |
| 144 | CONNECTION = "connection" |
| 145 | FUNCTION = "function" |
| 146 | INDEX = "index" |
| 147 | MATERIALIZED_VIEW = "materialized-view" |
| 148 | SECRET = "secret" |
| 149 | SINK = "sink" |
| 150 | SOURCE = "source" |
| 151 | TABLE = "table" |
| 152 | TYPE = "type" |
| 153 | VIEW = "view" |
| 154 | |
| 155 | def sql(self) -> str: |
| 156 | """Return the SQL string corresponding to this item type.""" |
| 157 | return self.replace("-", " ").upper() |
| 158 | |
| 159 | def show_create(self, fqname: str) -> str | None: |
| 160 | """ |
| 161 | Return a show create query for an item of the given type identified by |
| 162 | the given `fqname` or `None` for item types that are currently not |
| 163 | supported. |
| 164 | """ |
| 165 | if self in [ |
| 166 | ItemType.INDEX, |
| 167 | ItemType.MATERIALIZED_VIEW, |
| 168 | ItemType.SOURCE, |
| 169 | ItemType.TABLE, |
| 170 | ItemType.VIEW, |
| 171 | ]: |
| 172 | return f"SHOW CREATE {self.sql()} {fqname}" |
| 173 | else: # unsupported item type |
| 174 | return None |
| 175 | |
| 176 | |
| 177 | @dataclass(frozen=True) |
no outgoing calls
no test coverage detected