mate_query.string module

Module implementing an enhanced string column type for SQLAlchemy with a support for regular expression operators in Postgres and SQLite.

http://xion.io/post/code/sqlalchemy-regex-filters.html https://gist.github.com/Xion/204ddbd020f1a4275a53

class mate_query.string.StringComparator(expression)

Bases: sqlalchemy.ext.hybrid.Comparator

A custom comparator for strings supporting a re_match operation.

operate(op: Any, other: Any, **_kwargs: Any) Any

Operate on an argument.

This is the lowest level of operation, raises NotImplementedError by default.

Overriding this on a subclass can allow common behavior to be applied to all operations. For example, overriding ColumnOperators to apply func.lower() to the left and right side:

class MyComparator(ColumnOperators):
    def operate(self, op, other):
        return op(func.lower(self), func.lower(other))
Parameters
  • op – Operator callable.

  • *other – the ‘other’ side of the operation. Will be a single scalar for most operations.

  • **kwargs – modifiers. These may be passed by special operators such as ColumnOperators.contains().

  • op (Any) –

  • other (Any) –

  • _kwargs (Any) –

Return type

Any

prop
property
re_match(other: re.Pattern) mate_query.string._RegexMatchExpression
Parameters

other (re.Pattern) –

Return type

mate_query.string._RegexMatchExpression