Query Processing Pipeline
Avocado provides a
avocado.query.pipeline package for handling and combining some of the boilerplate setup and interaction between it's APIs for using it as an end-to-end query pipeline.
Currently there is a single class,
QueryProcessor, that provides a few methods to make it easier for constructing and executing queries. A processor is initialized with an optional set of arguments:
ModelTreealias or instance
include_pk- A boolean denoting whether the primary key should be included in the result set. Default is
from avocado.query import pipeline processor = pipeline.query_processors.default() # It also supports key lookups processor = pipeline.query_processors['default']()
Create a QuerySet based on context, view, and tree. It also takes a
queryset argument to act as a base queryset to build upon.
queryset = processor.get_queryset()
Prepare an iterable for the exporter to consume with optional
limit arguments. This calls
get_queryset internally and passes any
iterable = processor.get_iterable()
Prepare an exporter instance given an exporter class. This passes the
view provided during initialization to the exporter. If
True an additional raw formatter will be inserted to handle the additional value at the beginning of the row.
from avocado.export import CSVExporter exporter = processor.get_exporter(CSVExporter)