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
transactionrecords 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 BYclause 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
joinsparam. If specified, each item in thejoinssequence must be a 3-tuple:(related_class, related_attr, instance_attr)
The meaning of those is as follows; assuming
Useris the main instance model class:related_class- model class which is “related” to the instance model class, e.g.UserExtensionrelated_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_typefrom 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.INSERTsqlalchemy_continuum:sqlalchemy_continuum.operation.Operation.UPDATEsqlalchemy_continuum:sqlalchemy_continuum.operation.Operation.DELETE
- Returns:
Display name for the operation type, as string.