import { WixDataFilter } from './WixDataFilter'; import { WixDataAggregateOptions } from './types'; import { WixDataResult } from './WixDataResult'; /** * @builder */ export interface WixDataAggregate { /** * Refines a `WixDataAggregate` to contain the sum from each aggregation group. * * The `sum()` method refines a `WixDataAggregate` to contain the sum of the * values from the specified field for each aggregated group or from the * whole collection if no group is defined. * * When the aggregation is `run()`, the returned `WixDataAggregateResult` * object contains an item for each group with the following key-value pairs: * - If a value was passed for the optional `projectedField`, the key is named * using that value. Otherwise, the key is named using the following format: * `"fieldSum"`, where `field` is the name of the specified field. * - The value is the sum of the values found in the specified field. * * Sums can only be calculated on fields of type Number. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be * > used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param field - Field in which to find the sum. * @requiredField field * @param projectedField - Name of the field in the aggregation results containing the sum. * @returns `WixDataAggregate` object representing the refined aggregation. */ sum(field: string, projectedField?: string): WixDataAggregate; /** * Refines a `WixDataAggregate` to only contain the average value from each aggregation group. * * The `avg()` method refines a `WixDataAggregate` to contain the average * value from the specified field for each aggregated group or from the * whole collection if no group is defined. * * When the aggregation is `run()`, the returned `WixDataAggregateResult` * object contains an item for each group with the following key-value pairs: * - If a value was passed for the optional `projectedField`, the key is named * using that value. Otherwise, the key is named using the following format: * `"fieldAvg"`, where `field` is the name of the specified field. * - The value is the average of the values found in the specified field. * * Averages can only be calculated on fields of type Number. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be * > used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param field - Field in which to find the average value. * @requiredField field * @param projectedField - Field in the aggregation results containing the average value. * @returns `WixDataAggregate` object representing the refined aggregation. */ avg(field: string, projectedField?: string): WixDataAggregate; /** * Refines a `WixDataAggregate` to only contain the minimum value from each aggregation group. * * The `min()` method refines a `WixDataAggregate` to contain the minimum * value from the specified field for each aggregated group or from the * whole collection if no group is defined. * * When the aggregation is `run()`, the returned `WixDataAggregateResult` * object contains an item for each group with the following key-value pairs: * - If a value was passed for the optional `projectedField`, the key is named * using that value. Otherwise, the key is named using the following format: * `"fieldMin"`, where `field` is the name of the specified field. * - The value is the minimum value found in the specified field. * * The following types of fields can be compared to determine a minimum value: * - Number: Compares numerically. * - Date and Time: Compares JavaScript Date objects. * - Text: Compares lexicographically, so `"text"` is greater than `"Text"`. * - Rich Text: Compares HTML source as text. * - URL: Compares as text. * - Image: Compares image source as text. * - Video: Compares video source as text. * - Document: Compares document source as text. * - Reference: Compares by the ID of the referenced item as a String. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be * > used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param field - Field in which to find the minimum value. * @requiredField field * @param projectedField - Name of the field in the aggregation results containing the minimum value. * @returns `WixDataAggregate` object representing the refined aggregation. */ min(field: string, projectedField?: string): WixDataAggregate; /** * Refines a `WixDataAggregate` to only contain the maximum value from each aggregation group. * * The `max()` method refines a `WixDataAggregate` to contain the maximum * value from the specified field for each aggregated group or from the * whole collection if no group is defined. * * When the aggregation is `run()`, the returned `WixDataAggregateResult` * object contains an item for each group with the following key-value pairs: * - If a value was passed for the optional `projectedField`, the key is named * using that value. Otherwise, the key is named using the following format: * `"fieldMax"`, where `field` is the name of the specified field. * - The value is the maximum value found in the specified field. * * The following types of fields can be compared to determine a maximum value: * - Number: Compares numerically. * - Date and Time: Compares JavaScript Date objects. * - Text: Compares lexicographically, so `"text"` is greater than `"Text"`. * - Rich Text: Compares HTML source as text. * - URL: Compares as text. * - Image: Compares image source as text. * - Video: Compares video source as text. * - Document: Compares document source as text. * - Reference: Compares by the ID of the referenced item as a String. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be * > used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param field - Field in which to find the maximum value. * @requiredField field * @param projectedField - Field in the aggregation results that contains the maximum value. * @returns `WixDataAggregate` object representing the refined aggregation. */ max(field: string, projectedField?: string): WixDataAggregate; /** * Refines a `WixDataAggregate` to contain the item count of each group in the aggregation. * * The `count()` method refines a `WixDataAggregate` contains the item count in each of the aggregate's groups. * * When the aggregation is `run()`, the returned `WixDataAggregateResult` * object contains items with the following additional key-value pair: * - The key is named `count`. You can set a custom key using the `projectedField` parameter. * - The value is the count of items aggregated in the group. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be * > used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param projectedField - Field in the aggregation results that contains the count value. Default: `count`. * @returns `WixDataAggregate` object representing the refined aggregation. */ count(projectedField?: string): WixDataAggregate; /** * Filters out items from being used in an aggregation. * * The `filter()` method refines a `WixDataAggregate` so that it only * includes items from the aggregate's collection which match the specified * filter criteria. * * To create a filter, use the wix-data `filter()` method. * * Filtering using `filter()` takes place before grouping is performed on the * aggregation. To filter grouped results, use the `having()` method. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be * > used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param filter - Filter to use to filter out items from being used in the aggregation. * @requiredField filter * @returns `WixDataAggregate` object representing the refined aggregation. */ filter(filter: WixDataFilter): WixDataAggregate; /** * Groups items together in an aggregation. * * The `group()` method refines a `WixDataAggregate` so that its items are * grouped by the specified field or fields. * * You can perform aggregations on the groups using the following methods: * - `avg()` * - `count()` * - `max()` * - `min()` * - `sum()` * * To filter grouped results, use the `having()` method. * * > **Notes:** * > - Aggregations can only be used on collections you have created. They cannot be used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * > - You can only call the `group()` method once per aggregate query. * @public * @documentationMaturity preview * @param field - Field or fields to group on. * @requiredField field * @returns `WixDataAggregate` object representing the refined aggregation. */ group(...field: string[]): WixDataAggregate; /** * Filters out groups from being returned from an aggregation. * * The `having()` method refines a `WixDataAggregate` so that it only * includes groups from the aggregate's grouping which match the specified * filter criteria. * * To create a filter, use the wix-data `filter()` method. * * Filtering using `having()` takes place after grouping is performed on the * aggregation. To filter items before grouping, use the `filter()` method. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be used in [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param filter - Filter to use to filter out groups from being returned from the aggregation. * @requiredField filter * @returns `WixDataAggregate` object representing the refined aggregation. */ having(filter: WixDataFilter): WixDataAggregate; /** * Limits the number of items or groups the aggregation returns. * * The `limit()` method defines the number of results an aggregation returns in each * page. Only one page of results is retrieved at a time. The `next()` * method is used to navigate the pages of a query result. * * By default, `limit` is set to `50`. * * The maximum value that `limit()` can accept is `1000`. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param limit - Number of items or groups to return. * @requiredField limit * @returns `WixDataAggregate` object representing the refined aggregation. */ limit(limit: number): WixDataAggregate; /** * Sets the number of items or groups to skip before returning aggregation results. * * The `skip()` method defines the number of results to skip in the aggregation * results before returning new aggregation results. * * For example, if you perform an aggregation on a collection and 10 groups match * your aggregation, but you set `skip` to 3, the results returned will skip * the first 3 groups that match and return the 4th through 10th items. * * By default, `skip` is set to 0. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be * > used on [Wix app collections](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections). * @public * @documentationMaturity preview * @param skip - Number of items or groups to skip in the aggregation results before returning the results. * @requiredField skip * @returns `WixDataAggregate` object representing the refined aggregation. */ skip(skip: number): WixDataAggregate; /** * Adds a sort to a query or sort, sorting by the specified fields in descending order. * * The `descending()` method refines this query to sort in descending order of the specified fields. If you * specify more than one field, descending() sorts the results in descending order by each field in the order * they are listed. * * You can sort the following types: * * Number: Sorts numerically. * - Date: Sorts by date and time. * - String: Sorts lexicographically, so `"abc"` comes before `"XYZ"`. * - Reference: Compares by the ID of the referenced item as a String. * * If a field contains a number as a String, that value is sorted alphabetically and not numerically. Items * that do not have a value for the specified sort field are ranked lowest. * * > **Note**: Aggregations can only be used on collections you have created. They cannot be used on [Wix app collections](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections). * @public * @documentationMaturity preview * @param fields - Fields to sort by. * @requiredField fields * @returns Refined query. */ descending(...fields: string[]): WixDataAggregate; descending(fields: string[]): WixDataAggregate; descending(...fields: any): WixDataAggregate; /** * Adds a sort to a query or sort, sorting by the specified fields in ascending order. * * The `ascending()` method refines this query in ascending order of the specified fields. If you specify more * than one field, `ascending()` sorts the results in ascending order by each field in the order they are listed. * * You can sort the following types: * - Number: Sorts numerically. * - Date: Sorts by date and time. * - String: Sorts lexicographically, so `"abc"` comes after `"XYZ"`. * - Reference: Compares by the ID of the referenced item as a String. * * If a field contains a number as a String, that value is sorted alphabetically and not numerically. * Items that do not have a value for the specified sort field are ranked lowest. * * > **Note**: Aggregations can only be used on collections you have created. They cannot be used on [Wix app collections](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections). * @public * @documentationMaturity preview * @param fields - Fields to sort by. * @requiredField fields * @returns Refined query. */ ascending(...fields: string[]): WixDataAggregate; ascending(fields: string[]): WixDataAggregate; ascending(...fields: any): WixDataAggregate; /** * Runs the aggregation and returns the results. * * The `run()` method returns a Promise that resolves to the results found * by the aggregation and some information about the results. * * > **Note:** Aggregations can only be used on collections you have created. They cannot be * > used on [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code). * @public * @documentationMaturity preview * @param options - Options to use when running an aggregation. * @returns Promise that resolves to the results of the aggregation. */ run(options?: WixDataAggregateOptions): Promise>>; } //# sourceMappingURL=WixDataAggregate.d.ts.map