MCPcopy Index your code
hub / github.com/piccolo-orm/piccolo / Table

Class Table

piccolo/table.py:239–1525  ·  view source on GitHub ↗

The class represents a database table. An instance represents a row.

Source from the content-addressed store, hash-verified

237
238
239class Table(metaclass=TableMetaclass):
240 """
241 The class represents a database table. An instance represents a row.
242 """
243
244 # These are just placeholder values, so type inference isn't confused - the
245 # actual values are set in __init_subclass__.
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] = []

Callers

nothing calls this directly

Calls 1

TableMetaClass · 0.85

Tested by

no test coverage detected