diff --git a/royalnet/alchemist/__init__.py b/royalnet/alchemist/__init__.py index 8ce214bb..57a80848 100644 --- a/royalnet/alchemist/__init__.py +++ b/royalnet/alchemist/__init__.py @@ -1 +1,2 @@ from .func import * +from .repr import * \ No newline at end of file diff --git a/royalnet/alchemist/repr.py b/royalnet/alchemist/repr.py new file mode 100644 index 00000000..f6688ac0 --- /dev/null +++ b/royalnet/alchemist/repr.py @@ -0,0 +1,12 @@ +class ColRepr: + """A mixin that can be added to a declared class to display all table columns in the __repr__.""" + + def __repr__(self): + columns = [c.name for c in self.__class__.__table__.columns] + args = [f"{c}={repr(self.__getattribute__(c))}" for c in columns] + return f"{self.__class__.__qualname__}({', '.join(args)})" + + +__all__ = ( + "ColRepr", +)