wutta_continuum.util

SQLAlchemy-Continuum utilities

wutta_continuum.util.model_transaction_query(instance, session=None, model_class=None, joins=None)[source]

Make a query capable of finding all SQLAlchemy-Continuum transaction records associated with the given model instance.

Parameters:
  • instance – Instance of a versioned data model.

  • session – Optional db session to use for the query. If not specified, will be obtained from the instance.

  • model_class – Optional data model class to query. If not specified, will be obtained from the instance.

  • joins – Optional sequence of “join info tuples” - see further explanation below.

Returns:

SQLAlchemy query object. Note that it will not have an ORDER BY clause yet.

The default logic looks for any “version” records for the given instance, and returns the associated transactions. But sometimes you need to look for more than one type of version record:

If e.g. a core table provides common fields but a custom table adds extension fields for a record, you will want to find transactions involving either version table when showing a record’s total history.

This is accomplished here via the joins param. If specified, each item in the joins sequence must be a 3-tuple:

(related_class, related_attr, instance_attr)

The meaning of those is as follows; assuming User is the main instance model class:

  • related_class - model class which is “related” to the instance model class, e.g. UserExtension

  • related_attr - attribute name on the related class which serves as foreign key to the instance, e.g. "user_uuid"

  • instance_attr - attribute name on the main instance class which serves as primary key, e.g. "uuid"

wutta_continuum.util.render_operation_type(operation_type)[source]

Render a SQLAlchemy-Continuum operation_type from a version record, for display to user.

Parameters:

operation_type

Value of same name from a version record. Must be one of:

  • sqlalchemy_continuum:sqlalchemy_continuum.operation.Operation.INSERT

  • sqlalchemy_continuum:sqlalchemy_continuum.operation.Operation.UPDATE

  • sqlalchemy_continuum:sqlalchemy_continuum.operation.Operation.DELETE

Returns:

Display name for the operation type, as string.