Expand description
The mods, written once against the Has* traits and re-exported per statement.
Nothing in here names a query type. A mod is Mod<Q> for every Q that
implements the clause trait it needs, so where_ is one function that serves
SELECT, UPDATE, DELETE and the DO UPDATE body of an upsert — and
refuses to compile against an INSERT, which has no WHERE.
Three shapes recur.
A plain mod is a function returning impl Mod<Q>, built from
mod_fn.
A chain is a struct that is itself a mod and has builder methods. It exists
wherever a clause has decorations that must be set together rather than one mod
at a time: from(..).as_("u").not_indexed() replaces the whole from-item once,
so no later mod can silently wipe an earlier one.
A slot is how one chain type reaches different fields of different queries.
select::from and update::table are the same chain with a different
TableSlot; the marker is a type parameter, so which field is written is
decided at compile time and there is one implementation of the builder methods.
Structs§
- Conflict
Chain - An
upsert-clauseunder construction. - Conflict
Mod - A finished
upsert-clause, ready to apply. - CteChain
- A common table expression under construction.
- Extra
Slot - The additional-from-items slot, for the second and later entries of a
comma-separated
FROMlist. - From
Slot - The from-item slot: a
SELECT’s or anUPDATE’sFROM. - Into
Chain - An
INSERT’s target under construction:INTO "t" AS "alias" ("a", "b"). - Join
Chain - A join under construction.
- Order
Chain - One
ordering-termunder construction. - SetChain
- The left-hand side of an assignment:
set_col("a").to(arg(1)). - Table
Chain - A
table-or-subquery— or aqualified-table-name— under construction. - Target
Slot - The target slot: the table an
UPDATEwrites to or aDELETEremoves from.
Traits§
- Table
Slot - Where a
TableChainputs the table reference it has built.
Functions§
- columns
- Add to the result columns. Several calls accumulate; with none,
*is written. - cross_
join CROSS JOIN <table>— an inner join that also pins the join order.- except
EXCEPT <select-core>— rows of this query that are not in the other. There is noEXCEPT ALL.- extra_
from_ item - A further comma-separated from-item. A comma is one of SQLite’s
join-operators and means the same asCROSS JOIN. - from_
item - A from-item:
FROM <table>. - full_
join FULL JOIN <table>— SQLite 3.39 and later.- group_
by - Add a grouping expression.
- having
HAVING condition. Several calls areAND-joined.- inner_
join INNER JOIN <table>.- intersect
INTERSECT <select-core>— rows of both. There is noINTERSECT ALL.- into_
table INSERT INTO <table>.- left_
join LEFT JOIN <table>.- limit
LIMIT count.- offset
OFFSET start.- on_
conflict ON CONFLICT (columns)— infer the unique index from a column list.- or_
abort OR ABORT— abort this statement and undo it, but keep the transaction. The default, written out.- or_fail
OR FAIL— stop at the offending row, keeping the changes made before it.- or_
ignore OR IGNORE— skip the offending row and carry on with the rest.- or_
replace OR REPLACE— delete the rows that conflict, then proceed. This is what SQLite’sREPLACE INTOis short for.- or_
rollback OR ROLLBACK— a constraint violation aborts the whole transaction.- order_
by ORDER BY expression.- preload_
columns - Add to the preload result columns, which render after
columnsbut are counted separately. - recursive
WITH RECURSIVErather thanWITH.- returning
RETURNING a, b.returning("*")is an ordinary entry.- right_
join RIGHT JOIN <table>— SQLite 3.39 and later.- rows
- Several rows of
VALUESat once. - set
- One assignment, written out:
set(quote("a").eq(arg(1))). - set_col
- Assign to a column.
set_col(("t", "a"))qualifies it, whichUPDATEforbids but an upsert’sDO UPDATEpermits. - set_
excluded "col" = excluded."col"for each column — the body of an upsert.- target_
table - The statement’s target table: what an
UPDATEwrites to, what aDELETEremoves from. - union
UNION <select-core>— rows of either, duplicates removed.- union_
all UNION ALL <select-core>— rows of either, duplicates kept.- values
- One row of
VALUES. Several calls append several rows. - values_
from_ query - Insert the results of a query:
INSERT INTO t (cols) SELECT …. - where_
WHERE condition. Several calls areAND-joined; useorfor the other connective.- window
WINDOW "name" AS (definition), the definition built fromwindowandframemods.- with
WITH "name" AS (body).