Current section

Files

Jump to
cake src cake@where.erl
Raw

src/cake@where.erl

-module(cake@where).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/cake/where.gleam").
-export([col/1, float/1, int/1, string/1, null/0, date/1, true/0, false/0, bool/1, sub_query/1, fragment_value/1, 'not'/1, 'and'/1, 'or'/1, 'xor'/1, xor_parity/1, none/0, is_bool/2, is_not_bool/2, is_false/1, is_true/1, is_null/1, is_not_null/1, eq/2, lt/2, lte/2, gt/2, gte/2, neq/2, eq_any_query/2, lt_any_query/2, lte_any_query/2, gt_any_query/2, gte_any_query/2, neq_any_query/2, eq_all_query/2, lt_all_query/2, lte_all_query/2, gt_all_query/2, gte_all_query/2, neq_all_query/2, in_query/2, in/2, exists_in_query/1, between/3, like/2, ilike/2, similar_to/3, fragment/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Used to build `WHERE` clauses for SQL queries.\n"
"\n"
" Where clauses are used to filter rows in a table.\n"
"\n"
" Also used to build `HAVING` clauses for SQL queries, because they work the\n"
" same way as `WHERE` clauses, but are used to filter rows after `GROUP BY`\n"
" has been applied.\n"
"\n"
" ## Compatibility\n"
"\n"
" - 🪶SQLite does not support `ANY`, `ALL` and `SIMILAR TO`.\n"
"\n"
).
-file("src/cake/where.gleam", 49).
?DOC(" Creates a `WhereValue` from a column name `String`.\n").
-spec col(binary()) -> cake@internal@read_query:where_value().
col(Name) ->
{where_column_value, Name}.
-file("src/cake/where.gleam", 55).
?DOC(" Creates a `WhereValue` from a `Float`.\n").
-spec float(float()) -> cake@internal@read_query:where_value().
float(Value) ->
_pipe = {float_param, Value},
{where_param_value, _pipe}.
-file("src/cake/where.gleam", 61).
?DOC(" Creates a `WhereValue` from an `Int`.\n").
-spec int(integer()) -> cake@internal@read_query:where_value().
int(Value) ->
_pipe = {int_param, Value},
{where_param_value, _pipe}.
-file("src/cake/where.gleam", 67).
?DOC(" Creates a `WhereValue` from a `String`.\n").
-spec string(binary()) -> cake@internal@read_query:where_value().
string(Value) ->
_pipe = {string_param, Value},
{where_param_value, _pipe}.
-file("src/cake/where.gleam", 73).
?DOC(" Creates a `NULL` `WhereValue`.\n").
-spec null() -> cake@internal@read_query:where_value().
null() ->
_pipe = null_param,
{where_param_value, _pipe}.
-file("src/cake/where.gleam", 79).
?DOC(" Creates a `WhereValue` from a `calendar.Date`.\n").
-spec date(gleam@time@calendar:date()) -> cake@internal@read_query:where_value().
date(Value) ->
_pipe = {date_param, Value},
{where_param_value, _pipe}.
-file("src/cake/where.gleam", 87).
?DOC(
" Creates a `TRUE` `WhereValue`.\n"
"\n"
" Notice: You probably want to use `where.is_true()` instead.\n"
).
-spec true() -> cake@internal@read_query:where_value().
true() ->
_pipe = true,
_pipe@1 = {bool_param, _pipe},
{where_param_value, _pipe@1}.
-file("src/cake/where.gleam", 95).
?DOC(
" Creates a `FALSE` `WhereValue`.\n"
"\n"
" Notice: You probably want to use `where.is_false()` instead.\n"
).
-spec false() -> cake@internal@read_query:where_value().
false() ->
_pipe = false,
_pipe@1 = {bool_param, _pipe},
{where_param_value, _pipe@1}.
-file("src/cake/where.gleam", 101).
?DOC(" Creates a `WhereValue` from a `Bool`.\n").
-spec bool(boolean()) -> cake@internal@read_query:where_value().
bool(Value) ->
_pipe = {bool_param, Value},
{where_param_value, _pipe}.
-file("src/cake/where.gleam", 109).
?DOC(
" Creates a `WhereValue` off a `ReadQuery`.\n"
"\n"
" NOTICE: Usually the sub-query must return a single column.\n"
).
-spec sub_query(cake@internal@read_query:read_query()) -> cake@internal@read_query:where_value().
sub_query(Query) ->
{where_sub_query_value, Query}.
-file("src/cake/where.gleam", 115).
?DOC(" Creates a `WhereValue` from a `Fragment`.\n").
-spec fragment_value(cake@internal@read_query:fragment()) -> cake@internal@read_query:where_value().
fragment_value(Fragment) ->
{where_fragment_value, Fragment}.
-file("src/cake/where.gleam", 125).
?DOC(" Negates a `Where`.\n").
-spec 'not'(cake@internal@read_query:where()) -> cake@internal@read_query:where().
'not'(Where) ->
{not_where, Where}.
-file("src/cake/where.gleam", 131).
?DOC(" Logical AND of multiple `Where`s.\n").
-spec 'and'(list(cake@internal@read_query:where())) -> cake@internal@read_query:where().
'and'(Wheres) ->
{and_where, Wheres}.
-file("src/cake/where.gleam", 137).
?DOC(" Logical OR of multiple `Where`s.\n").
-spec 'or'(list(cake@internal@read_query:where())) -> cake@internal@read_query:where().
'or'(Wheres) ->
{or_where, Wheres}.
-file("src/cake/where.gleam", 156).
?DOC(
" Logical XOR of multiple `Where`s.\n"
"\n"
" Returns `TRUE` when **exactly one** condition is true.\n"
"\n"
" Unlike `xor_parity`, which returns `TRUE` for any **odd number** of true\n"
" conditions, `xor` is stricter: two or more true conditions yield `FALSE`.\n"
"\n"
" | Number of conditions true | Result |\n"
" |---------------------------|--------|\n"
" | 0 | FALSE |\n"
" | 1 | TRUE |\n"
" | 2 | FALSE |\n"
" | 3 | FALSE |\n"
" | 4 | FALSE |\n"
).
-spec 'xor'(list(cake@internal@read_query:where())) -> cake@internal@read_query:where().
'xor'(Wheres) ->
{xor_where, Wheres}.
-file("src/cake/where.gleam", 185).
?DOC(
" Logical XOR of multiple `Where`s using left-associative binary XOR.\n"
"\n"
" Unlike `xor`, which returns `TRUE` when _exactly one_ condition is true,\n"
" `xor_parity` returns `TRUE` when an **odd number** of conditions are true —\n"
" matching the behaviour of MySQL's and MariaDB's native `XOR` operator.\n"
"\n"
" | Number of conditions true | Result |\n"
" |---------------------------|--------|\n"
" | 0 | FALSE |\n"
" | 1 | TRUE |\n"
" | 2 | FALSE |\n"
" | 3 | TRUE |\n"
" | 4 | FALSE |\n"
"\n"
" **NULL handling:** if any predicate evaluates to `NULL`, the entire\n"
" expression evaluates to `NULL`, which a `WHERE` clause treats as no\n"
" match (NULL-poisoning). This is consistent across all adapters:\n"
"\n"
" - 🐘PostgreSQL / 🪶SQLite emulate parity via integer arithmetic;\n"
" a NULL predicate propagates as NULL through the sum and modulo.\n"
" - 🦭MariaDB / 🐬MySQL use native `XOR`, where `NULL XOR anything = NULL`.\n"
"\n"
" For adapters 🦭MariaDB or 🐬MySQL the native `XOR` syntax will be\n"
" utilized under the hood.\n"
).
-spec xor_parity(list(cake@internal@read_query:where())) -> cake@internal@read_query:where().
xor_parity(Wheres) ->
{xor_parity_where, Wheres}.
-file("src/cake/where.gleam", 191).
?DOC(" No where condition.\n").
-spec none() -> cake@internal@read_query:where().
none() ->
no_where.
-file("src/cake/where.gleam", 196).
?DOC(" Creates a `WHERE` clause that checks if a `WhereValue` matches a `Bool`.\n").
-spec is_bool(cake@internal@read_query:where_value(), boolean()) -> cake@internal@read_query:where().
is_bool(Value, Bool) ->
_pipe = Value,
{where_is_bool, _pipe, Bool}.
-file("src/cake/where.gleam", 202).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` does not match a\n"
" `Bool`.\n"
).
-spec is_not_bool(cake@internal@read_query:where_value(), boolean()) -> cake@internal@read_query:where().
is_not_bool(Value, Bool) ->
_pipe = Value,
{where_is_not_bool, _pipe, Bool}.
-file("src/cake/where.gleam", 207).
?DOC(" Creates a `WHERE` clause that checks if a `WhereValue` is `False`.\n").
-spec is_false(cake@internal@read_query:where_value()) -> cake@internal@read_query:where().
is_false(Value) ->
_pipe = Value,
{where_is_bool, _pipe, false}.
-file("src/cake/where.gleam", 212).
?DOC(" Creates a `WHERE` clause that checks if a `WhereValue` is `True`.\n").
-spec is_true(cake@internal@read_query:where_value()) -> cake@internal@read_query:where().
is_true(Value) ->
_pipe = Value,
{where_is_bool, _pipe, true}.
-file("src/cake/where.gleam", 218).
?DOC(" Creates a `WHERE` clause that checks if a `WhereValue` is SQL `NULL`.\n").
-spec is_null(cake@internal@read_query:where_value()) -> cake@internal@read_query:where().
is_null(Value) ->
{where_is_null, Value}.
-file("src/cake/where.gleam", 224).
?DOC(" Creates a `WHERE` clause that checks if a `WhereValue` is not SQL `NULL`.\n").
-spec is_not_null(cake@internal@read_query:where_value()) -> cake@internal@read_query:where().
is_not_null(Value) ->
{where_is_not_null, Value}.
-file("src/cake/where.gleam", 231).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` equals another\n"
" `WhereValue`.\n"
).
-spec eq(
cake@internal@read_query:where_value(),
cake@internal@read_query:where_value()
) -> cake@internal@read_query:where().
eq(Value_a, Value_b) ->
{where_comparison, Value_a, equal, Value_b}.
-file("src/cake/where.gleam", 238).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` lower than another\n"
" `WhereValue`.\n"
).
-spec lt(
cake@internal@read_query:where_value(),
cake@internal@read_query:where_value()
) -> cake@internal@read_query:where().
lt(Value_a, Value_b) ->
{where_comparison, Value_a, lower, Value_b}.
-file("src/cake/where.gleam", 245).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` lower or equal to\n"
" another `WhereValue`.\n"
).
-spec lte(
cake@internal@read_query:where_value(),
cake@internal@read_query:where_value()
) -> cake@internal@read_query:where().
lte(Value_a, Value_b) ->
{where_comparison, Value_a, lower_or_equal, Value_b}.
-file("src/cake/where.gleam", 252).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is greater than\n"
" another `WhereValue`.\n"
).
-spec gt(
cake@internal@read_query:where_value(),
cake@internal@read_query:where_value()
) -> cake@internal@read_query:where().
gt(Value_a, Value_b) ->
{where_comparison, Value_a, greater, Value_b}.
-file("src/cake/where.gleam", 259).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is greater or equal\n"
" to another `WhereValue`.\n"
).
-spec gte(
cake@internal@read_query:where_value(),
cake@internal@read_query:where_value()
) -> cake@internal@read_query:where().
gte(Value_a, Value_b) ->
{where_comparison, Value_a, greater_or_equal, Value_b}.
-file("src/cake/where.gleam", 266).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is not equal to\n"
" another `WhereValue`.\n"
).
-spec neq(
cake@internal@read_query:where_value(),
cake@internal@read_query:where_value()
) -> cake@internal@read_query:where().
neq(Value_a, Value_b) ->
{where_comparison, Value_a, unequal, Value_b}.
-file("src/cake/where.gleam", 275).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` matches any\n"
" in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec eq_any_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
eq_any_query(Value, Query) ->
{where_any_of_sub_query, Value, equal, Query}.
-file("src/cake/where.gleam", 287).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is lower than an any\n"
" in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec lt_any_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
lt_any_query(Value, Query) ->
{where_any_of_sub_query, Value, lower, Query}.
-file("src/cake/where.gleam", 299).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is lower or equal to\n"
" any in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec lte_any_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
lte_any_query(Value, Query) ->
{where_any_of_sub_query, Value, lower_or_equal, Query}.
-file("src/cake/where.gleam", 311).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is greater than any\n"
" in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec gt_any_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
gt_any_query(Value, Query) ->
{where_any_of_sub_query, Value, greater, Query}.
-file("src/cake/where.gleam", 323).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is greater or equal\n"
" to any in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec gte_any_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
gte_any_query(Value, Query) ->
{where_any_of_sub_query, Value, greater_or_equal, Query}.
-file("src/cake/where.gleam", 335).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is not equal to any\n"
" in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec neq_any_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
neq_any_query(Value, Query) ->
{where_any_of_sub_query, Value, unequal, Query}.
-file("src/cake/where.gleam", 347).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` matches all\n"
" in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec eq_all_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
eq_all_query(Value, Query) ->
{where_all_of_sub_query, Value, equal, Query}.
-file("src/cake/where.gleam", 359).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is lower than all\n"
" in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec lt_all_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
lt_all_query(Value, Query) ->
{where_all_of_sub_query, Value, lower, Query}.
-file("src/cake/where.gleam", 371).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is lower or equal to\n"
" all in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec lte_all_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
lte_all_query(Value, Query) ->
{where_all_of_sub_query, Value, lower_or_equal, Query}.
-file("src/cake/where.gleam", 383).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is greater than all\n"
" in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec gt_all_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
gt_all_query(Value, Query) ->
{where_all_of_sub_query, Value, greater, Query}.
-file("src/cake/where.gleam", 395).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is greater or equal\n"
" to all in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec gte_all_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
gte_all_query(Value, Query) ->
{where_all_of_sub_query, Value, greater_or_equal, Query}.
-file("src/cake/where.gleam", 407).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is not equal to all\n"
" in a sub-query.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec neq_all_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
neq_all_query(Value, Query) ->
{where_all_of_sub_query, Value, unequal, Query}.
-file("src/cake/where.gleam", 418).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is IN a sub-query.\n"
"\n"
" NOTICE: Usually the sub-query must return a single column.\n"
).
-spec in_query(
cake@internal@read_query:where_value(),
cake@internal@read_query:read_query()
) -> cake@internal@read_query:where().
in_query(Value, Query) ->
{where_in, Value, [{where_sub_query_value, Query}]}.
-file("src/cake/where.gleam", 425).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is in a list of\n"
" `WhereValue`s.\n"
).
-spec in(
cake@internal@read_query:where_value(),
list(cake@internal@read_query:where_value())
) -> cake@internal@read_query:where().
in(Value, Values) ->
{where_in, Value, Values}.
-file("src/cake/where.gleam", 431).
?DOC(" Creates a `WHERE` clause that checks if it exists in a sub-query.\n").
-spec exists_in_query(cake@internal@read_query:read_query()) -> cake@internal@read_query:where().
exists_in_query(Query) ->
{where_exists_in_sub_query, Query}.
-file("src/cake/where.gleam", 443).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` A is between two\n"
" `WhereValue`s B and C.\n"
).
-spec between(
cake@internal@read_query:where_value(),
cake@internal@read_query:where_value(),
cake@internal@read_query:where_value()
) -> cake@internal@read_query:where().
between(Value_a, Value_b, Value_c) ->
{where_between, Value_a, Value_b, Value_c}.
-file("src/cake/where.gleam", 457).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` matches a pattern.\n"
" The pattern can contain for example the following wildcards:\n"
"\n"
" - `%` matches any sequence of characters.\n"
" - `_` matches any single character.\n"
).
-spec like(cake@internal@read_query:where_value(), binary()) -> cake@internal@read_query:where().
like(Value, Pattern) ->
{where_like, Value, Pattern}.
-file("src/cake/where.gleam", 465).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` matches a pattern.\n"
"\n"
" `ilike` is the same as `like` but case-insensitive.\n"
).
-spec ilike(cake@internal@read_query:where_value(), binary()) -> cake@internal@read_query:where().
ilike(Value, Pattern) ->
{where_i_like, Value, Pattern}.
-file("src/cake/where.gleam", 474).
?DOC(
" Creates a `WHERE` clause that checks if a `WhereValue` is similar to a\n"
" pattern.\n"
"\n"
" NOTICE: Not supported by 🪶SQLite.\n"
).
-spec similar_to(cake@internal@read_query:where_value(), binary(), binary()) -> cake@internal@read_query:where().
similar_to(Value, Pattern, Escape_char) ->
{where_similar_to, Value, Pattern, Escape_char}.
-file("src/cake/where.gleam", 484).
?DOC(" Creates a `WhereFragment` from a `Fragment`.\n").
-spec fragment(cake@internal@read_query:fragment()) -> cake@internal@read_query:where().
fragment(Fragment) ->
{where_fragment, Fragment}.