cake/update

A DSL to build UPDATE queries.

Types

pub type Comment =
  @internal Comment
pub type Epilog =
  @internal Epilog
pub type From =
  @internal From
pub type Join =
  @internal Join
pub type Joins =
  @internal Joins
pub type ReadQuery =
  @internal ReadQuery
pub type Update(a) =
  @internal Update(a)
pub type UpdateSet =
  @internal UpdateSet
pub type UpdateSets =
  @internal UpdateSets
pub type UpdateTable =
  @internal UpdateTable
pub type Where =
  @internal Where
pub type WriteQuery(a) =
  @internal WriteQuery(a)

Values

pub fn comment(
  update update: Update(a),
  comment comment: String,
) -> Update(a)

Sets a Comment or appends into an existing Comment.

pub fn epilog(
  update update: Update(a),
  epilog epilog: String,
) -> Update(a)

Sets an Epilog or appends into an existing Epilog.

pub fn from_sub_query(
  update update: Update(a),
  query query: ReadQuery,
  alias alias: String,
) -> Update(a)

Sets the FROM clause of the Update query to an aliased sub-query.

pub fn from_table(
  update update: Update(a),
  name table_name: String,
) -> Update(a)

Sets the FROM clause of the Update query to a table name.

pub fn get_comment(update update: Update(a)) -> Comment

Gets the Comment of the Update query.

pub fn get_epilog(update update: Update(a)) -> Epilog

Gets the Epilog of the Update query.

pub fn get_from(update update: Update(a)) -> From

Gets the FROM clause of the Update query.

pub fn get_joins(update update: Update(a)) -> Joins

Gets the Joins of the Update query.

pub fn get_set(update update: Update(a)) -> List(UpdateSet)

Get the SETs of the Update query.

pub fn get_table(update update: Update(a)) -> UpdateTable

Get the table of the Update query.

pub fn get_where(update update: Update(a)) -> Where

Gets the Where of the Update query.

pub fn join(
  update update: Update(a),
  join join: Join,
) -> Update(a)

Adds a Join to the Update query.

NOTICE: On 🐘PostgreSQL and 🪶SQLite Joins are only allowed if the FROM clause is set as well.

pub fn joins(
  update update: Update(a),
  joins joins: List(Join),
) -> Update(a)

Adds Joins to the Update query.

NOTICE: On 🐘PostgreSQL and 🪶SQLite Joins are only allowed if the FROM clause is set as well.

pub fn new() -> Update(a)

Creates an empty Update query.

pub fn no_comment(update update: Update(a)) -> Update(a)

Removes the Comment from the Update query.

pub fn no_epilog(update update: Update(a)) -> Update(a)

Removes the Epilog from the Update query.

pub fn no_from(update update: Update(a)) -> Update(a)

Removes the FROM clause of the Update query.

pub fn no_join(update update: Update(a)) -> Update(a)

Removes any Joins from the Update query.

pub fn no_returning(update update: Update(a)) -> Update(a)

NOTICE: 🦭MariaDB and 🐬MySQL do not support RETURNING in UPDATE queries; they do support it in INSERT (and REPLACE) queries, however.

pub fn no_where(update update: Update(a)) -> Update(a)

Removes the Where from the Update query.

pub fn or_where(
  update update: Update(a),
  where where: Where,
) -> Update(a)

Sets an OrWhere or appends into an existing OrWhere.

  • If the outermost Where is an OrWhere, the new Where is appended to the list within OrWhere.
  • If the query does not have a Where clause, the given Where is set instead.
  • If the outermost Where is any other kind of Where, this and the current outermost Where are wrapped in an OrWhere.
pub fn replace_join(
  update update: Update(a),
  join join: Join,
) -> Update(a)

Replaces any Joins of the Update query with a single Join.

NOTICE: On 🐘PostgreSQL and 🪶SQLite Joins are only allowed if the FROM clause is set as well.

pub fn replace_joins(
  update update: Update(a),
  joins joins: List(Join),
) -> Update(a)

Replaces any Joins of the Update query with the given Joins.

NOTICE: On 🐘PostgreSQL and 🪶SQLite Joins are only allowed if the FROM clause is set as well.

