cake/insert

A DSL to build INSERT queries.

Functions

pub fn bool(value vl: Bool) -> Param

Create an InsertValue from a column String and a Bool value.

pub fn columns(
  query qry: Insert(a),
  columns cols: List(String),
) -> Insert(a)

Specify the columns to insert into.

NOTICE: You have to specify the columns and keep track if their names are correct, as well as their count which must be equal to the count of InsertRows the caster function returns or is given as source values.

pub fn comment(
  query qry: Insert(a),
  comment cmmnt: String,
) -> Insert(a)

Specify a comment for the INSERT query.

pub fn epilog(
  query qry: Insert(a),
  epilog eplg: String,
) -> Insert(a)

Specify an epilog for the INSERT query.

pub fn float(value vl: Float) -> Param

Create an InsertValue from a column String and a Float value.

pub fn from_records(
  table_name tbl_nm: String,
  columns cols: List(String),
  records rcrds: List(a),
  caster cstr: fn(a) -> InsertRow,
) -> Insert(a)

Create an INSERT query from a list of gleam records.

The caster function is used to convert each record into an InsertRow.

pub fn from_values(
  table_name tbl_nm: String,
  columns cols: List(String),
  values vls: List(InsertRow),
) -> Insert(a)

Create an INSERT query from a list of InsertRows.

pub fn get_columns(query qry: Insert(a)) -> InsertColumns

Get the columns to insert into from an Insert query.

pub fn get_comment(query qry: Insert(a)) -> Comment

Get the comment from an INSERT query.

pub fn get_epilog(query qry: Insert(a)) -> Epilog

Get the epilog from an INSERT query.

pub fn get_modifier(query qry: Insert(a)) -> String

Get the modifier from an Insert query.

pub fn get_on_conflict(
  query qry: Insert(a),
) -> InsertConflictStrategy(a)

Get the conflict strategy from an Insert query.

pub fn get_source(query qry: Insert(a)) -> InsertSource(a)

Get the source from an Insert query which is either a list of records, accompanied by a caster function or a list of InsertRows.

pub fn get_table(query qry: Insert(a)) -> InsertIntoTable

Get the table name to insert into from an Insert query.

pub fn int(value vl: Int) -> Param

Create an InsertValue from a column String and an Int value.

pub fn modifier(
  query qry: Insert(a),
  modifier mdfr: String,
) -> Insert(a)

Specify a modifier for the INSERT query.

pub fn new() -> Insert(a)

Create an empty INSERT query.

pub fn no_comment(query qry: Insert(a)) -> Insert(a)

Specify that no comment should be added to the INSERT query.

pub fn no_epilog(query qry: Insert(a)) -> Insert(a)

Specify that no epilog should be added to the INSERT query.

pub fn no_modifier(query qry: Insert(a)) -> Insert(a)

Specify that no modifier should be used for the given INSERT query.

pub fn no_returning(query qry: Insert(a)) -> Insert(a)

Specify that no columns should be returned after the INSERT query.

pub fn null() -> Param

Create a NULL InsertValue.

pub fn on_columns_conflict_ignore(
  query qry: Insert(a),
  column cols: List(String),
  where whr: Where,
) -> Insert(a)

This specifies that specific conflicts do not result in an error but instead are just ignored and not inserted.

Conflict Target: Columns

pub fn on_columns_conflict_update(
  query qry: Insert(a),
  column cols: List(String),
  where whr: Where,
  update updt: Update(a),
) -> Insert(a)

Inserts or updates on conflict, also called ´UPSERT´.

Conflict Target: Columns

pub fn on_conflict_error(query qry: Insert(a)) -> Insert(a)

This specifies that any conflicts result in the query to fail

This is the default behaviour.

pub fn on_constraint_conflict_ignore(
  query qry: Insert(a),
  constraint cnstrt: String,
  where whr: Where,
) -> Insert(a)

This specifies that specific conflicts do not result in an error but instead are just ignored and not inserted.

Conflict Target: Constraint

pub fn on_constraint_conflict_update(
  query qry: Insert(a),
  constraint cnstrt: String,
  where whr: Where,
  update updt: Update(a),
) -> Insert(a)

Inserts or updates on conflict, also called ´UPSERT´.

Conflict Target: Constraint

pub fn param(column col: String, param prm: Param) -> InsertValue

Create an InsertValue from a column String and a Param.

pub fn returning(
  query qry: Insert(a),
  returning rtrn: List(String),
) -> Insert(a)

Specify the columns to return after the INSERT query.

pub fn row(values vls: List(InsertValue)) -> InsertRow

Create an InsertRow from a list of InsertValues.

pub fn source_records(
  query qry: Insert(a),
  source rcrds: List(a),
  caster cstr: fn(a) -> InsertRow,
) -> Insert(a)

Specify the source records to insert.

pub fn source_values(
  query qry: Insert(a),
  records rcrds: List(InsertRow),
) -> Insert(a)

Specify the source values to insert.

pub fn string(value vl: String) -> Param

Create an InsertValue from a column String and a String value.

pub fn table(
  query qry: Insert(a),
  table_name tbl_nm: String,
) -> Insert(a)

Specify the table to insert into.

pub fn to_query(insert isrt: Insert(a)) -> WriteQuery(a)

Creates a WriteQuery from an Insert query.

Search Document