Query builder

flask_restalchemy.resources.querybuilder.create_collection_query(parent_query, model_class, model_serializer, args)[source]

Build a query using query parameters in the http URL, disposed on the request args. The default logical operator is AND, but you can set the OR as in the following examples:

  1. OR -> ?filter={“$or”:{“name”: {“startswith”: “Terrans 1”},”location”: “Location 1”}}
  2. AND -> ?filter={“$and”:{“name”: {“ilike”: “%Terrans 1%”},”location”: “Location 1”}}
    or ?filter={“name”: {“ilike”: “%Terrans 1%”},”location”: {“eq”: “Location 1”}}

Ordered search is available using ‘order_by=<col_name>’. The minus sign (“-<col_name>”) could be used to set descending order.

Parameters:
  • parent_query – SQLAlchemy query instance
  • model_class (class) – SQLAlchemy model class representing a database resource
  • model_serializer – instance of model serializer
  • args – arguments of the Flask http request
Return type:

query

Returns:

SQLAlchemy query instance

flask_restalchemy.resources.querybuilder.get_field_serializer_or_none(serializer, field_name)[source]
flask_restalchemy.resources.querybuilder.get_operator(column, op_name, value, serializer)[source]
Parameters:
  • column – SQLAlchemy ColumnElement
  • op_name – Key of OPERATORS or COMPARE_OPERATORS
  • value – value to be applied to the operator
Return type:

ColumnOperators

Returns:

returns a boolean, comparison, and other operators for ColumnElement expressions. ref: http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.operators.ColumnOperators

flask_restalchemy.resources.querybuilder.parse_value(value, serializer)[source]