prorm API Reference
    Preparing search index...

    Interface ViewDefinition

    A view body expressed as query options rather than SQL.

    Every field means what it means in findAll(). attributes accepts the same rich forms — plain columns, [expression, alias] tuples, and fn() / col() / cast() expressions — so aggregates need no SQL either:

    await qi.createView('order_totals', {
    from: Order,
    attributes: ['userId', [fn('COUNT', col('id')), 'orderCount']],
    group: 'userId',
    });
    interface ViewDefinition {
        from: ViewSource;
        schema?: string;
        attributes?: string[] | { include?: string[]; exclude?: string[] };
        where?: WhereOptions;
        include?: IncludeOptions[];
        order?: Order;
        group?: string | string[];
        having?: WhereOptions;
        limit?: string | number;
        offset?: string | number;
        distinct?: boolean;
        distinctOn?: string[];
        cte?: ViewCTE[];
        union?: {
            model: any;
            where?: WhereOptions;
            attributes?: string[] | { include?: string[]; exclude?: string[] };
            order?: Order;
            limit?: string | number;
            offset?: string | number;
            include?: IncludeOptions[];
            as?: string;
        }[];
        unionType?: "UNION"
        | "UNION ALL"
        | "EXCEPT"
        | "INTERSECT";
    }
    Index

    The table or model the view selects from.

    schema?: string

    Schema qualifying from. Defaults to the source model's own schema.

    attributes?: string[] | { include?: string[]; exclude?: string[] }

    Columns the view exposes. Omit to select every column.

    Attribute names are used exactly as findAll() uses them, so a view built from a model selects the same columns a query on that model would.

    where?: WhereOptions

    Row filter, in the usual operator syntax.

    include?: IncludeOptions[]

    Joins to other models, same as findAll({ include }).

    order?: Order

    Ordering. Note that several databases ignore ORDER BY inside a view.

    group?: string | string[]

    GROUP BY column(s).

    having?: WhereOptions

    HAVING filter, applied after grouping.

    limit?: string | number

    Row cap. Not permitted inside a view by every database.

    offset?: string | number

    Row offset.

    distinct?: boolean

    SELECT DISTINCT.

    distinctOn?: string[]

    PostgreSQL SELECT DISTINCT ON (...).

    cte?: ViewCTE[]

    Common table expressions prepended as a WITH clause. Each body may itself be a ViewDefinition, so a view with CTEs needs no SQL either.

    union?: {
        model: any;
        where?: WhereOptions;
        attributes?: string[] | { include?: string[]; exclude?: string[] };
        order?: Order;
        limit?: string | number;
        offset?: string | number;
        include?: IncludeOptions[];
        as?: string;
    }[]

    Queries combined with the main one.

    unionType?: "UNION" | "UNION ALL" | "EXCEPT" | "INTERSECT"

    How union entries are combined. Defaults to UNION.