Skip to main content

ModelSelect

Derive Macro ModelSelect 

Source
#[derive(ModelSelect)]
{
    // Attributes available to this derive:
    #[model_select]
}
Expand description

Adds a typed SQL query builder to a Gen model.

The derive parses the model’s named fields and generates a <Model>Select type. Calling <Model>::select(...) creates that builder; its generated filter methods, typed field constants, ordering, joins, and projections are rendered into SQL when the query is loaded. String fields receive exact, literal _contains, and SQL _like filters, plus typed .order_by_relevance(field, search) ordering. Selectors can be composed with .join_on(left_field, right_field) or .join_filtered_on(...). Joined queries can project fields with .only(...) or complete models with .models::<(...)>(). Primary-key selectors also provide get_by_id(...), ordered and deduplicated query_by_ids(...) loads, and batched delete_by_ids(...) mutations. #[model_select(table = "...")] defines the selector’s table metadata and row decoder. #[model_select(column = "...")] overrides a field’s SQL column, #[model_select(primary_key)] marks each field in an explicit primary key, #[model_select(default_sort(field = "asc", tie_breaker = "desc"))] configures default ordering in precedence order, #[model_select(skip)] excludes a field, and the struct-level history, from_row, source, alias, and select options support custom persistence behavior or aliased queries.