Skip to main content

Module diesel

Module diesel 

Source
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§

ColumnType
What a column takes, at compile time: the Value variants of its non-null SQL type (ValueSqlType::ACCEPTS), and whether it may be NULL.
ValueMismatch
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 NULL for a NOT NULL column.

Traits§

AssignColumn
A Diesel column a model’s merge-patch writes can set: one whose SQL type converts a domain value (ColumnValue).
BoxedQuery
A boxed query on the table QS (table.into_boxed(), after any select or filter): one taking conditions, orderings, a limit and an offset as the same type, which apply adds.
ColumnValue
The Rust value a column whose SQL type is Self is set to: the SQL type’s Rust type, or an Option of it for a nullable column.
Comparison
How a column whose non-null SQL type is Self is compared with a value: <, =, >, and for text the LIKE operators.
Entity
A Diesel entity: one whose columns the model’s data can name, implemented by #[derive(Columns)] for an entity with #[diesel(table_name = ..)].
FilterColumn
A Diesel column a model’s filter conditions can compare: one whose SQL type converts a domain value (ValueSqlType and Comparison).
JoinConditions
A backend whose conditions on the table QS can be joined: every Diesel backend.
NonNull
Nullable<ST> → ST: the non-null SQL type of a column, nullable or not (through IntoNullable, which leaves a nullable type as it is).
OrderColumn
A Diesel column a model’s sort keys can order by.
ValueSqlType
A non-null SQL type a domain value binds as: the Rust type it binds, taken from a Value.

Functions§

apply
The boxed query query with the condition (its filter, so ANDed to the query’s own), the orderings after its own (then_order_by), and the page (limit and offset, from page).
assignment
The assignment column = value for a merge-patch write of the model.
condition
The condition column operator value for a filter condition of the model, the column being the one the entity stores its domain field in.
join
The conditions joined by junction (AND or OR), in order; None when there are none.
ordering
The ordering column ASC or column DESC for a sort key of the model.
page
The LIMIT and OFFSET of page page (0 based) of page_size rows, for a boxed query’s limit and offset; None unless both are requested.

Type Aliases§

Assignment
The assignment column = value of the column C: one slot of an entity’s changeset (an Option of it, None when unchanged).
BoxedCondition
A filter condition on the table QS, boxed for a boxed query’s filter.
BoxedOrdering
An ordering on the table QS, boxed for a boxed query’s then_order_by.
NonNullSqlType
The non-null SQL type of the column C.
ValueOf
The Rust value type of the column C, by its SQL type.