Query

Criterion

class contacthub.models.query.criterion.Criterion(first_element, operator, second_element=None)[source]

Bases: object

Criterion class for applying a criteria to our queries. A criteria consists of three elements:

  • the queried attributes, an EntityField element if the criteria has a simple operator, another Criteria otherwise
  • an operator, simple or complex, for querying data
  • a value or a list of value to perform the comparision if the criteria has a simple operator, another Criteria otherwise

This criteria is consumed by a QueryBuilder object for returning a new Query object containing a dictionary representing the query in Contacthub

class COMPLEX_OPERATORS[source]

List of complex operators handled in Contacthub

AND = 'and'
OPERATORS = ['and', 'or']
OR = 'or'
class SIMPLE_OPERATORS[source]

List of simple operators handled in Contacthub

BETWEEN = 'BETWEEN'
EQUALS = 'EQUALS'
GT = 'GT'
GTE = 'GTE'
IN = 'IN'
IS_NOT_NULL = 'IS_NOT_NULL'
IS_NULL = 'IS_NULL'
LT = 'LT'
LTE = 'LTE'
NOT_EQUALS = 'NOT_EQUALS'
NOT_IN = 'NOT_IN'
OPERATORS = ['EQUALS', 'NOT_EQUALS', 'GT', 'GTE', 'LT', 'LTE', 'IN', 'NOT_IN', 'IS_NULL', 'IS_NOT_NULL', 'BETWEEN']

EntityField

class contacthub.models.query.entity_field.EntityField(entity, field)[source]

Bases: object

Class for creating Critierion object for queries. Use this class for handling all operation that you want to implements in queries syntax and create new Criterion with related operations.

EntityMeta

class contacthub.models.query.entity_meta.EntityMeta[source]

Bases: type

Metaclass for Properties class. Use this metaclass to handling the __getattr__ method and returns a new EntityField. This metaclass is useful for creating query objects and optimize the querying syntax.

Query

class contacthub.models.query.query.Query(node, entity, previous_query=None)[source]

Bases: object

Query object for applying the specified query in the APIs.

Use this class for interact with the DeclarativeAPIManager Layer or APIManagerLevel and return the queried as object or json format variables

all()[source]

Get all queried data of an entity from the API

Returns:a ReadOnly list with all object queried
filter(criterion)[source]

Create a new API Like query for Contacthub APIs (JSON Format)

Parameters:criterion – the Criterion object for fields for query data
Returns:a Query object containing the JSON object representing a query for the APIs

Module contents

contacthub.models.query.between_(attribute, value1, value2)[source]

In operation for check if a str representing a date or a datetime object is between value1 and value2

Parameters:
  • attribute – a date attribute to check if is between two values
  • value1 – the the lower extreme for compare the date attribute
  • value2 – the the upper extreme for compare the date attribute
Returns:

a new Criterion object representing the BETWEEN operation

contacthub.models.query.in_(value, list_attribute)[source]

IN operation for check if a value is in a list attribute

Parameters:
  • value – the value to check if is in the given list
  • list_attribute – a list attribute for checking the presence of the value
Returns:

a new Criterion object representing the IN operation between a list and a value

contacthub.models.query.not_in_(value, list_attribute)[source]

NOT IN operation for check if a value is NOT in a list attribute

Parameters:
  • value – the value to check if is not in the given list
  • list_attribute – a list attribute for checking the absence of the value
Returns:

a new Criterion object representing the NOT IN operation between a list and a value