An abstract class which specifies append, delete, and set event handlers to be attached to an object property.
a MapperOption that applies a MapperExtension to a query operation.
a stack object used during load operations to track the current position among a chain of mappers to eager loaders.
return an 'snapshot' of this stack.
this is a tuple form of the stack which can be used as a hash key.
Describe the loading behavior of a StrategizedProperty object.
The LoaderStrategy interacts with the querying process in three ways:
return row processing functions which fulfill the contract specified by MapperProperty.create_row_processor.
StrategizedProperty delegates its create_row_processor method directly to this method.
Base implementation for customizing Mapper behavior.
For each method in MapperExtension, returning a result of EXT_CONTINUE will allow processing to continue to the next MapperExtension in line or use the default functionality if there are no other extensions.
Returning EXT_STOP will halt processing of further extensions handling that method. Some methods such as load have other return requirements, see the individual documentation for details. Other than these exception cases, any return value other than EXT_CONTINUE or EXT_STOP will be interpreted as equivalent to EXT_STOP.
EXT_PASS is a synonym for EXT_CONTINUE and is provided for backward compatibility.
Receive an object instance after that instance is DELETEed.
Receive an object instance after that instance is INSERTed.
Receive an object instance after that instance is UPDATEed.
Receive an object instance before that instance is appended to a result list.
If this method returns EXT_CONTINUE, result appending will proceed normally. if this method returns any other value or None, result appending will not proceed for this instance, giving this extension an opportunity to do the appending itself, if desired.
Receive an object instance before that instance is DELETEed.
Note that no changes to the overall flush plan can be made here; this means any collection modification, save() or delete() operations which occur within this method will not take effect until the next flush call.
Receive an object instance before that instance is INSERTed into its table.
This is a good place to set up primary key values and such that aren't handled otherwise.
Column-based attributes can be modified within this method which will result in the new value being inserted. However no changes to the overall flush plan can be made; this means any collection modification or save() operations which occur within this method will not take effect until the next flush call.
Receive an object instance before that instance is UPDATEed.
Note that this method is called for all instances that are marked as "dirty", even those which have no net changes to their column-based attributes. An object is marked as dirty when any of its column-based attributes have a "set attribute" operation called or when any of its collections are modified. If, at update time, no column-based attributes have any net changes, no UPDATE statement will be issued. This means that an instance being sent to before_update is not a guarantee that an UPDATE statement will be issued (although you can affect the outcome here).
To detect if the column-based attributes on the object have net changes, and will therefore generate an UPDATE statement, use object_session(instance).is_modified(instance, include_collections=False).
Column-based attributes can be modified within this method which will result in their being updated. However no changes to the overall flush plan can be made; this means any collection modification or save() operations which occur within this method will not take effect until the next flush call.
Receive a row when a new object instance is about to be created from that row.
The method can choose to create the instance itself, or it can return None to indicate normal object creation should take place.
Override the get method of the Query object.
The return value of this method is used as the result of query.get() if the value is anything other than EXT_CONTINUE.
Override the get_by method of the Query object.
The return value of this method is used as the result of query.get_by() if the value is anything other than EXT_CONTINUE.
DEPRECATED.
Retrieve a contextual Session instance with which to register a new object.
Note: this is not called if a session is provided with the __init__ params (i.e. _sa_session).
Override the load method of the Query object.
The return value of this method is used as the result of query.load() if the value is anything other than EXT_CONTINUE.
Receive a newly-created instance before that instance has its attributes populated.
The normal population of attributes is according to each attribute's corresponding MapperProperty (which includes column-based attributes as well as relationships to other classes). If this method returns EXT_CONTINUE, instance population will proceed normally. If any other value or None is returned, instance population will not proceed, giving this extension an opportunity to populate the instance itself, if desired.
Override the select method of the Query object.
The return value of this method is used as the result of query.select() if the value is anything other than EXT_CONTINUE.
DEPRECATED.
Override the select_by method of the Query object.
The return value of this method is used as the result of query.select_by() if the value is anything other than EXT_CONTINUE.
DEPRECATED.
Perform pre-processing on the given result row and return a new row instance.
This is called as the very first step in the _instance() method.
Describe a modification to an OperationContext or Query.
Manage the relationship of a Mapper to a single class attribute, as well as that attribute as it appears on individual instances of the class, including attribute instrumentation, attribute access, loading behavior, and dependency calculations.
run the given callable across all objects which are child objects of the given object, as attached to the attribute corresponding to this MapperProperty.
return an iterator of objects which are child objects of the given object, as attached to the attribute corresponding to this MapperProperty.
Return a compare operation for the columns represented by this MapperProperty to the given value, which may be a column value or an instance. 'operator' is an operator from the operators module, or from sql.Comparator.
By default uses the PropComparator attached to this MapperProperty under the attribute name "comparator".
return a 3-tuple consiting of a two row processing functions and an instance post-processing function.
Input arguments are the query.SelectionContext and the first applicable row of a result set obtained within query.Query.instances(), called only the first time a particular mapper's populate_instance() method is invoked for the overall result.
The settings contained within the SelectionContext as well as the columns present in the row (which will be the same columns present in all rows) are used to determine the presence and behavior of the returned callables. The callables will then be used to process all rows and to post-process all instances, respectively.
callables are of the following form:
def new_execute(instance, row, **flags): # process incoming instance and given row. the instance is "new" and # was just created upon receipt of this row. # flags is a dictionary containing at least the following attributes: # isnew - indicates if the instance was newly created as a result of reading this row # instancekey - identity key of the instance # optional attribute: # ispostselect - indicates if this row resulted from a 'post' select of additional tables/columns def existing_execute(instance, row, **flags): # process incoming instance and given row. the instance is "existing" and # was created based on a previous row. def post_execute(instance, **flags): # process instance after all result rows have been processed. this # function should be used to issue additional selections in order to # eagerly load additional properties. return (new_execute, existing_execute, post_execute)
either of the three tuples can be None in which case no function is called.
Perform subclass-specific initialization steps.
This is a template method called by the MapperProperty object's init() method.
Return a WHERE clause suitable for this MapperProperty corresponding to the given key/value pair, where the key is a column or object property name, and value is a value to be matched. This is only picked up by PropertyLoaders.
This is called by a Query's join_by method to formulate a set of key/value pairs into a WHERE criterion that spans multiple tables if needed.
Called after all mappers are compiled to assemble relationships between mappers, establish instrumented class attributes.
Return True if this MapperProperty's mapper is the primary mapper for its class.
This flag is used to indicate that the MapperProperty can define attribute instrumentation for the class at the class level (as opposed to the individual instance level).
Merge the attribute represented by this MapperProperty from source to destination object
Called by the Mapper in response to the UnitOfWork calling the Mapper's register_dependencies operation. Should register with the UnitOfWork all inter-mapper dependencies as well as dependency processors (see UOW docs for more details).
Called by Query for the purposes of constructing a SQL statement.
Each MapperProperty associated with the target mapper processes the statement referenced by the query context, adding columns and/or criterion as appropriate.
Serve as a context during a query construction or instance loading operation.
Accept MapperOption objects which may modify its state before proceeding.
defines comparison operations for MapperProperty objects
return true if this collection contains any member that meets the given criterion.
return true if this element references a member which meets the given criterion.
A MapperOption that is applied to a property off the mapper or one of its child mappers, identified by a dot-separated key.
A MapperOption that affects which LoaderStrategy will be used for an operation by a StrategizedProperty.
A MapperProperty which uses selectable strategies to affect loading behavior.
There is a single default strategy selected by default. Alternate strategies can be selected at Query time through the usage of StrategizedOption objects via the Query.options() method.