cake/select
A DSL to build SELECT queries.
Types
Defines the direction of an OrderBy.
pub type Direction {
Asc
Desc
}
Constructors
-
Asc -
Desc
pub type OrderByDirection =
@internal OrderByDirection
pub type SelectKind =
@internal SelectKind
pub type SelectValue =
@internal SelectValue
Values
pub fn alias(
value value: SelectValue,
alias alias: String,
) -> SelectValue
Creates an alias SelectValue from String.
pub fn all(select select: Select) -> Select
Sets the kind of the Select query to
return duplicates which is the default.
pub fn comment(
select select: Select,
comment comment: String,
) -> Select
Appends a Comment to the Select query.
pub fn date(v value: calendar.Date) -> SelectValue
Creates a SelectValue from a calendar.Date.
pub fn distinct(select select: Select) -> Select
Sets the kind of the Select query to
return distinct rows only.
pub fn epilog(
select select: Select,
epilog epilog: String,
) -> Select
Appends an Epilog to the Select query.
pub fn fragment(fragment fragment: Fragment) -> SelectValue
Creates a SelectFragment off a Fragment.
pub fn from_query(
select select: Select,
sub_query sub_query: ReadQuery,
alias alias: String,
) -> Select
Sets the FROM clause of the Select query to an aliased sub-query.
pub fn from_table(
select select: Select,
name table_name: String,
) -> Select
Sets the FROM clause of the Select query to a table name.
pub fn get_having(select select: Select) -> Where
Gets HAVING in the Select query.
See function having on details why this returns a Where.
pub fn get_kind(select select: Select) -> SelectKind
Gets the kind of the Select query.
pub fn group_by(
select select: Select,
group_by group_by: String,
) -> Select
Sets or appends GroupBy a single into an existing GroupBy.
pub fn group_bys(
select select: Select,
group_bys group_bys: List(String),
) -> Select
Sets or appends a list of GroupBy into an existing GroupBy.
pub fn having(
select select: Select,
having where: Where,
) -> Select
Sets an AndWhere or appends into an existing AndWhere.
- If the outermost
Whereis anAndWhere, the newWhereis appended to the list withinAndWhere. - If the query does not have a
Whereclause, the givenWhereis set instead. - If the outermost
Whereis any other kind ofWhere, this and the current outermostWhereare 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(
select select: Select,
joins joins: List(Join),
) -> Select
Adds Joins to the Select query.
pub fn offset(
select select: Select,
offset offset: Int,
) -> Select
Sets an Offset in the Select query.
pub fn or_having(
select select: Select,
having where: Where,
) -> Select
Sets an OrWhere or appends into an existing OrWhere.
- If the outermost
Whereis anOrWhere, the newWhereis appended to the list withinOrWhere. - If the query does not have a
Whereclause, the givenWhereis set instead. - If the outermost
Whereis any other kind ofWhere, this and the current outermostWhereare wrapped in anOrWhere.
See function having on details why this takes a Where.
pub fn or_where(
select select: Select,
where where: Where,
) -> Select
Sets an OrWhere or appends into an existing OrWhere.
- If the outermost
Whereis anOrWhere, the newWhereis appended to the list withinOrWhere. - If the query does not have a
Whereclause, the givenWhereis set instead. - If the outermost
Whereis any other kind ofWhere, this and the current outermostWhereare wrapped in anOrWhere.
pub fn order_by(
select select: Select,
order_by order_by: String,
direction direction: Direction,
) -> Select
Creates or appends an OrderBy a column with a direction.
The direction can either ASC or DESC.
pub fn order_by_asc(
select select: Select,
order_by order_by: String,
) -> Select
Creates or appends an ascending OrderBy.
pub fn order_by_asc_nulls_first(
select select: Select,
order_by order_by: String,
) -> Select
Creates or appends an ascending OrderBy with NULLS FIRST.
NOTICE: 🦭MariaDB and 🐬MySQL do not support NULLS FIRST out of the box.
pub fn order_by_asc_nulls_last(
select select: Select,
order_by order_by: String,
) -> Select
Creates or appends an ascending OrderBy with NULLS LAST.
NOTICE: 🦭MariaDB and 🐬MySQL do not support NULLS LAST out of the box.
pub fn order_by_desc(
select select: Select,
order_by order_by: String,
) -> Select
Creates or appends a descending OrderBy.
pub fn order_by_desc_nulls_first(
select select: Select,
order_by order_by: String,
) -> Select
Creates or appends a descending order with NULLS FIRST.
NOTICE: 🦭MariaDB and 🐬MySQL do not support NULLS FIRST out of the box.
pub fn order_by_desc_nulls_last(
select select: Select,
order_by order_by: String,
) -> Select
Creates or appends a descending OrderBy with NULLS LAST.
NOTICE: 🦭MariaDB and 🐬MySQL do not support NULLS LAST out of the box.
pub fn replace_group_by(
select select: Select,
group_by group_by: String,
) -> Select
Replaces GroupBy with a single GroupBy.
pub fn replace_group_bys(
select select: Select,
group_bys group_bys: List(String),
) -> Select
Replaces GroupBy with a list of GroupBys.
pub fn replace_having(
select select: Select,
having where: Where,
) -> Select
Replaces HAVING in the Select query.
See function having on details why this takes a Where.
pub fn replace_join(
select select: Select,
join join: Join,
) -> Select
Replaces any Joins of the Select query with a single Join.
pub fn replace_joins(
select select: Select,
joins joins: List(Join),
) -> Select
Replaces any Joins of the Select query with the given Joins.
pub fn replace_order_by(
select select: Select,
order_by order_by: String,
direction direction: Direction,
) -> Select
Replaces the OrderBy a column with a direction.
pub fn replace_order_by_asc(
select select: Select,
order_by order_by: String,
) -> Select
Replaces the OrderBy a single ascending OrderBy.
pub fn replace_order_by_asc_nulls_first(
select select: Select,
order_by order_by: String,
) -> Select
Replaces the OrderBy a single ascending OrderBy with NULLS FIRST.
NOTICE: 🦭MariaDB and 🐬MySQL do not support NULLS FIRST out of the box.
pub fn replace_order_by_asc_nulls_last(
select select: Select,
order_by order_by: String,
) -> Select
Replaces the OrderBy a single ascending OrderBy with NULLS LAST.
NOTICE: 🦭MariaDB and 🐬MySQL do not support NULLS LAST out of the box.
pub fn replace_order_by_desc(
select select: Select,
order_by order_by: String,
) -> Select
Replaces the OrderBy a single descending order.
pub fn replace_order_by_desc_nulls_first(
select select: Select,
order_by order_by: String,
) -> Select
Replaces the OrderBy a single descending order with NULLS FIRST.
NOTICE: 🦭MariaDB and 🐬MySQL do not support NULLS FIRST out of the box.
pub fn replace_order_by_desc_nulls_last(
select select: Select,
order_by order_by: String,
) -> Select
Replaces the OrderBy a single descending OrderBy with NULLS LAST.
NOTICE: 🦭MariaDB and 🐬MySQL do not support NULLS LAST out of the box.
pub fn replace_select(
select select: Select,
select_value select_value: SelectValue,
) -> Select
Add a SelectValue to the Select query.
If the query already has any SelectValues, they are replaced.
pub fn replace_select_col(
select select: Select,
name name: String,
) -> Select
Add a column name to the Select query as a SelectValue.
If the query already has any SelectValues, they are replaced.
pub fn replace_select_cols(
select select: Select,
select_cols columns: List(String),
) -> Select
Adds many column names as SelectValues to the Select query.
If the query already has any SelectValues, the new ones are replaced.
pub fn replace_selects(
select select: Select,
select_values select_values: List(SelectValue),
) -> Select
Adds many SelectValues to the Select query.
If the query already has any SelectValues, they are replaced.
If no SelectValues are provided, the query is returned as-is.
pub fn replace_where(
select select: Select,
where where: Where,
) -> Select
Replaces the Where in the Select query.
pub fn select(
select select: Select,
select_value select_value: SelectValue,
) -> Select
Add a SelectValue to the Select query.
If the query already has any SelectValues, the new one is appended.
pub fn select_col(
select select: Select,
name name: String,
) -> Select
Add a column name to the Select query as a SelectValue.
If the query already has any SelectValues, the new one is appended.
pub fn select_cols(
select select: Select,
select_cols columns: List(String),
) -> Select
Adds many column names as SelectValues to the Select query.
If the query already has any SelectValues, the new ones are appended.
pub fn selects(
select select: Select,
select_values select_values: List(SelectValue),
) -> Select
Adds many SelectValues to the Select query.
If the query already has any SelectValues, the new ones are appended.
pub fn where(select select: Select, where where: Where) -> Select
Sets an AndWhere or appends into an existing AndWhere.
- If the outermost
Whereis anAndWhere, the newWhereis appended to the list withinAndWhere. - If the query does not have a
Whereclause, the givenWhereis set instead. - If the outermost
Whereis any other kind ofWhere, this and the current outermostWhereare wrapped in anAndWhere.
pub fn xor_having(
select select: Select,
having where: Where,
) -> Select
Sets an XorWhere or appends into an existing XorWhere.
- If the outermost
Whereis anXorWhere, the newWhereis appended to the list withinXorWhere. - If the query does not have a
Whereclause, the givenWhereis set instead. - If the outermost
Whereis any other kind ofWhere, this and the current outermostWhereare wrapped in anXorWhere.
See function having on details why this takes a Where.
NOTICE: This operator does not exist in 🐘PostgreSQL or 🪶SQLite,
and Cake generates equivalent SQL using OR and AND and NOT.
This operator exists in 🦭MariaDB and 🐬MySQL.
pub fn xor_where(
select select: Select,
where where: Where,
) -> Select
Sets an XorWhere or appends into an existing XorWhere.
- If the outermost
Whereis anXorWhere, the newWhereis appended to the list withinXorWhere. - If the query does not have a
Whereclause, the givenWhereis set instead. - If the outermost
Whereis any other kind ofWhere, this and the current outermostWhereare wrapped in anXorWhere.
NOTICE: This operator does not exist in 🐘PostgreSQL or 🪶SQLite,
and Cake generates equivalent SQL using OR and AND and NOT.
This operator exists in 🦭MariaDB and 🐬MySQL.