Skip to main content

Crate queryweave_codegen

Crate queryweave_codegen 

Source
Expand description

The code generation behind the queryweave derives, as an ordinary library.

Each derive is a function from the derive’s input to the generated code, generic over the conventions::Conventions it names things by. queryweave-derive exports every derive with conventions::DefaultConventions; a crate wanting other rules writes its own small proc-macro crate calling these functions with its own conventions:

ⓘ
#[proc_macro_derive(Filters, attributes(filter, sortable, filters, equivalent_field))]
pub fn derive_filters(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    queryweave_codegen::filters::<MyConventions>(input.into()).into()
}

Every derive is built as a steps::Derive pipeline, private to the crate (see docs/macros.md).

Modules§

conventions
How the derives name what they generate, and which names they require of the structs they are placed on or link to.
errors
Errors spanned to the user’s code, for a Conventions impl to report a name that does not fit.
integrations
What a Filters mirror’s generated code integrates with (serialization, API documentation, validation, …), each opted into per struct with a flag of #[filters(...)] named after it.
names
Checks on the names of the structs a derive is placed on or links to.

Functions§

append_conditions
#[derive(AppendConditions)]: queryweave_sql::AppendConditions for a filter-options wrapper, appending its set filters to a query as conditions.
append_to_query
#[derive(AppendToQuery)]: the append to query trait on a wrapper of a domain query model.
columns
#[derive(Columns)]: queryweave_sql::Columns for a sqlx entity, recording which column stores each field of the domain model named by #[columns(model = Model)].
filters
#[derive(Filters)]: the filtering, sorting and paging types of a struct, from its #[filter(lt|eq|gt|sw|c|ew|bool)] and #[sortable] fields.
merge_patch
#[derive(MergePatch)]: the functions merge patching a model with its merge patch model counterpart.
merge_patch_nullable_fields
#[derive(MergePatchNullableFields)]: a function listing the nullable fields of a struct used for merge-patching, i.e. its Option<Option<T>> fields.
raw_value
#[derive(RawValue)]: queryweave::RawValue for a value object (a newtype such as struct Username<T = String>(T);), whose raw value is the wrapped type’s.
validate_non_nullable
#[derive(ValidateNonNullable)]: a validation function for a merge patch DTO, mirroring a domain merge patch model.