MCPcopy Create free account
hub / github.com/CloverHealth/temporal-sqlalchemy / build_history_class

Function build_history_class

temporal_sqlalchemy/clock.py:248–271  ·  view source on GitHub ↗

build a sqlalchemy model for given prop

(
        cls: declarative.DeclarativeMeta,
        prop: T_PROPS,
        schema: str = None)

Source from the content-addressed store, hash-verified

246
247
248def build_history_class(
249 cls: declarative.DeclarativeMeta,
250 prop: T_PROPS,
251 schema: str = None) -> nine.Type[TemporalProperty]:
252 """build a sqlalchemy model for given prop"""
253 class_name = "%s%s_%s" % (cls.__name__, 'History', prop.key)
254 table = build_history_table(cls, prop, schema)
255 base_classes = (
256 TemporalProperty,
257 declarative.declarative_base(metadata=table.metadata),
258 )
259 class_attrs = {
260 '__table__': table,
261 'entity': orm.relationship(
262 lambda: cls,
263 backref=orm.backref('%s_history' % prop.key, lazy='dynamic'),
264 ),
265 }
266
267 if isinstance(prop, orm.RelationshipProperty):
268 class_attrs[prop.key] = orm.relationship(prop.argument, lazy='noload')
269
270 model = type(class_name, base_classes, class_attrs)
271 return model
272
273
274def _generate_history_table_name(local_table: sa.Table,

Callers 2

test_build_history_classFunction · 0.90
temporal_mapFunction · 0.85

Calls 1

build_history_tableFunction · 0.85

Tested by 1

test_build_history_classFunction · 0.72