QueryId

Derive Macro QueryId 

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

Implements QueryId

For example, given this struct:

#[derive(diesel::query_builder::QueryId)]
pub struct And<Left, Right> {
    left: Left,
    right: Right,
}

the following implementation will be generated

impl<Left, Right> QueryId for And<Left, Right>
where
    Left: QueryId,
    Right: QueryId,
{
    type QueryId = And<Left::QueryId, Right::QueryId>;

    const HAS_STATIC_QUERY_ID: bool = Left::HAS_STATIC_QUERY_ID && Right::HAS_STATIC_QUERY_ID;
}

If the SQL generated by a struct is not uniquely identifiable by its type, meaning that HAS_STATIC_QUERY_ID should always be false, you shouldn’t derive this trait. In that case, you should implement it manually instead.

§Expanded Code

Expanded Code
§Input
#[derive(QueryId)]
struct Query;
§Expanded Code
Expanded code might use diesel internal API's and is only shown for educational purpose

The macro expands the input to the following Rust code:

const _: () = {
    use diesel;
    #[allow(non_camel_case_types)]
    impl diesel::query_builder::QueryId for Query {
        type QueryId = Query;
        const HAS_STATIC_QUERY_ID: bool = true;
        const IS_WINDOW_FUNCTION: bool = false;
    }
};