Skip to main content

Module insert

Module insert 

Source
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
InsertSeed
Missing
A column an *Insert builder 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.
NothingToInsert
An INSERT was given no rows at all. Returned rather than panicked for the reason update::NothingToSet gives: an empty collection is ordinary request-shaped data, and the caller decides whether it is a no-op or an error.

Enums§

Defaultable
InsertValue

Traits§

ConflictTarget
An ON CONFLICT target: one or more columns proven by T to belong to the table being inserted into, where a raw &[&str] would let a typo through to the database. Implemented for a bare Column<C> and for tuples of up to three; add arities as real schemas need them.
Filled
Proof that a builder’s slot for column C holds that column’s value. Deliberately unsealed, unlike scope::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 what build() 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 missing build.
InsertRow
Implemented by the #[derive(Table)]-generated *Insert struct for each table. One list of (column, value) pairs rather than a name list beside a value list, for the reason select::AllColumns carries 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, and INSERT INTO t (a, b, c) VALUES ($1) is malformed whatever the table looks like. update::UpdateRow::sets has always had this shape.
InsertValues
A chain of (column, value) cells: RowCons<C, InsertValue, Tail> down to RowNil. 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 an INSERT with nothing to name: SQL spells that DEFAULT VALUES, and spells it for exactly one row.
IntoColumnValue
What a column’s setter accepts, keyed by what that column’s field holds: the column’s own Rust type — &str for text — plus the Option a request struct already carries, wherever leaving the column out means something. What None means 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 an UPDATE that says nothing about a column leaves it alone.

Functions§

insert