Skip to content

Commit

Permalink
add custom __repr__ to ermrest_model Schema, Table, Column, Key, Fore…
Browse files Browse the repository at this point in the history
…ignKey
  • Loading branch information
karlcz committed Oct 1, 2024
1 parent 67db3e3 commit e49197c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions deriva/core/ermrest_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,15 @@ def __init__(self, model, sname, schema_doc):
for tname, tdoc in schema_doc.get('tables', {}).items()
}

def __repr__(self):
cls = type(self)
return "<%s.%s object %r at 0x%x>" % (
cls.__module__,
cls.__name__,
self.name,
id(self),
)

@property
def catalog(self):
return self.model.catalog
Expand Down Expand Up @@ -801,6 +810,16 @@ def __init__(self, schema, tname, table_doc):
])
self.referenced_by = KeyedList([])

def __repr__(self):
cls = type(self)
return "<%s.%s object %r.%r at 0x%x>" % (
cls.__module__,
cls.__name__,
self.schema.name if self.schema is not None else None,
self.name,
id(self),
)

@property
def columns(self):
"""Sugared access to self.column_definitions"""
Expand Down Expand Up @@ -2106,6 +2125,17 @@ def __init__(self, table, column_doc):
self.default = column_doc.get('default')
self.comment = column_doc.get('comment')

def __repr__(self):
cls = type(self)
return "<%s.%s object %r.%r.%r at 0x%x>" % (
cls.__module__,
cls.__name__,
self.table.schema.name if self.table is not None and self.table.schema is not None else None,
self.table.name if self.table is not None else None,
self.name,
id(self),
)

@property
def catalog(self):
return self.table.schema.model.catalog
Expand Down Expand Up @@ -2347,6 +2377,16 @@ def __init__(self, table, key_doc):
for cname in key_doc['unique_columns']
])

def __repr__(self):
cls = type(self)
return "<%s.%s object %r.%r at 0x%x>" % (
cls.__module__,
cls.__name__,
self.constraint_schema.name if self.constraint_schema is not None else None,
self.constraint_name,
id(self),
)

@property
def columns(self):
"""Sugared access to self.unique_columns"""
Expand Down Expand Up @@ -2545,6 +2585,16 @@ def __init__(self, table, fkey_doc):
self._referenced_columns_doc = fkey_doc['referenced_columns']
self.referenced_columns = None

def __repr__(self):
cls = type(self)
return "<%s.%s object %r.%r at 0x%x>" % (
cls.__module__,
cls.__name__,
self.constraint_schema.name if self.constraint_schema is not None else None,
self.constraint_name,
id(self),
)

def digest_referenced_columns(self, model):
"""Finish construction deferred until model is known with all tables."""
if self.referenced_columns is None:
Expand Down

0 comments on commit e49197c

Please sign in to comment.