DB Model Query¶
The implementation in neutron_lib.db.model_query
is intended to be used as a
stepping stone for existing consumers using standard database models/tables.
Moving forward new database implementations should all use neutron’s Versioned
Object approach, while existing model based implementations should begin
migrating to Versioned Objects.
Registering Hooks¶
The neutron_lib.db.model_query.register_hook
function allows hooks to be
registered for invocation during a respective database query.
Each hook has three components:
“query”: used to build the query expression
“filter”: used to build the filter expression
“result_filters”: used for final filtering on the query result
Query hooks take as input the query being built and return a transformed query expression. For example:
def mymodel_query_hook(context, original_model, query):
augmented_query = ...
return augmented_query
Filter hooks take as input the filter expression being built and return a transformed filter expression. For example:
def mymodel_filter_hook(context, original_model, filters):
refined_filters = ...
return refined_filters
Result filter hooks take as input the query expression and the filter expression, and return a final transformed query expression. For example:
def mymodel_result_filter_hook(query, filters):
final_filters = ...
return query.filter(final_filters)