Expand description
Diesel’s typed query DSL as the target of a model’s data.
Filter conditions become boxed expressions on a table, sort keys boxed
orderings, a page LIMIT / OFFSET values, and merge-patch writes typed
column = value assignments for a changeset.
Diesel types every column statically, so a column is named by the code
Columns generates for a Diesel entity (one match arm per column), not
looked up by name here. The functions below take that typed column and an
item of the model’s data, and convert the item’s Value into the column’s
own Rust type, picked by the column’s SQL type through ValueSqlType: no
SQL is written by hand, and Diesel renders it for each backend.
The wrappers reach a Diesel entity’s methods through Entity, which
Columns implements for it, and apply them to a BoxedQuery.
A domain field whose value does not fit its column’s SQL type (a domain
field and its column disagree on the type, or a nullable field is written
to a NOT NULL column) fails to build where the entity’s methods are
called for its model: the domain derives publish each field’s value type
(PersistedFields::FIELD_TYPES), and each column’s SQL type the values it
takes (ValueSqlType::ACCEPTS, through FilterColumn::ACCEPTS and
ColumnValue::TYPE). A value that
still does not fit at run time (a model implementing PersistedFields by
hand, or a NULL written to a NOT NULL column) is a ValueMismatch
error, not a panic.
Structs§
- Column
Type - What a column takes, at compile time: the
Valuevariants of its non-null SQL type (ValueSqlType::ACCEPTS), and whether it may beNULL. - Value
Mismatch - A value that does not fit its column: the domain field’s raw type and the
column’s SQL type disagree, or the value is a
NULLfor aNOT NULLcolumn.
Traits§
- Assign
Column - A Diesel column a model’s merge-patch writes can set: one whose SQL type
converts a domain value (
ColumnValue). - Boxed
Query - A boxed query on the table
QS(table.into_boxed(), after anyselectorfilter): one taking conditions, orderings, a limit and an offset as the same type, whichapplyadds. - Column
Value - The Rust value a column whose SQL type is
Selfis set to: the SQL type’s Rust type, or anOptionof it for a nullable column. - Comparison
- How a column whose non-null SQL type is
Selfis compared with a value:<,=,>, and for text theLIKEoperators. - Entity
- A Diesel entity: one whose columns the model’s data can name, implemented
by
#[derive(Columns)]for an entity with#[diesel(table_name = ..)]. - Filter
Column - A Diesel column a model’s filter conditions can compare: one whose SQL
type converts a domain value (
ValueSqlTypeandComparison). - Join
Conditions - A backend whose conditions on the table
QScan be joined: every Diesel backend. - NonNull
Nullable<ST>→ST: the non-null SQL type of a column, nullable or not (throughIntoNullable, which leaves a nullable type as it is).- Order
Column - A Diesel column a model’s sort keys can order by.
- Value
SqlType - A non-null SQL type a domain value binds as: the Rust type it binds, taken
from a
Value.
Functions§
- apply
- The boxed query
querywith the condition (itsfilter, soANDed to the query’s own), the orderings after its own (then_order_by), and the page (limitandoffset, frompage). - assignment
- The assignment
column = valuefor a merge-patch write of the model. - condition
- The condition
column operator valuefor a filter condition of the model, the column being the one the entity stores its domain field in. - join
- The conditions joined by
junction(ANDorOR), in order;Nonewhen there are none. - ordering
- The ordering
column ASCorcolumn DESCfor a sort key of the model. - page
- The
LIMITandOFFSETof pagepage(0 based) ofpage_sizerows, for a boxed query’slimitandoffset;Noneunless both are requested.
Type Aliases§
- Assignment
- The assignment
column = valueof the columnC: one slot of an entity’s changeset (anOptionof it,Nonewhen unchanged). - Boxed
Condition - A filter condition on the table
QS, boxed for a boxed query’sfilter. - Boxed
Ordering - An ordering on the table
QS, boxed for a boxed query’sthen_order_by. - NonNull
SqlType - The non-null SQL type of the column
C. - ValueOf
- The Rust value type of the column
C, by its SQL type.