cake/select
A DSL to build SELECT
queries.
Types
Functions
pub fn alias(
value vl: SelectValue,
alias als: String,
) -> SelectValue
Creates an alias off a String
.
pub fn all(query qry: Select) -> Select
Sets the kind of the Select
query to
return duplicates which is the default.
pub fn comment(
query qry: Select,
comment cmmnt: String,
) -> Select
Appends a Comment
to the Select
query.
pub fn distinct(query qry: Select) -> Select
Sets the kind of the Select
query to
return distinct rows only.
pub fn epilog(query qry: Select, epilog eplg: String) -> Select
Appends an Epilog
to the Select
query.
pub fn fragment(fragment frgmt: Fragment) -> SelectValue
Creates a SelectFragment
off a Fragment
.
pub fn from_sub_query(
query qry: Select,
sub_query sb_qry: Query,
alias als: String,
) -> Select
Sets the FROM
clause of the Select
query to an aliased sub-query.
pub fn from_table(
query qry: Select,
name tbl_nm: String,
) -> Select
Sets the FROM
clause of the Select
query to a table name.
pub fn get_comment(query qry: Select) -> Comment
Gets the Comment
from the Select
query.
pub fn get_epilog(query qry: Select) -> Epilog
Gets the Epilog
from the Select
query.
pub fn get_group_by(query qry: Select) -> GroupBy
Gets GroupBy
in the Select
query.
pub fn get_having(query qry: Select) -> Where
GetsHAVING
in the Select
query.
See function having
on details why this returns a Where
.
pub fn get_kind(
query qry: Select,
kind knd: SelectKind,
) -> Select
Gets the kind of the Select
query.
pub fn get_order_by(query qry: Select) -> OrderBy
Gets the OrderBy
from the Select
query.
pub fn get_select(query qry: Select) -> Selects
Gets the SelectValue
s of the Select
query.
pub fn group_by(
query qry: Select,
group_by grpb: String,
) -> Select
Sets or appends GroupBy
a single into an existing GroupBy
.
pub fn group_bys(
query qry: Select,
group_bys grpbs: List(String),
) -> Select
Sets or appends a list of GroupBy
into an existing GroupBy
.
pub fn having(query qry: Select, having whr: Where) -> Select
Sets an AndWhere
or appends into an existing AndWhere
.
- If the outermost
Where
is anAndWhere
, the newWhere
is appended to the list withinAndWhere
. - If the query does not have a
Where
clause, the givenWhere
is set instead. - If the outermost
Where
is any other kind ofWhere
, this and the current outermostWhere
are wrapped in anAndWhere
.
NOTICE: HAVING
allows to specify constraints much like WHERE
, but
filters the results after GROUP BY
is applied instead of before. Because
HAVING
uses the same semantics as WHERE
, it
takes a Where
.
pub fn joins(query qry: Select, joins jns: List(Join)) -> Select
Adds Join
s to the Select
query.
pub fn limit(query qry: Select, limit lmt: Int) -> Select
Sets a Limit
in the Select
query.
pub fn no_comment(query qry: Select) -> Select
Removes the Comment
from the Select
query.
pub fn no_epilog(query qry: Select) -> Select
Removes the Epilog
from the Select
query.
pub fn no_from(query qry: Select) -> Select
Removes the FROM
clause of the Select
query.
pub fn no_group_by(query qry: Select) -> Select
Removes GroupBy
from the Select
query.
pub fn no_order_by(query qry: Select) -> Select
Removes the OrderBy
from the Select
query.
pub fn offset(query qry: Select, offst offst: Int) -> Select
Sets an Offset
in the Select
query.
pub fn or_having(query qry: Select, having whr: Where) -> Select
Sets an OrWhere
or appends into an existing OrWhere
.
- If the outermost
Where
is anOrWhere
, the newWhere
is appended to the list withinOrWhere
. - If the query does not have a
Where
clause, the givenWhere
is set instead. - If the outermost
Where
is any other kind ofWhere
, this and the current outermostWhere
are wrapped in anOrWhere
.
See function having
on details why this takes a Where
.
pub fn or_where(query qry: Select, where whr: Where) -> Select
Sets an OrWhere
or appends into an existing OrWhere
.
- If the outermost
Where
is anOrWhere
, the newWhere
is appended to the list withinOrWhere
. - If the query does not have a
Where
clause, the givenWhere
is set instead. - If the outermost
Where
is any other kind ofWhere
, this and the current outermostWhere
are wrapped in anOrWhere
.
pub fn order_by(
query qry: Select,
by ordb: String,
direction dir: Direction,
) -> Select
Creates or appends an OrderBy
a column with a direction.
The direction can either ASC
or DESC
.
pub fn order_by_asc(query qry: Select, by ordb: String) -> Select
Creates or appends an ascending OrderBy
.
pub fn order_by_asc_nulls_first(
query qry: Select,
by ordb: String,
) -> Select
Creates or appends an ascending OrderBy
with NULLS FIRST
.
NOTICE: MariaDB/MySQL do not support NULLS FIRST
out of the box.
pub fn order_by_asc_nulls_last(
query qry: Select,
by ordb: String,
) -> Select
Creates or appends an ascending OrderBy
with NULLS LAST
.
NOTICE: MariaDB/MySQL do not support NULLS LAST
out of the box.
pub fn order_by_desc(
query qry: Select,
by ordb: String,
) -> Select
Creates or appends a descending OrderBy
.
pub fn order_by_desc_nulls_first(
query qry: Select,
by ordb: String,
) -> Select
Creates or appends a descending order with NULLS FIRST
.
NOTICE: MariaDB/MySQL do not support NULLS FIRST
out of the box.
pub fn order_by_desc_nulls_last(
query qry: Select,
by ordb: String,
) -> Select
Creates or appends a descending OrderBy
with NULLS LAST
.
NOTICE: MariaDB/MySQL do not support NULLS LAST
out of the box.
pub fn replace_group_by(
query qry: Select,
group_by grpb: String,
) -> Select
Replaces GroupBy
with a single GroupBy
.
pub fn replace_group_bys(
query qry: Select,
group_bys grpbs: List(String),
) -> Select
Replaces GroupBy
with a list of GroupBy
s.
pub fn replace_having(
query qry: Select,
having whr: Where,
) -> Select
Replaces HAVING
in the Select
query.
See function having
on details why this takes a Where
.
pub fn replace_join(query qry: Select, join jn: Join) -> Select
Replaces any Join
s of the Select
query with a signle Join
.
pub fn replace_joins(
query qry: Select,
joins jns: List(Join),
) -> Select
Replaces any Join
s of the Select
query with the given Join
s.
pub fn replace_order_by(
query qry: Select,
by ordb: String,
direction dir: Direction,
) -> Select
Replaces the OrderBy
a column with a direction.
pub fn replace_order_by_asc(
query qry: Select,
by ordb: String,
) -> Select
Replaces the OrderBy
a single ascending OrderBy
.
pub fn replace_order_by_asc_nulls_first(
query qry: Select,
by ordb: String,
) -> Select
Replaces the OrderBy
a single ascending OrderBy
with NULLS FIRST
.
NOTICE: MariaDB/MySQL do not support NULLS FIRST
out of the box.
pub fn replace_order_by_asc_nulls_last(
query qry: Select,
by ordb: String,
) -> Select
Replaces the OrderBy
a single ascending OrderBy
with NULLS LAST
.
NOTICE: MariaDB/MySQL do not support NULLS LAST
out of the box.
pub fn replace_order_by_desc(
query qry: Select,
by ordb: String,
) -> Select
Replaces the OrderBy
a single descending order.
pub fn replace_order_by_desc_nulls_first(
query qry: Select,
by ordb: String,
) -> Select
Replaces the OrderBy
a single descending order with NULLS FIRST
.
NOTICE: MariaDB/MySQL do not support NULLS FIRST
out of the box.
pub fn replace_order_by_desc_nulls_last(
query qry: Select,
by ordb: String,
) -> Select
Replaces the OrderBy
a single descending OrderBy
with NULLS LAST
.
NOTICE: MariaDB/MySQL do not support NULLS LAST
out of the box.
pub fn replace_select(
query qry: Select,
select_value sv: SelectValue,
) -> Select
Add a SelectValue
s to the Select
query.
If the query already has any SelectValue
s, they are replaced.
pub fn replace_selects(
query qry: Select,
select_values svs: List(SelectValue),
) -> Select
Adds SelectValue
s to the Select
query.
If the query already has any SelectValue
s, they are replaced.
pub fn replace_where(
query qry: Select,
where whr: Where,
) -> Select
Replaces the Where
in the Select
query.
pub fn select(
query qry: Select,
select_value sv: SelectValue,
) -> Select
Add a SelectValue
to the Select
query.
If the query already has any SelectValue
s, the new one is appended.
pub fn selects(
query qry: Select,
select_values svs: List(SelectValue),
) -> Select
Adds SelectValue
s to the Select
query.
If the query already has any SelectValue
s, the new ones are appended.
pub fn where(query qry: Select, where whr: Where) -> Select
Sets an AndWhere
or appends into an existing AndWhere
.
- If the outermost
Where
is anAndWhere
, the newWhere
is appended to the list withinAndWhere
. - If the query does not have a
Where
clause, the givenWhere
is set instead. - If the outermost
Where
is any other kind ofWhere
, this and the current outermostWhere
are wrapped in anAndWhere
.
pub fn xor_having(query qry: Select, having whr: Where) -> Select
Sets an XorWhere
or appends into an existing XorWhere
.
- If the outermost
Where
is anXorWhere
, the newWhere
is appended to the list withinXorWhere
. - If the query does not have a
Where
clause, the givenWhere
is set instead. - If the outermost
Where
is any other kind ofWhere
, this and the current outermostWhere
are wrapped in anXorWhere
.
See function having
on details why this takes a Where
.
NOTICE: This operator does not exist in Postgres or SQLite,
and Cake generates equivalent SQL using OR
and AND
and NOT
.
This operator exists in MariaDB/MySQL.
pub fn xor_where(query qry: Select, where whr: Where) -> Select
Sets an XorWhere
or appends into an existing XorWhere
.
- If the outermost
Where
is anXorWhere
, the newWhere
is appended to the list withinXorWhere
. - If the query does not have a
Where
clause, the givenWhere
is set instead. - If the outermost
Where
is any other kind ofWhere
, this and the current outermostWhere
are wrapped in anXorWhere
.
NOTICE: This operator does not exist in Postgres or SQLite,
and Cake generates equivalent SQL using OR
and AND
and NOT
.
This operator exists in MariaDB/MySQL.