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<DB: BindValues, M: PersistedFields>(
        query_builder: &mut QueryBuilder<'_, DB>,
        conditions: Conditions<M>,
        separator: &str,
    ) { ... }
    fn push_order_by<DB: BindValues, M: PersistedFields>(
        query_builder: &mut QueryBuilder<'_, DB>,
        sort_keys: SortKeys<M>,
    ) { ... }
    fn push_assignments<'qb, 'args, DB: BindValues, M: PersistedFields>(
        query_builder: &'qb mut QueryBuilder<'args, DB>,
        assignments: FieldValues<M>,
    ) -> Separated<'qb, 'args, DB, &'static str> { ... }
}
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 database (DB: BindValues: 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<DB: BindValues, M: PersistedFields>( query_builder: &mut QueryBuilder<'_, DB>, conditions: Conditions<M>, separator: &str, )

Push the conditions of the model M to a query, joined by separator (e.g. AND), 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<DB: BindValues, M: PersistedFields>( query_builder: &mut QueryBuilder<'_, DB>, 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<'qb, 'args, DB: BindValues, M: PersistedFields>( query_builder: &'qb mut QueryBuilder<'args, DB>, assignments: FieldValues<M>, ) -> Separated<'qb, 'args, DB, &'static str>

Push column = value assignments of the model M for an UPDATE … SET, comma separated, returning the separated builder so more can be added.

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§