Skip to main content

Columns

Trait Columns 

Source
pub trait Columns {
    const NAME: &'static str;
    const COLUMNS: &'static [(&'static str, &'static str)];

    // Provided methods
    fn column(field: &str) -> Option<&'static str> { ... }
    fn push_conditions<Q: ConditionsTarget, M: PersistedFields>(
        query: &mut Q,
        conditions: Conditions<M>,
        junction: Junction,
    ) { ... }
    fn push_order_by<Q: OrderByTarget, M: PersistedFields>(
        query: &mut Q,
        sort_keys: SortKeys<M>,
    ) { ... }
    fn push_assignments<Q: AssignmentsTarget, M: PersistedFields>(
        query: &mut Q,
        assignments: FieldValues<M>,
    ) -> Q::Assignments<'_> { ... }
}
Expand description

A table (usually a sqlx entity) whose columns store a domain model’s fields, and the SQL written for that model’s data against those columns.

The SQL methods are generic over the query they write into (a target, such as sqlx’s QueryBuilder for any BindValues database: Postgres, MySQL/MariaDB, SQLite) and over the model M, both taken from the arguments: Order::push_assignments(&mut query_builder, order.changed_values(&diff)). Each fails to build unless every field of M has a column on the table.

Required Associated Constants§

Source

const NAME: &'static str

The table’s type name, for compile errors about it.

Source

const COLUMNS: &'static [(&'static str, &'static str)]

(domain field, column) for every column of the table.

Provided Methods§

Source

fn column(field: &str) -> Option<&'static str>

The column a domain field is stored in, if the table has one.

Source

fn push_conditions<Q: ConditionsTarget, M: PersistedFields>( query: &mut Q, conditions: Conditions<M>, junction: Junction, )

Push the conditions of the model M to a query, joined by junction, each a column operator value comparison against the column the table stores its domain field in.

The conditions are a generated filter-options model’s conditions(). Values are bound with their own SQL type; the LIKE operators bind an escaped pattern (… LIKE ? ESCAPE '!'), so user input matches literally.

Fails to build unless every field of M has a column on the table.

Source

fn push_order_by<Q: OrderByTarget, M: PersistedFields>( query: &mut Q, sort_keys: SortKeys<M>, )

Push an ORDER BY column direction, … clause for the sort keys of the model M; nothing when there are none.

The sort keys are a generated query model’s sort_keys(), written in order, each by the column the table stores its domain field in.

Fails to build unless every field of M has a column on the table.

Source

fn push_assignments<Q: AssignmentsTarget, M: PersistedFields>( query: &mut Q, assignments: FieldValues<M>, ) -> Q::Assignments<'_>

Push column = value assignments of the model M for an UPDATE … SET, comma separated, returning what the query gives to add more (for sqlx, the separated builder).

The assignments are a MergePatch model’s changed_values, each to the column the table stores its domain field in.

Fails to build unless every field of M has a column on the table.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§