{"id":15150680,"url":"https://github.com/arraypress/edd-extended-query","last_synced_at":"2026-02-04T14:02:23.360Z","repository":{"id":221243689,"uuid":"753839545","full_name":"arraypress/edd-extended-query","owner":"arraypress","description":"Enhances Easy Digital Downloads database querying with SQL aggregate functions (SUM, AVG, MAX, etc.) and arithmetic operations.","archived":false,"fork":false,"pushed_at":"2024-05-20T19:55:09.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T16:43:51.410Z","etag":null,"topics":["easy-digital-downloads","library","wordpress-development","wordpress-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arraypress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-06T22:11:21.000Z","updated_at":"2024-05-20T19:55:12.000Z","dependencies_parsed_at":"2024-02-06T23:04:01.807Z","dependency_job_id":"0fe541fc-3825-48cc-8723-b452e221b228","html_url":"https://github.com/arraypress/edd-extended-query","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.16666666666666663","last_synced_commit":"5ecd3a0a7fbacdebf416dbac683c9b4ac74fe435"},"previous_names":["arraypress/edd-extended-query"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/arraypress/edd-extended-query","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-extended-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-extended-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-extended-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-extended-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arraypress","download_url":"https://codeload.github.com/arraypress/edd-extended-query/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-extended-query/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262941544,"owners_count":23388149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["easy-digital-downloads","library","wordpress-development","wordpress-plugin"],"created_at":"2024-09-26T14:23:54.813Z","updated_at":"2026-02-04T14:02:23.287Z","avatar_url":"https://github.com/arraypress.png","language":"PHP","readme":"# Easy Digital Downloads Extended Query Class\n\nThis class significantly enhances\nthe [Easy Digital Downloads (EDD)](https://github.com/awesomemotive/easy-digital-downloads) querying capabilities by\nintroducing the ability to\nperform advanced SQL aggregate operations such as SUM, AVG, MAX, MIN, and more. Designed to complement the ORM\nfunctionality provided by [BerlinDB](https://github.com/berlindb/core) through the base EDD Query Class, it facilitates\ncomplex mathematical queries,\nenriching\ndata analysis and manipulation tasks.\n\n## Features ##\n\n* **Advanced SQL Aggregation:** Incorporates SQL aggregate functions such as SUM, AVG, MAX, MIN, GROUP_CONCAT, STDDEV,\n  VAR_SAMP, and VAR_POP into EDD queries, enabling in-depth data summarization and analysis.\n\n* **Arithmetic Operation Support:** Allows for direct arithmetic operations within queries using operators like\n  addition, subtraction, multiplication, and division, facilitating complex calculations directly within database\n  queries.\n\n* **Numerical Column Type Support:** Provides a comprehensive list of supported numeric SQL column types for precise\n  data handling, including tinyint, smallint, mediumint, int, bigint, decimal, numeric, float, double, bit, and real.\n\n* **Enhanced Grouping Capabilities:** Enables the use of GROUP BY clauses to aggregate multiple sums (SUM), averages (\n  AVG), and other calculations for distinct fields in a single query request. This feature allows for streamlined data\n  grouping and summarization, providing powerful insights into datasets with minimal overhead.\n\n* **Comprehensive Documentation:** Accompanied by detailed documentation and usage examples, making it straightforward\n  for developers to implement and leverage its advanced features in their projects.\n\n## Minimum Requirements ##\n\n* **PHP:** 7.4\n\n## Installation ##\n\nExtended Query is a developer library, not a plugin, which means you need to include it somewhere in your own\nproject.\n\nYou can use Composer:\n\n```bash\ncomposer require arraypress/edd-extended-query\n```\n\n#### Basic Usage\n\n```php\n// Require the Composer autoloader to enable class autoloading.\nrequire_once __DIR__ . '/vendor/autoload.php';\n```\n\nThis class is specifically designed to serve as a foundational base, enabling developers to extend and tailor their own\ncustom query classes according to specific data retrieval and manipulation needs within their Easy Digital Downloads (\nEDD) extensions or related projects. By inheriting from the `Extended_Query` class, you can create specialized query\nhandlers for different aspects of your application, such as managing custom task requests, with ease and precision.\n\nHere's an illustrative example of how to extend the Extended_Query class to construct a custom query handler for task\nrequests.\n\n```php\nuse ArrayPress\\Utils\\EDD\\Database\\Extended_Query;\n\n/**\n * Extends the `Extended_Query` class to manage custom task requests.\n */\nclass Task_Requests extends Extended_Query {\n\n    /**\n     * Database table name.\n     *\n     * @var string\n     */\n    protected $table_name = 'task_requests';\n\n    /**\n     * Database table alias.\n     *\n     * @var string\n     */\n    protected $table_alias = 'tr';\n\n    /**\n     * Schema class for database structure.\n     *\n     * @var string\n     */\n    protected $table_schema = '\\\\ArrayPress\\\\EDD\\\\Tasks\\\\Database\\\\Schemas\\\\Task_Requests';\n\n    /**\n     * Singular item name.\n     *\n     * @var string\n     */\n    protected $item_name = 'task_request';\n\n    /**\n     * Plural items name.\n     *\n     * @var string\n     */\n    protected $item_name_plural = 'task_requests';\n\n    /**\n     * Class for item objects.\n     *\n     * @var string\n     */\n    protected $item_shape = '\\\\ArrayPress\\\\EDD\\\\Tasks\\\\Objects\\\\Task_Request';\n\n    /**\n     * Cache group name.\n     *\n     * @var string\n     */\n    protected $cache_group = 'task_requests';\n\n    /**\n     * Constructor to set up query parameters.\n     *\n     * @param array|string $query Query parameters.\n     */\n    public function __construct( $query = [] ) {\n        parent::__construct( $query );\n    }\n}\n```\n\n## Example 1: Simple Aggregate Query\n\nCalculating the total sales amount for a specific product ID.\n\n```php\n$query = new Task_Transactions([\n    'function'   =\u003e 'SUM',\n    'fields'     =\u003e 'amount',\n    'product_id' =\u003e 123 // Assuming product ID is 123\n]);\n\n$total_sales = $query-\u003eget_result();\n```\n\n##### Supported Aggregate Functions\n\n* **SUM:** Calculates the sum of a set of values. Useful for finding total amounts, like total sales.\n* **AVG:** Calculates the average of a set of values. Ideal for determining the average transaction size or average\n  discount applied.\n* **MAX:** Finds the maximum value in a set of values. Can be used to find the largest transaction amount or highest\n  discount.\n* **MIN:** Finds the minimum value in a set of values. Useful for identifying the smallest transaction or lowest price\n  item sold.\n* **GROUP_CONCAT:** Concatenates values from multiple rows into a single string. This is particularly useful for\n  aggregating text-based data, such as combining tags or categories.\n* **STDDEV:** Calculates the standard deviation of a set of values, which helps in understanding the variance in data\n  points, like transaction amounts.\n* **VAR_SAMP:** Calculates the sample variance of a set of values, providing insight into the variability of a sample\n  from a population.\n* **VAR_POP:** Calculates the population variance of a set of values, offering a view into the variability of the entire\n  population.\n\n## Example 2: Aggregate Function with Arithmetic Operation\n\nCalculating the total profit by subtracting tax from sales amounts.\n\n```php\n$query = new Task_Transactions([\n    'function' =\u003e 'SUM',\n    'fields'   =\u003e ['amount', 'tax'],\n    'operator' =\u003e '-' // Subtracting discount from amount\n]);\n\n$total_profit = $query-\u003eget_result();\n```\n\n##### Supported Aggregate Functions\n\n+, -, *, /, %\n\n## Example 3: Grouping by Product ID\n\nCalculating total sales amount grouped by product ID.\n\n```php\n$query = new Task_Transactions([\n    'function' =\u003e 'SUM',\n    'fields'   =\u003e 'amount',\n    'groupby'  =\u003e ['product_id']\n]);\n\n$sales_by_product = $query-\u003eget_result();\n```\n\n## Example 4: Grouping by Multiple Columns\n\nCalculating total sales amount grouped by product ID.\n\n```php\n$query = new Task_Transactions([\n    'function' =\u003e 'AVG',\n    'fields'   =\u003e ['amount', 'discount']\n    'groupby'  =\u003e ['product_id']\n]);\n\n$sales_by_product = $query-\u003eget_result();\n```\n\n## Contributions\n\nContributions to this library are highly appreciated. Raise issues on GitHub or submit pull requests for bug\nfixes or new features. Share feedback and suggestions for improvements.\n\n## License: GPLv2 or later\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public\nLicense as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later\nversion.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\nwarranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fedd-extended-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farraypress%2Fedd-extended-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fedd-extended-query/lists"}