pub fn replace_where(
  update update: Update(a),
  where where: Where,
) -> Update(a)

Replaces the Where in the Update query.

pub fn returning(
  update update: Update(a),
  returning returning: List(String),
) -> Update(a)

NOTICE: 🦭MariaDB and 🐬MySQL do not support RETURNING in UPDATE queries; they do support it in INSERT (and REPLACE) queries, however.

pub fn set(
  update update: Update(a),
  set set: UpdateSet,
) -> Update(a)

Sets or appends one column set in an Update query.

pub fn set_bool(
  column column: String,
  value value: Bool,
) -> UpdateSet

Sets a column to a Bool UpdateParamSet.

pub fn set_date(
  column column: String,
  date date: calendar.Date,
) -> UpdateSet

Sets a column to a calendar.Date UpdateParamSet.

pub fn set_expression(
  column column: String,
  expression expression: String,
) -> UpdateSet

Sets a column to an expression value.

pub fn set_false(column column: String) -> UpdateSet

Sets a column to a False UpdateParamSet.

pub fn set_float(
  column column: String,
  value value: Float,
) -> UpdateSet

Sets a column to a Float UpdateParamSet.

pub fn set_fragment(
  column column: String,
  value value: select.Fragment,
) -> UpdateSet

Sets a column to a fragment value with parameter binding.

Example

import cake/fragment as f
import cake/update as u

"org_id" |> u.set_fragment(f.prepared("$::uuid", [f.string("0000000000-0000-4000-a000-a00000000000")]))
pub fn set_int(
  column column: String,
  value value: Int,
) -> UpdateSet

Sets a column to a Int UpdateParamSet.

pub fn set_null(column column: String) -> UpdateSet

Sets a column to an SQL NULL UpdateParamSet.

pub fn set_replace(
  update update: Update(a),
  set set: UpdateSet,
) -> Update(a)

Sets or replaces one column set in an Update query.

pub fn set_string(
  column column: String,
  value value: String,
) -> UpdateSet

Sets a column to a string UpdateParamSet.

pub fn set_sub_query(
  column column: String,
  query query: ReadQuery,
) -> UpdateSet

Sets a column to a sub-query value.

pub fn set_true(column column: String) -> UpdateSet

Sets a column to a True UpdateParamSet.

pub fn sets(
  update update: Update(a),
  set sets: List(UpdateSet),
) -> Update(a)

Sets or appends many column sets in an Update query.

pub fn sets_expression(
  columns columns: List(String),
  expression expression: String,
) -> UpdateSet

Sets many columns to an expression value.

NOTICE: the expression must return an equal count of columns.

pub fn sets_replace(
  update update: Update(a),
  sets sets: List(UpdateSet),
) -> Update(a)

Sets or replaces many column sets in an Update query.

pub fn sets_sub_query(
  columns columns: List(String),
  query query: ReadQuery,
) -> UpdateSet

Sets many columns to a sub-query value.

NOTICE: the sub-query must return an equal count of columns.

pub fn table(
  update update: Update(a),
  name name: String,
) -> Update(a)

Sets the table of the Update query.

pub fn to_query(update update: Update(a)) -> WriteQuery(a)

Creates a WriteQuery from an Update query.

pub fn where(
  update update: Update(a),
  where where: Where,
) -> Update(a)

Sets an AndWhere or appends into an existing AndWhere.

  • If the outermost Where is an AndWhere, the new Where is appended to the list within AndWhere.
  • If the query does not have a Where clause, the given Where is set instead.
  • If the outermost Where is any other kind of Where, this and the current outermost Where are wrapped in an AndWhere.
pub fn xor_where(
  update update: Update(a),
  where where: Where,
) -> Update(a)

Sets an XorWhere or appends into an existing XorWhere.

  • If the outermost Where is an XorWhere, the new Where is appended to the list within XorWhere.
  • If the query does not have a Where clause, the given Where is set instead.
  • If the outermost Where is any other kind of Where, this and the current outermost Where are wrapped in an XorWhere.

NOTICE: This operator does not exist in 🐘PostgreSQL or 🪶SQLite, and Cake generates equivalent SQL using OR and AND and NOT.

NOTICE: This operator exists in 🦭MariaDB and 🐬MySQL with native support.

Search Document