cake/where
Used to build WHERE clauses for SQL queries.
Where clauses are used to filter rows in a table.
Also used to build HAVING clauses for SQL queries, because they work the
same way as WHERE clauses, but are used to filter rows after GROUP BY
has been applied.
Compatibility
- 🪶SQLite does not support
ANY,ALLandSIMILAR TO.
Types
pub type WhereValue =
@internal WhereValue
Values
pub fn between(
value_a value_a: WhereValue,
value_b value_b: WhereValue,
value_c value_c: WhereValue,
) -> Where
Creates a WHERE clause that checks if a WhereValue A is between two
WhereValues B and C.
pub fn date(value value: calendar.Date) -> WhereValue
Creates a WhereValue from a calendar.Date.
pub fn eq(
value_a value_a: WhereValue,
value_b value_b: WhereValue,
) -> Where
Creates a WHERE clause that checks if a WhereValue equals another
WhereValue.
pub fn eq_all_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue matches all
in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn eq_any_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue matches any
in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn exists_in_query(sub_query query: ReadQuery) -> Where
Creates a WHERE clause that checks if it exists in a sub-query.
pub fn false() -> WhereValue
Creates a FALSE WhereValue.
Notice: You probably want to use where.is_false() instead.
pub fn fragment_value(fragment fragment: Fragment) -> WhereValue
Creates a WhereValue from a Fragment.
pub fn gt(
value_a value_a: WhereValue,
value_b value_b: WhereValue,
) -> Where
Creates a WHERE clause that checks if a WhereValue is greater than
another WhereValue.
pub fn gt_all_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is greater than all
in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn gt_any_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is greater than any
in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn gte(
value_a value_a: WhereValue,
value_b value_b: WhereValue,
) -> Where
Creates a WHERE clause that checks if a WhereValue is greater or equal
to another WhereValue.
pub fn gte_all_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is greater or equal
to all in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn gte_any_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is greater or equal
to any in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn ilike(
value value: WhereValue,
pattern pattern: String,
) -> Where
Creates a WHERE clause that checks if a WhereValue matches a pattern.
ilike is the same as like but case-insensitive.
pub fn in(
value value: WhereValue,
values values: List(WhereValue),
) -> Where
Creates a WHERE clause that checks if a WhereValue is in a list of
WhereValues.
pub fn in_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is IN a sub-query.
NOTICE: Usually the sub-query must return a single column.
pub fn is_bool(value value: WhereValue, bool bool: Bool) -> Where
Creates a WHERE clause that checks if a WhereValue matches a Bool.
pub fn is_false(value value: WhereValue) -> Where
Creates a WHERE clause that checks if a WhereValue is False.
pub fn is_not_bool(
value value: WhereValue,
bool bool: Bool,
) -> Where
Creates a WHERE clause that checks if a WhereValue does not match a
Bool.
pub fn is_not_null(value value: WhereValue) -> Where
Creates a WHERE clause that checks if a WhereValue is not SQL NULL.
pub fn is_null(value value: WhereValue) -> Where
Creates a WHERE clause that checks if a WhereValue is SQL NULL.
pub fn is_true(value value: WhereValue) -> Where
Creates a WHERE clause that checks if a WhereValue is True.
pub fn like(
value value: WhereValue,
pattern pattern: String,
) -> Where
Creates a WHERE clause that checks if a WhereValue matches a pattern.
The pattern can contain for example the following wildcards:
%matches any sequence of characters._matches any single character.
pub fn lt(
value_a value_a: WhereValue,
value_b value_b: WhereValue,
) -> Where
Creates a WHERE clause that checks if a WhereValue lower than another
WhereValue.
pub fn lt_all_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is lower than all
in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn lt_any_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is lower than an any
in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn lte(
value_a value_a: WhereValue,
value_b value_b: WhereValue,
) -> Where
Creates a WHERE clause that checks if a WhereValue lower or equal to
another WhereValue.
pub fn lte_all_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is lower or equal to
all in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn lte_any_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is lower or equal to
any in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn neq(
value_a value_a: WhereValue,
value_b value_b: WhereValue,
) -> Where
Creates a WHERE clause that checks if a WhereValue is not equal to
another WhereValue.
pub fn neq_all_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is not equal to all
in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn neq_any_query(
value value: WhereValue,
sub_query query: ReadQuery,
) -> Where
Creates a WHERE clause that checks if a WhereValue is not equal to any
in a sub-query.
NOTICE: Not supported by 🪶SQLite.
pub fn similar_to(
value value: WhereValue,
to pattern: String,
escape_with escape_char: String,
) -> Where
Creates a WHERE clause that checks if a WhereValue is similar to a
pattern.
NOTICE: Not supported by 🪶SQLite.
pub fn sub_query(query query: ReadQuery) -> WhereValue
Creates a WhereValue off a ReadQuery.
NOTICE: Usually the sub-query must return a single column.
pub fn true() -> WhereValue
Creates a TRUE WhereValue.
Notice: You probably want to use where.is_true() instead.
pub fn xor(wheres wheres: List(Where)) -> Where
Logical XOR of multiple Wheres.
Returns TRUE when exactly one condition is true.
Unlike xor_parity, which returns TRUE for any odd number of true
conditions, xor is stricter: two or more true conditions yield FALSE.
| Number of conditions true | Result |
|---|---|
| 0 | FALSE |
| 1 | TRUE |
| 2 | FALSE |
| 3 | FALSE |
| 4 | FALSE |
pub fn xor_parity(wheres wheres: List(Where)) -> Where
Logical XOR of multiple Wheres using left-associative binary XOR.
Unlike xor, which returns TRUE when exactly one condition is true,
xor_parity returns TRUE when an odd number of conditions are true —
matching the behaviour of MySQL’s and MariaDB’s native XOR operator.
| Number of conditions true | Result |
|---|---|
| 0 | FALSE |
| 1 | TRUE |
| 2 | FALSE |
| 3 | TRUE |
| 4 | FALSE |
NULL handling: if any predicate evaluates to NULL, the entire
expression evaluates to NULL, which a WHERE clause treats as no
match (NULL-poisoning). This is consistent across all adapters:
- 🐘PostgreSQL / 🪶SQLite emulate parity via integer arithmetic; a NULL predicate propagates as NULL through the sum and modulo.
- 🦭MariaDB / 🐬MySQL use native
XOR, whereNULL XOR anything = NULL.
For adapters 🦭MariaDB or 🐬MySQL the native XOR syntax will be
utilized under the hood.