SqlAnd
- class SqlAnd(*terms)
Combines terms with AND. Created via
SQL.and_expr(*terms). Inherits from SqlObj (viaSqlBoolOp).- Parameters:
terms – Zero or more initial
SqlTermorSqlBoolOpinstances.
- add(expr, op=None, value=None)
Add a term. If expr is a string with op and value, it is wrapped in a SqlTerm. See SqlTerm for the full list of supported parameter variants.
- Parameters:
expr – A string (column name or literal expression),
SqlTerm, orSqlBoolOp.op – Optional operator string.
value – Optional comparison value.
expr = (SQL.and_expr() .add('status', '=', 'active') .add('age', '>', 18)) # status = %s # AND age > %s # args: ['active', 18] expr.add(SQL.or_expr().add('a', '=', 1).add('b', '=', 2)) # status = %s # AND age > %s # AND (a = %s # OR b = %s) # args: ['active', 18, 1, 2]
- extend(other)
Append all terms from another boolean expression.
- Parameters:
other – A
SqlAndorSqlOrinstance whose terms are appended.
expr1 = SQL.and_expr().add('a', '=', 1) expr2 = SQL.and_expr().add('b', '=', 2) expr1.extend(expr2) # a = %s # AND b = %s # args: [1, 2]
- is_empty()
Returns
Trueif all terms are empty.- Return type:
bool
- has_sql()
Returns
Trueif any term produces SQL output.- Return type:
bool
SqlOr
- class SqlOr(*terms)
Combines terms with OR. Created via
SQL.or_expr(*terms). Same interface asSqlAnd. Inherits from SqlObj (viaSqlBoolOp).- Parameters:
terms – Zero or more initial
SqlTermorSqlBoolOpinstances.
expr = (SQL.or_expr() .add('role', '=', 'admin') .add('role', '=', 'superuser')) # role = %s # OR role = %s # args: ['admin', 'superuser']