asyncqlio.orm.operators

Classes for operators returned from queries.

Functions

requires_bop(…) A decorator that marks a magic method as requiring another BaseOperator.

Classes

And(*ops: asyncqlio.orm.operators.BaseOperator) Represents an AND operator in a query.
AscSorter(…)
BaseOperator The base operator class.
BasicSetter(…) Represents a basic setting operation.
ColumnValueMixin(…) A mixin that specifies that an operator takes both a Column and a Value as arguments.
ComparisonOp(…) A helper class that implements easy generation of comparison-based operators.
DecrementSetter(…) Represents a decrement setter.
DescSorter(…)
Eq(…) Represents an equality operator.
Gt(…) Represents a more than operator.
Gte(…) Represents a more than or equals to operator.
HackyILike(…) A “hacky” ILIKE operator for databases that do not support it.
ILike(…) Represents an ILIKE operator.
In(…)
IncrementSetter(…) Represents an increment setter.
Like(…) Represents a LIKE operator.
Lt(…) Represents a less than operator.
Lte(…) Represents a less than or equals to operator.
NEq(…) Represents a non-equality operator.
OperatorResponse(sql: str, parameters: dict) A storage class for the generated SQL from an operator.
Or(*ops: asyncqlio.orm.operators.BaseOperator) Represents an OR operator in a query.
Sorter(…) A generic sorter operator, for use in ORDER BY.
ValueSetter(…) Represents a value setter (col = 1).
class asyncqlio.orm.operators.OperatorResponse(sql: str, parameters: dict)[source]

Bases: object

A storage class for the generated SQL from an operator.

Parameters:
  • sql – The generated SQL for this operator.
  • parameters – A dict of parameters to use for this response.
asyncqlio.orm.operators.requires_bop(func) → typing.Callable[[asyncqlio.orm.operators.BaseOperator, asyncqlio.orm.operators.BaseOperator], typing.Any][source]

A decorator that marks a magic method as requiring another BaseOperator.

Parameters:func – The function to decorate.
Returns:A function that returns NotImplemented when the class required isn’t specified.
class asyncqlio.orm.operators.BaseOperator[source]

Bases: abc.ABC

The base operator class.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str][source]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
generate_sql(emitter: typing.Callable[[str], str], counter: itertools.count) → asyncqlio.orm.operators.OperatorResponse[source]

Generates the SQL for an operator.

Parameters must be generated using the emitter callable.

Parameters:
  • emitter – A callable that can be used to generate param placeholders in a query.
  • counter – The current “parameter number”.
Returns:

A OperatorResponse representing the result.

Warning

The param name and the param can be empty if none is to be returned.

class asyncqlio.orm.operators.And(*ops: asyncqlio.orm.operators.BaseOperator)[source]

Bases: asyncqlio.orm.operators.BaseOperator

Represents an AND operator in a query.

This will join multiple other BaseOperator objects together.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.Or(*ops: asyncqlio.orm.operators.BaseOperator)[source]

Bases: asyncqlio.orm.operators.BaseOperator

Represents an OR operator in a query.

This will join multiple other BaseOperator objects together.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.Sorter(*columns: asyncqlio.orm.schema.column.Column)[source]

Bases: asyncqlio.orm.operators.BaseOperator

A generic sorter operator, for use in ORDER BY.

sort_order

The sort order for this row; ASC or DESC.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.ColumnValueMixin(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: object

A mixin that specifies that an operator takes both a Column and a Value as arguments.

class MyOp(BaseOperator, ColumnValueMixin):
    ...

# myop is constructed MyOp(col, value)
class asyncqlio.orm.operators.BasicSetter(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.BaseOperator, asyncqlio.orm.operators.ColumnValueMixin

Represents a basic setting operation. Used for bulk queries.

set_operator
Returns:The “setting” operator to use when generating the SQL.
get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.ValueSetter(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.BasicSetter

Represents a value setter (col = 1).

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.IncrementSetter(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.BasicSetter

Represents an increment setter. (col = col + 1)

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.DecrementSetter(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.BasicSetter

Represents a decrement setter.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.ComparisonOp(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ColumnValueMixin, asyncqlio.orm.operators.BaseOperator

A helper class that implements easy generation of comparison-based operators.

To customize the operator provided, set the value of operator in the class body.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.Eq(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ComparisonOp

Represents an equality operator.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.NEq(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ComparisonOp

Represents a non-equality operator.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.Lt(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ComparisonOp

Represents a less than operator.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.Gt(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ComparisonOp

Represents a more than operator.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.Lte(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ComparisonOp

Represents a less than or equals to operator.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.Gte(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ComparisonOp

Represents a more than or equals to operator.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.Like(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ComparisonOp

Represents a LIKE operator.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.ILike(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.ComparisonOp

Represents an ILIKE operator.

Warning

This operator is not natively supported on all dialects. If used on a dialect that doesn’t support it, it will fallback to a lowercase LIKE.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.
class asyncqlio.orm.operators.HackyILike(column: asyncqlio.orm.schema.column.Column, value: typing.Any)[source]

Bases: asyncqlio.orm.operators.BaseOperator, asyncqlio.orm.operators.ColumnValueMixin

A “hacky” ILIKE operator for databases that do not support it.

get_param(emitter: typing.Callable[[str], str], counter: itertools.count) → typing.Tuple[str, str]

Gets the next parameter.

Parameters:
  • emitter – A function that emits a parameter name that can be formatted in a SQL query.
  • counter – The counter for parameters.