{"id":15030071,"url":"https://github.com/xp-forge/aggregate","last_synced_at":"2026-02-06T20:02:24.249Z","repository":{"id":57084815,"uuid":"201767275","full_name":"xp-forge/aggregate","owner":"xp-forge","description":"Aggregate data on lists","archived":false,"fork":false,"pushed_at":"2024-03-24T10:19:09.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-26T11:46:27.124Z","etag":null,"topics":["aggregate","n-plus-1","php7","php8","sql","xp-framework"],"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/xp-forge.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","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":"2019-08-11T13:19:55.000Z","updated_at":"2022-02-27T18:30:18.000Z","dependencies_parsed_at":"2024-09-28T20:40:32.356Z","dependency_job_id":"481a1d3f-9198-4e95-bb32-3a8585db22b0","html_url":"https://github.com/xp-forge/aggregate","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/xp-forge/aggregate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Faggregate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Faggregate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Faggregate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Faggregate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-forge","download_url":"https://codeload.github.com/xp-forge/aggregate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Faggregate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29174332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T19:56:27.068Z","status":"ssl_error","status_checked_at":"2026-02-06T19:56:18.934Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["aggregate","n-plus-1","php7","php8","sql","xp-framework"],"created_at":"2024-09-24T20:12:22.048Z","updated_at":"2026-02-06T20:02:24.202Z","avatar_url":"https://github.com/xp-forge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Aggregate data on lists\n=======================\n\n[![Build status on GitHub](https://github.com/xp-forge/aggregate/workflows/Tests/badge.svg)](https://github.com/xp-forge/aggregate/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_0plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-forge/aggregate/version.png)](https://packagist.org/packages/xp-forge/aggregate)\n\nCircumvents [`n + 1`-problems](https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping) often occuring with SQL queries. \n\nExample\n-------\nThe following shows how the *Aggregate* class works, firing only **two** SQL queries instead of creating an `n + 1`-problem.\n\n```php\nuse util\\data\\Aggregate;\nuse rdbms\\DriverManager;\n\n$conn= DriverManager::getConnection($dsn);\n$posts= Aggregate::of($conn-\u003equery('select * from post'))\n  -\u003ecollect('comments', ['id' =\u003e 'post_id'], function($ids) use($conn) {\n    return $conn-\u003equery('select * from comment where post_id in (%d)', $ids);\n  })\n  -\u003eall()\n;\n\n// [\n//   [\n//     'id'       =\u003e 1,\n//     'body'     =\u003e 'The first post',\n//     'comments' =\u003e [\n//        ['id' =\u003e 1, 'post_id' =\u003e 1, 'body' =\u003e 'Re #1: The first post'],\n//        ['id' =\u003e 2, 'post_id' =\u003e 1, 'body' =\u003e 'Re #2: The first post'],\n//     ]\n//   ],\n//   [\n//     'id'       =\u003e 2,\n//     'body'     =\u003e 'The second post',\n//     'comments' =\u003e [\n//        ['id' =\u003e 3, 'post_id' =\u003e 2, 'body' =\u003e 'Re #1: The second post'],\n//     ]\n//   ],\n// ]\n``` ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Faggregate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-forge%2Faggregate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Faggregate/lists"}