{"id":14966306,"url":"https://github.com/yiisoft/data-db","last_synced_at":"2025-10-19T09:31:13.291Z","repository":{"id":38818232,"uuid":"412468667","full_name":"yiisoft/data-db","owner":"yiisoft","description":"Database adapter for data interfaces","archived":false,"fork":false,"pushed_at":"2024-05-21T15:09:16.000Z","size":132,"stargazers_count":14,"open_issues_count":7,"forks_count":4,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-05-23T01:06:45.072Z","etag":null,"topics":["data","database","db","hacktoberfest","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2021-10-01T13:02:52.000Z","updated_at":"2024-05-28T17:13:03.925Z","dependencies_parsed_at":"2023-02-09T20:30:58.733Z","dependency_job_id":"fc735434-7500-4d59-8b0c-fbb36e82108f","html_url":"https://github.com/yiisoft/data-db","commit_stats":{"total_commits":53,"total_committers":12,"mean_commits":4.416666666666667,"dds":0.8113207547169812,"last_synced_commit":"299d16b0fe2ed96a4a759b70eb99ac9d9aa60818"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":"yiisoft/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fdata-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fdata-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fdata-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fdata-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/data-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219865475,"owners_count":16554151,"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":["data","database","db","hacktoberfest","yii3"],"created_at":"2024-09-24T13:36:11.781Z","updated_at":"2025-10-19T09:31:13.279Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Data DB\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/data-db/v)](https://packagist.org/packages/yiisoft/data-db)\n[![Total Downloads](https://poser.pugx.org/yiisoft/data-db/downloads)](https://packagist.org/packages/yiisoft/data-db)\n[![Code Coverage](https://codecov.io/gh/yiisoft/data-db/graph/badge.svg?token=9qlfGa4kI1)](https://codecov.io/gh/yiisoft/data-db)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdata-db%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/data-db/master)\n[![static analysis](https://github.com/yiisoft/data-db/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/data-db/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/data-db/coverage.svg)](https://shepherd.dev/github/yiisoft/data-db)\n\nThe package provides `Yiisoft\\Db\\Query\\Query` bindings for generic data abstractions.\n\nDetailed build statuses:\n\n| RDBMS                | Status                                                                                                                                                            |\n|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| SQLite               | [![SQLite status](https://github.com/yiisoft/data-db/workflows/sqlite/badge.svg)](https://github.com/yiisoft/data-db/actions?query=workflow%3Asqlite)             |\n| MySQL                | [![MYSQL status](https://github.com/yiisoft/data-db/workflows/mysql/badge.svg)](https://github.com/yiisoft/data-db/actions?query=workflow%3Amysql)                |\n| PostgreSQL           | [![PostgreSQL status](https://github.com/yiisoft/data-db/workflows/pgsql/badge.svg)](https://github.com/yiisoft/data-db/actions?query=workflow%3Apgsql)           |\n| Microsoft SQL Server | [![Microsoft SQL Server status](https://github.com/yiisoft/data-db/workflows/mssql/badge.svg)](https://github.com/yiisoft/data-db/actions?query=workflow%3Amssql) |\n| Oracle               | [![Oracle status](https://github.com/yiisoft/data-db/workflows/oracle/badge.svg)](https://github.com/yiisoft/data-db/actions?query=workflow%3Aoracle)             |\n\n## Requirements\n\n- PHP 8.1 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/data-db\n```\n\n## General usage\n\n```php\nuse Yiisoft\\Data\\Db\\Filter\\All;\nuse Yiisoft\\Data\\Db\\Filter\\Equals;\nuse Yiisoft\\Data\\Db\\QueryDataReader;\n\n$typeId    = filter_input(INPUT_GET, 'type_id', FILTER_VALIDATE_INT);\n$countryId = filter_input(INPUT_GET, 'country_id', FILTER_VALIDATE_INT);\n$parentId  = filter_input(INPUT_GET, 'parent_id', FILTER_VALIDATE_INT);\n\n// OR\n// $typeId    = $_GET['type_id'] ?? null;\n// $countryId = $_GET['country_id'] ?? null;\n// $parentId  = $_GET['parent_id'] ?? null;\n\n// OR\n// $params = $request-\u003egetQueryParams();\n// $typeId    = $params['type_id'] ?? null;\n// $countryId = $params['country_id'] ?? null;\n// $parentId  = $params['parent_id'] ?? null;\n\n// OR same with ArrayHelper::getValue();\n\n\n$query = $arFactory-\u003ecreateQueryTo(AR::class);\n\n$filter = new All(\n    (new Equals('type_id', $typeId)),\n    (new Equals('country_id', $countryId)),\n    (new Equals('parent_id', $parentId))\n);\n\n$dataReader = (new QueryDataReader($query))\n            -\u003ewithFilter($filter);\n```\n\nIf $typeId, $countryId and $parentId equals NULL that generate SQL like:\n\n```sql\nSELECT AR::tableName().* FROM AR::tableName() WHERE type_id IS NULL AND country_id IS NULL AND parent_id IS NULL\n```\n\nIf we want ignore not existing arguments (i.e. not set in $_GET/queryParams), we can use withIgnoreNull(true) method:\n\n```php\n$typeId    = 1;\n$countryId = null;\n$parentId  = null;\n\n$filter = new All(\n    (new Equals('type_id', $typeId))-\u003ewithIgnoreNull(true),\n    (new Equals('country_id', $countryId))-\u003ewithIgnoreNull(true),\n    (new Equals('parent_id', $parentId))-\u003ewithIgnoreNull(true)\n);\n\n$dataReader = (new QueryDataReader($query))\n            -\u003ewithFilter($filter);\n```\n\nThat generate SQL like:\n\n```sql\nSELECT AR::tableName().* FROM AR::tableName() WHERE type_id = 1\n```\n\nIf query joins several tables with same column name, pass table name as 3-th filter arguments\n\n```php\n$equalsTableOne = (new Equals('id', 1, 'table_one'))-\u003ewithIgnoreNull(true);\n$equalsTableTwo = (new Equals('id', 100, 'table_two'))-\u003ewithIgnoreNull(true);\n```\n\n## Current filters/processors\n\n### Compare\n\n- Equals - =\n- NotEquals - !=\n- GreaterThan - \u003e\n- GreaterThanOrEqual - \u003e=\n- In\n- LessThan - \u003c\n- LessThanOrEqual - \u003c=\n- Not\n- Like\\ILIke\n- Exists\n- Between\n\n#### Filter \"Like\" or \"ILike\"\n\nThis filters has methods `withBoth`, `withoutBoth`, `withStart`, `withoutStart`, `withEnd`, `withoutEnd`\n\n```php\n$filter = new Like('column', 'value');\n$dataReader = (new QueryDataReader($query))-\u003ewithFilter($filter);\n//column LIKE '%value%'\n\n$filter = (new Like('column', 'value'))-\u003ewithoutStart();\n$dataReader = (new QueryDataReader($query))-\u003ewithFilter($filter);\n//column LIKE 'value%'\n\n$filter = (new Like('column', 'value'))-\u003ewithoutEnd();\n$dataReader = (new QueryDataReader($query))-\u003ewithFilter($filter);\n//column LIKE '%value'\n```\n\n#### Filter \"Exists\"\n\nTakes only one argument with type of`Yiisoft\\Db\\Query\\Query`\n\n#### Filter \"Not\"\n\nTakes only one argument with type of`Yiisoft\\Data\\Reader\\Filter\\FilterInterface`\n\n### Group\n\n- All - and\n- Any - or\n\n## Documentation\n\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for\nthat. You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Data DB is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fdata-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fdata-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fdata-db/lists"}