sqla-filters: Nodes

Base nodes

../_images/base_nodes.png

Tree

class sqla_filters.nodes.base.TreeNode[source]

Abstract base class for every nodes.

This class

childs

Property that return the node childs list.

Returns:The node childs list.
Return type:List[TreeNode]
filter(query: sqlalchemy.orm.query.Query, entity: type) → Tuple[sqlalchemy.orm.query.Query, Any][source]

Define the filter function that every node must to implement.

Parameters:
  • query (Query) – The sqlalchemy query.
  • entity (type) – The entity model.
Returns:

The filtered query.

Return type:

Tuple[Query, Any]

Base logical

class sqla_filters.nodes.base.BaseLogicalNode(*args, method=<function default_method>, **kwargs)[source]
filter(query: sqlalchemy.orm.query.Query, entity: type) → Tuple[sqlalchemy.orm.query.Query, Any][source]

Apply the _method to all childs of the node.

Parameters:
  • query (Query) – The sqlachemy query.
  • entity (type) – The entity model of the query.
Returns:

A tuple with in first place the updated query and in second place the list of filters to apply to the query.

Return type:

Tuple[Query, Any]

Base operational

class sqla_filters.nodes.base.BaseOperationalNode(attribute: str, value: Any, attr_sep: str = '.')[source]
_extract_relations(attribute: str) → Tuple[List[str], str][source]

Split and return the list of relation(s) and the attribute.

Parameters:attribute (str) –
Returns:A tuple where the first element is the list of related entities and the second is the attribute.
Return type:Tuple[List[str], str]
_get_relation(related_model: type, relations: List[str]) → Tuple[Optional[List[type]], Optional[type]][source]

Transform the list of relation to list of class.

Parameters:
  • related_mode (type) – The model of the query.
  • relations (List[str]) – The relation list get from the _extract_relations.
Returns:

Tuple with the list of relations (class) and the second element is the last relation class.

Return type:

Tuple[Optional[List[type]], Optional[type]]

_join_tables(query: sqlalchemy.orm.query.Query, join_models: Optional[List[type]]) → sqlalchemy.orm.query.Query[source]

Method to make the join when relation is found.

Parameters:
  • query (Query) – The sqlalchemy query.
  • join_models (Optional[List[type]]) – The list of joined models get from the method _get_relation.
Returns:

The new Query with the joined tables.

Return type:

Query

attribute

Property that return the model attribute.

Returns:The model attribute.
Return type:str
filter(query: sqlalchemy.orm.query.Query, entity: type) → Tuple[sqlalchemy.orm.query.Query, Any][source]

Add a filters to the list of filters to apply.

Warning

This method must be override in childs nodes.

Parameters:
  • query (Query) – The sqlachemy query.
  • entity (type) – The entity model of the query.
Returns:

A tuple with in first place the updated query and in second place the list of filters to apply to the query.

Return type:

Tuple[Query, Any]

value

Property that return the value of the model attribute.

Returns:The value of the model attribute.
Return type:Any

Logical nodes

../_images/logical_nodes.png

And

class sqla_filters.nodes.logical.AndNode[source]

Represent the and operation from sqlalchemy.

When the filter method is called on this node it run on all of it’s childs to create the filters list and apply the and_ function to this list.

Or

class sqla_filters.nodes.logical.OrNode[source]

Represent the or operation from sqlalchemy.

When the filter method is called on this node it run on all of it’s childs to create the filters list and apply the or_ function to this list.

Operational nodes

../_images/operational_nodes.png

Equality

class sqla_filters.nodes.operational.EqNode(attribute: str, value: Any, attr_sep: str = '.')[source]

EqNode class.

This node test the equality between two values. Internally it use the operators.eq function available in sqlalchemy.sql.operators.

class sqla_filters.nodes.operational.NotEqNode(attribute: str, value: Any, attr_sep: str = '.')[source]

NotEqNode class.

This node test the non equality between two values. Internally it use the operators.ne function available in sqlalchemy.sql.operators.

Greater / Greater equal

class sqla_filters.nodes.operational.GtNode(attribute: str, value: Any, attr_sep: str = '.')[source]

GtNode class.

This node test if a value is greater than another one. Internally it use the operators.gt function available in sqlalchemy.sql.operators.

class sqla_filters.nodes.operational.GteNode(attribute: str, value: Any, attr_sep: str = '.')[source]

GteNode class.

This node test if a value is greater or equal to another one. Internally it use the operators.ge function available in sqlalchemy.sql.operators.

Lower / Lower equal

class sqla_filters.nodes.operational.LtNode(attribute: str, value: Any, attr_sep: str = '.')[source]

LtNode class.

This node test if a value is lower than another one. Internally it use the operators.lt function available in sqlalchemy.sql.operators.

class sqla_filters.nodes.operational.LteNode(attribute: str, value: Any, attr_sep: str = '.')[source]

LteNode class.

This node test if a value is lower or equal to another one. Internally it use the operators.le function available in sqlalchemy.sql.operators.

Contains

class sqla_filters.nodes.operational.ContainsNode(attribute: str, value: Any, attr_sep: str = '.')[source]

ContainsNode class.

This node test if an attribut contains the value. Internally it use the operators.contains function available in sqlalchemy.sql.operators.

Like

class sqla_filters.nodes.operational.LikeNode(attribute: str, value: Any, attr_sep: str = '.')[source]

ContainsNode class.

This node test if an attribut is like the value. This function have the behavior of the LIKE in the sql language. This node use the attr.like function of a model attribute.

In

class sqla_filters.nodes.operational.InNode(attribute: str, value: Any, attr_sep: str = '.')[source]

InNode class.

This node test if an attribut is in a list of values. This function have the behavior of the in in the sql language. This node use the attr.in function of a model attribute.

class sqla_filters.nodes.operational.NotInNode(attribute: str, value: Any, attr_sep: str = '.')[source]

NotInNode class.

This node test if an attribut is not in a list of values. This function have the behavior of the not in in the sql language. This node use the ~attr.in_ function of a model attribute.

Null

class sqla_filters.nodes.operational.InNode(attribute: str, value: Any, attr_sep: str = '.')[source]

InNode class.

This node test if an attribut is in a list of values. This function have the behavior of the in in the sql language. This node use the attr.in function of a model attribute.

class sqla_filters.nodes.operational.NotInNode(attribute: str, value: Any, attr_sep: str = '.')[source]

NotInNode class.

This node test if an attribut is not in a list of values. This function have the behavior of the not in in the sql language. This node use the ~attr.in_ function of a model attribute.