Automatically populate the _meta, which includes the tablename, and columns. :param tablename: Specify a custom tablename. By default the classname is converted to snakecase. :param db: Manually specify an engine to use for connec
(
cls,
tablename: Optional[str] = None,
db: Optional[Engine] = None,
tags: Optional[list[str]] = None,
help_text: Optional[str] = None,
schema: Optional[str] = None,
)
| 246 | _meta = TableMeta() |
| 247 | |
| 248 | def __init_subclass__( |
| 249 | cls, |
| 250 | tablename: Optional[str] = None, |
| 251 | db: Optional[Engine] = None, |
| 252 | tags: Optional[list[str]] = None, |
| 253 | help_text: Optional[str] = None, |
| 254 | schema: Optional[str] = None, |
| 255 | ): # sourcery no-metrics |
| 256 | """ |
| 257 | Automatically populate the _meta, which includes the tablename, and |
| 258 | columns. |
| 259 | |
| 260 | :param tablename: |
| 261 | Specify a custom tablename. By default the classname is converted |
| 262 | to snakecase. |
| 263 | :param db: |
| 264 | Manually specify an engine to use for connecting to the database. |
| 265 | Useful when writing simple scripts. If not set, the engine is |
| 266 | imported from piccolo_conf.py using ``engine_finder``. |
| 267 | :param tags: |
| 268 | Used for filtering, for example by ``table_finder``. |
| 269 | :param help_text: |
| 270 | A user friendly description of what the table is used for. It isn't |
| 271 | used in the database, but will be used by tools such a Piccolo |
| 272 | Admin for tooltips. |
| 273 | :param schema: |
| 274 | The Postgres schema to use for this table. |
| 275 | |
| 276 | """ |
| 277 | if tags is None: |
| 278 | tags = [] |
| 279 | tablename = tablename or _camel_to_snake(cls.__name__) |
| 280 | |
| 281 | if "." in tablename: |
| 282 | warnings.warn( |
| 283 | "There's a '.' in the tablename - please use the `schema` " |
| 284 | "argument instead." |
| 285 | ) |
| 286 | schema, tablename = tablename.split(".", maxsplit=1) |
| 287 | |
| 288 | if tablename in PROTECTED_TABLENAMES: |
| 289 | warnings.warn(TABLENAME_WARNING.format(tablename=tablename)) |
| 290 | |
| 291 | columns: list[Column] = [] |
| 292 | default_columns: list[Column] = [] |
| 293 | non_default_columns: list[Column] = [] |
| 294 | array_columns: list[Array] = [] |
| 295 | foreign_key_columns: list[ForeignKey] = [] |
| 296 | secret_columns: list[Column] = [] |
| 297 | json_columns: list[Union[JSON, JSONB]] = [] |
| 298 | email_columns: list[Email] = [] |
| 299 | auto_update_columns: list[Column] = [] |
| 300 | primary_key: Optional[Column] = None |
| 301 | m2m_relationships: list[M2M] = [] |
| 302 | |
| 303 | attribute_names = itertools.chain( |
| 304 | *[i.__dict__.keys() for i in reversed(cls.__mro__)] |
| 305 | ) |
nothing calls this directly
no test coverage detected