MCPcopy
hub / github.com/tortoise/tortoise-orm / describe

Method describe

tortoise/fields/base.py:449–547  ·  view source on GitHub ↗

Describes the field. :param serializable: ``False`` if you want raw python objects, ``True`` for JSON-serializable data. (Defaults to ``True``) :return: A dictionary containing the field description. (This assumes ``serializ

(self, serializable: bool)

Source from the content-addressed store, hash-verified

447 return getattr(self, key, None)
448
449 def describe(self, serializable: bool) -> dict:
450 """
451 Describes the field.
452
453 :param serializable:
454 ``False`` if you want raw python objects,
455 ``True`` for JSON-serializable data. (Defaults to ``True``)
456
457 :return:
458 A dictionary containing the field description.
459
460 (This assumes ``serializable=True``, which is the default):
461
462 .. code-block:: python3
463
464 {
465 "name": str # Field name
466 "field_type": str # Field type
467 "db_column": str # Name of DB column
468 # Optional: Only for pk/data fields
469 "raw_field": str # Name of raw field of the Foreign Key
470 # Optional: Only for Foreign Keys
471 "db_field_types": dict # DB Field types for default and DB overrides
472 "python_type": str # Python type
473 "generated": bool # Is the field generated by the DB?
474 "nullable": bool # Is the column nullable?
475 "unique": bool # Is the field unique?
476 "indexed": bool # Is the field indexed?
477 "default": ... # The default value (coerced to int/float/str/bool/null)
478 "description": str # Description of the field (nullable)
479 "docstring": str # Field docstring (nullable)
480 }
481
482 When ``serializable=False`` is specified some fields are not coerced to valid
483 JSON types. The changes are:
484
485 .. code-block:: python3
486
487 {
488 "field_type": Field # The Field class used
489 "python_type": Type # The actual Python type
490 "default": ... # The default value as native type OR a callable
491 }
492 """
493
494 def _type_name(typ: type) -> str:
495 if typ.__module__ == "builtins":
496 return typ.__name__
497 if typ.__module__ == "typing":
498 return str(typ).replace("typing.", "")
499 return f"{typ.__module__}.{typ.__name__}"
500
501 def type_name(typ: Any) -> str | list[str]:
502 try:
503 return typ._meta.full_name
504 except (AttributeError, TypeError):
505 pass
506 try:

Callers

nothing calls this directly

Calls 2

has_db_defaultMethod · 0.95
get_db_field_typesMethod · 0.95

Tested by

no test coverage detected