kreator
Types
The method of the query. This is what defines if the query is a select, insert, update, or delete.
pub opaque type Method
Functions
pub fn and_where(
plan: Plan,
fun: fn(List(Where)) -> List(Where),
) -> Plan
pub fn delete(plan: Plan) -> Plan
Transforms the plan into a delete query. Will not fail if no where was set.
pub fn insert(plan: Plan, data: List(#(String, Value))) -> Plan
Transforms the plan into an insert query and sets the data to be inserted. It will not fail if the data is empty, tough the generated query will probably be invalid.
Example
import kreator.{table, insert, to_sqlite}
pub fn insert_users() {
table("users")
|> insert([("name", "Bruno")])
|> to_sqlite()
/// ==> "insert into `users` (`name`) values (?)"
}
pub fn not_returning(plan: Plan) -> Plan
pub fn or_where(
plan: Plan,
fun: fn(List(Where)) -> List(Where),
) -> Plan
pub fn order_by(
plan: Plan,
column column: String,
direction direction: Direction,
) -> Plan
Add an order by clause to the plan. Can be used multiple times to add multiple order by clauses.
pub fn returning(plan: Plan, returning: List(String)) -> Plan
Set the columns to be returned.
table("users") |> select(["name", "id"]) |> returning("id") |> to_sqlite() /// ==> "select `name`, `id` from `users` returning `id`"
pub fn select(plan: Plan, select: List(String)) -> Plan
Set the columns on a select statement. By default the value is ["*"]
.
table("users") |> select(["name", "id"]) |> to_sqlite() /// ==> "select `name`, `id` from `users`"
pub fn table(table: String) -> Plan
Start a new plan to build a query by setting the table. With just using this you can already create a simple select like this:
table("users") |> to_sqlite() /// ==> "select * from `users`"
If you want to know how to select specific columns you can jump to the select function.
pub fn to_postgres(plan: Plan) -> Query
Builds a query based on a Plan
for the `Postgres`` dialect.
pub fn to_sqlite(plan: Plan) -> Query
Builds a query based on a Plan
for the SQLite dialect.
pub fn update(plan: Plan, data: List(#(String, Value))) -> Plan
Transforms the plan into an unpdate query and sets the data to be updated. It will not fail if the data is empty, tough the generated query will probably be invalid. Also it will not fail if no where was set.