cake/insert
A DSL to build INSERT
queries.
Types
pub type InsertColumns =
@internal InsertColumns
pub type InsertConflictStrategy(a) =
@internal InsertConflictStrategy(a)
pub type InsertIntoTable =
@internal InsertIntoTable
pub type InsertSource(a) =
@internal InsertSource(a)
pub type InsertValue =
@internal InsertValue
pub type WriteQuery(a) =
@internal WriteQuery(a)
Values
pub fn bool(value vl: Bool) -> @internal InsertValue
Create an InsertValue
from a column String
and a Bool
value.
pub fn columns(
insert isrt: @internal Insert(a),
columns cols: List(String),
) -> @internal 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 encoder function returns or is given as source
values.
pub fn comment(
insert isrt: @internal Insert(a),
comment cmmnt: String,
) -> @internal Insert(a)
Specify a comment for the INSERT
query.
pub fn epilog(
insert isrt: @internal Insert(a),
epilog eplg: String,
) -> @internal Insert(a)
Specify an epilog for the INSERT
query.
pub fn float(value vl: Float) -> @internal InsertValue
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),
encoder encdr: fn(a) -> @internal InsertRow,
) -> @internal Insert(a)
Create an INSERT
query from a list of gleam records.
The encoder
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(@internal InsertRow),
) -> @internal Insert(a)
Create an INSERT
query from a list of InsertRow
s.
pub fn get_columns(
insert isrt: @internal Insert(a),
) -> @internal InsertColumns
Get the columns to insert into from an Insert
query.
pub fn get_comment(
insert isrt: @internal Insert(a),
) -> @internal Comment
Get the comment from an INSERT
query.
pub fn get_epilog(
insert isrt: @internal Insert(a),
) -> @internal Epilog
Get the epilog from an INSERT
query.
pub fn get_modifier(insert isrt: @internal Insert(a)) -> String
Get the modifier from an Insert
query.
pub fn get_on_conflict(
insert isrt: @internal Insert(a),
) -> @internal InsertConflictStrategy(a)
Get the conflict strategy from an Insert
query.
pub fn get_source(
insert isrt: @internal Insert(a),
) -> @internal InsertSource(a)
Get the source from an Insert
query which is either a list of records,
accompanied by a encoder function or a list of InsertRow
s.
pub fn get_table(
insert isrt: @internal Insert(a),
) -> @internal InsertIntoTable
Get the table name to insert into from an Insert
query.
pub fn int(value vl: Int) -> @internal InsertValue
Create an InsertValue
from a column String
and an Int
value.
pub fn modifier(
insert isrt: @internal Insert(a),
modifier mdfr: String,
) -> @internal Insert(a)
Specify a modifier for the INSERT
query.
pub fn no_comment(
insert isrt: @internal Insert(a),
) -> @internal Insert(a)
Specify that no comment should be added to the INSERT
query.
pub fn no_epilog(
insert isrt: @internal Insert(a),
) -> @internal Insert(a)
Specify that no epilog should be added to the INSERT
query.
pub fn no_modifier(
insert isrt: @internal Insert(a),
) -> @internal Insert(a)
Specify that no modifier should be used for the given INSERT
query.
pub fn no_returning(
insert isrt: @internal Insert(a),
) -> @internal Insert(a)
Specify that no columns should be returned after the INSERT
query.
pub fn on_columns_conflict_ignore(
insert isrt: @internal Insert(a),
columns cols: List(String),
where whr: @internal Where,
) -> @internal 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(
insert isrt: @internal Insert(a),
columns cols: List(String),
where whr: @internal Where,
update updt: @internal Update(a),
) -> @internal Insert(a)
Inserts or updates on conflict, also called ´UPSERT´.
Conflict Target: Columns
pub fn on_conflict_error(
insert isrt: @internal Insert(a),
) -> @internal Insert(a)
This specifies that any conflicts result in the query to fail
This is the default behaviour.
pub fn on_constraint_conflict_ignore(
insert isrt: @internal Insert(a),
constraint cnstrt: String,
where whr: @internal Where,
) -> @internal 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(
insert isrt: @internal Insert(a),
constraint cnstrt: String,
where whr: @internal Where,
update updt: @internal Update(a),
) -> @internal Insert(a)
Inserts or updates on conflict, also called ´UPSERT´.
Conflict Target: Constraint
pub fn returning(
insert isrt: @internal Insert(a),
returning rtrn: List(String),
) -> @internal Insert(a)
Specify the columns to return after the INSERT
query.
pub fn row(
values vls: List(@internal InsertValue),
) -> @internal InsertRow
Create an InsertRow
from a list of InsertValue
s.
pub fn source_records(
insert isrt: @internal Insert(a),
source rcrds: List(a),
encoder encdr: fn(a) -> @internal InsertRow,
) -> @internal Insert(a)
Specify the source records to insert.
pub fn source_values(
insert isrt: @internal Insert(a),
source rws: List(@internal InsertRow),
) -> @internal Insert(a)
Specify the source values to insert.
pub fn string(value vl: String) -> @internal InsertValue
Create an InsertValue
from a column String
and a String
value.
pub fn table(
insert isrt: @internal Insert(a),
table_name tbl_nm: String,
) -> @internal Insert(a)
Specify the table to insert into.