Skip to main content

Module logical

Module logical 

Source
Expand description

Logical operators for SQL conditions: or_() and and_(), and the ConditionGroup that they make.

A group writes one set of brackets around the full chain. It writes no brackets around each operand: (a OR b OR c). A chain stays flat while the operator does not change, and thus a.or_(b).or_(c) gives (a OR b OR c). To make a different group, nest the calls. a.or_(b.or_(c)) gives (a OR (b OR c)), because the inner group is an operand and it writes its own brackets.

The group writes the brackets. The statement renderer does not. WHERE joins its conditions with a plain AND, and each group arrives complete. This keeps the conditions of a table when a search runs on top of them. The query says role = 'admin' AND (a OR b). It does not say role = 'admin' AND a OR b, which means (role = 'admin' AND a) OR b, because AND binds more tightly than OR.

Structs§

ConditionGroup
Conditions that one logical operator joins, written as a single group in brackets. To make a group, call or_ or and_, or use the or_ and and_ methods on a column or an identifier.

Functions§

and_
Joins two conditions with AND: (lhs AND rhs).
or_
Joins two conditions with OR: (lhs OR rhs).