{"id":50759051,"url":"https://github.com/kraz/read-model","last_synced_at":"2026-06-11T08:01:58.293Z","repository":{"id":354382975,"uuid":"1222716285","full_name":"kraz/read-model","owner":"kraz","description":"Read Model Domain implementation","archived":false,"fork":false,"pushed_at":"2026-05-06T16:05:01.000Z","size":190,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-06T17:41:34.598Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kraz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-27T16:29:53.000Z","updated_at":"2026-05-06T16:06:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/kraz/read-model","commit_stats":null,"previous_names":["kraz/read-model"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kraz/read-model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fread-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fread-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fread-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fread-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kraz","download_url":"https://codeload.github.com/kraz/read-model/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kraz%2Fread-model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34188272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2026-06-11T08:01:54.951Z","updated_at":"2026-06-11T08:01:58.288Z","avatar_url":"https://github.com/kraz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Read Model\n\n[![CI](https://github.com/kraz/read-model/actions/workflows/ci.yml/badge.svg)](https://github.com/kraz/read-model/actions/workflows/ci.yml)\n[![Packagist Version](https://img.shields.io/packagist/v/kraz/read-model)](https://packagist.org/packages/kraz/read-model)\n[![GitHub license](https://img.shields.io/github/license/kraz/read-model)](LICENSE)\n\nA domain-first Read Model library that provides a uniform API for querying read-only data from multiple backends. Define your query logic once; plug in Doctrine ORM, raw SQL, JSON-RPC APIs, or Elasticsearch — or use the built-in in-memory implementation for fast, dependency-free tests.\n\n## Installation\n\n```bash\ncomposer require kraz/read-model\n```\n\n## Additional packages\n\nInstall any of the following packages which matches your infrastructure requirements:\n\n| Package                                                                             | Description                                                    |\n|-------------------------------------------------------------------------------------|----------------------------------------------------------------|\n| [kraz/read-model-doctrine](https://github.com/kraz/read-model-doctrine)             | Doctrine ORM \u0026 raw SQL backend                                 |\n| [kraz/read-model-json-rpc](https://github.com/kraz/read-model-json-rpc)             | JSON-RPC 2.0 API backend _(expects read-model exposed as API)_ |\n| [kraz/read-model-elastic-search](https://github.com/kraz/read-model-elastic-search) | Elasticsearch backend                                          |\n\n## Documentation\n\nFull documentation lives in the [`docs/`](docs/) directory:\n\n- [Getting Started](docs/getting-started.md)\n- [Core Concepts](docs/core-concepts.md)\n- [Filtering \u0026 Sorting](docs/filtering.md)\n- [Pagination \u0026 Limits](docs/pagination.md)\n- [Specifications](docs/specifications.md)\n- [Testing](docs/testing.md)\n- [Doctrine Backend](docs/doctrine.md)\n- [JSON-RPC Backend](docs/json-rpc.md)\n- [Elasticsearch Backend](docs/elasticsearch.md)\n\n## Example usage\n\n### Raw SQL\n\n```php\nuse Kraz\\ReadModel\\ReadDataProviderInterface;\nuse Kraz\\ReadModelDoctrine\\DataSource;\nuse Kraz\\ReadModelDoctrine\\DataSourceBuilder;\nuse Kraz\\ReadModelDoctrine\\RawQueryReadDataProvider;\n\nclass ProductsReadModel implements ReadDataProviderInterface\n{\n    use RawQueryReadDataProvider;\n\n    public function __construct(private readonly Connection $connection) {}\n\n    protected function createDataSource(): DataSource\n    {\n        return new DataSourceBuilder()\n            -\u003ewithData(\u003c\u003c\u003c'SQL'\n                SELECT r.* FROM (\n                    SELECT p.id, p.name, p.price, c.name AS category\n                    FROM product p\n                    JOIN category c ON c.id = p.category_id\n                    WHERE p.deleted_at IS NULL\n                ) r\n                /*#WHERE#*/\n                /*#ORDERBY_B#*/ORDER BY r.id ASC/*#ORDERBY_E#*/\n            SQL)\n            -\u003ecreate($this-\u003econnection);\n    }    \n}\n```\n\nThe `/*#WHERE#*/` and `/*#ORDERBY#*/` markers are replaced automatically with generated SQL when filters and sorts are applied. When nothing is applied they are removed cleanly.\n\n### ORM QueryBuilder\n\n```php\nuse Kraz\\ReadModelDoctrine\\DoctrineReadDataProvider;\n\nclass ProductsReadModel implements ReadDataProviderInterface\n{\n    use DoctrineReadDataProvider;\n\n    public function __construct(private EntityManagerInterface $em) {}\n\n    protected function createDataSource(): DataSource\n    {\n        $qb = $this-\u003eem-\u003ecreateQueryBuilder()\n            -\u003eselect('r.id, r.name, r.price')\n            -\u003efrom(Product::class, 'r');\n\n        return new DataSource($qb);\n    }\n}\n```\n\n### Querying\n\nBoth styles share the same query API:\n\n```php\n// Filters and sorting\n$products = $readModel\n    -\u003ewithQueryExpression(\n        $readModel-\u003eqry()\n            -\u003eandWhere($readModel-\u003eexpr()-\u003egreaterThan('price', 10))\n            -\u003eandWhere($readModel-\u003eexpr()-\u003eequalTo('category', 'tools'))\n            -\u003esortBy('name', SortExpression::DIR_ASC)\n    )\n    -\u003ewithPagination(page: 1, itemsPerPage: 20)\n    -\u003egetResult();\n\n// $result-\u003edata   — items on this page\n// $result-\u003epage   — current page\n// $result-\u003etotal  — total matching rows\n```\n\n_The query expression is serializable and can be stored and/or transferred as needed._\n\n## Acknowledgements\n\nThe library uses source code from [Doctrine Collections](https://github.com/doctrine/collections) which was modified to meet the required behavior.\n\n## License\n\nThis library is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkraz%2Fread-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkraz%2Fread-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkraz%2Fread-model/lists"}