Expand description
INSERT INTO .. VALUES ...
A column with a schema default gets a Defaultable<T> field, so “omit”
and “explicit value” stay distinguishable — and Defaultable<Option<T>>
when it’s also nullable, making that three distinct states. Omission
renders as the DEFAULT keyword in that row’s VALUES (..) tuple rather
than changing the column list, so rows that omit different fields still
share one statement.
Structs§
- Insert
- Insert
Seed - Missing
- A column an
*Insertbuilder hasn’t been given a value for yet. Named after the column so the builder’s type says which one is missing, rather than leaving a bare()to be counted by position. - Nothing
ToInsert - An
INSERTwas given no rows at all. Returned rather than panicked for the reasonupdate::NothingToSetgives: an empty collection is ordinary request-shaped data, and the caller decides whether it is a no-op or an error.
Enums§
Traits§
- Conflict
Target - An
ON CONFLICTtarget: one or more columns proven byTto belong to the table being inserted into, where a raw&[&str]would let a typo through to the database. Implemented for a bareColumn<C>and for tuples of up to three; add arities as real schemas need them. - Filled
- Proof that a builder’s slot for column
Cholds that column’s value. Deliberately unsealed, unlikescope::Find: forging it buys nothing, because*Insert’s fields are public and a complete row with a value of the caller’s choosing is directly constructible. What the type-state builder prevents is forgetting a column, not choosing its value — and a seal here can’t hold anyway, since the derive must implement this in the schema’s own crate, where any nameable proof is nameable twice.Missing<C>doesn’t implement it, which is whatbuild()is bounded by — on the method rather than by the slot’s type, so an incomplete row is a sentence naming the column rather than a missingbuild. - Insert
Row - Implemented by the
#[derive(Table)]-generated*Insertstruct for each table. One list of(column, value)pairs rather than a name list beside a value list, for the reasonselect::AllColumnscarries one list: the seal is#[doc(hidden)] pub— the derive has to write it in the schema’s own crate — so two lists that have to line up position for position could be made not to, andINSERT INTO t (a, b, c) VALUES ($1)is malformed whatever the table looks like.update::UpdateRow::setshas always had this shape. - Insert
Values - A chain of
(column, value)cells:RowCons<C, InsertValue, Tail>down toRowNil. Walked once for the header and once for each row’s values, so the two cannot disagree. - Insertable
- A table with at least one column a statement may insert into. Emitted by
#[derive(Table)]unless every column is generated, which leaves anINSERTwith nothing to name: SQL spells thatDEFAULT VALUES, and spells it for exactly one row. - Into
Column Value - What a column’s setter accepts, keyed by what that column’s field
holds: the column’s own Rust type —
&strfor text — plus theOptiona request struct already carries, wherever leaving the column out means something. WhatNonemeans is the position’s own: on an insert it is NULL for a nullable column and the schema’s default for a defaulted one (.<column>_null()says the other, where a column is both); on an update it is untouched, since anUPDATEthat says nothing about a column leaves it alone.