{"id":16423375,"url":"https://github.com/ngekoding/codeigniter-api-query-parser","last_synced_at":"2025-10-26T22:31:45.302Z","repository":{"id":62308442,"uuid":"559124807","full_name":"ngekoding/codeigniter-api-query-parser","owner":"ngekoding","description":"A query parser for REST-APIs based on CodeIgniter","archived":false,"fork":false,"pushed_at":"2023-06-13T14:13:42.000Z","size":12,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-01T00:51:08.145Z","etag":null,"topics":["codeigniter-library","codeigniter-query-parser","rest-api"],"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/ngekoding.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}},"created_at":"2022-10-29T06:07:10.000Z","updated_at":"2024-08-27T15:13:02.000Z","dependencies_parsed_at":"2023-01-21T00:16:56.746Z","dependency_job_id":null,"html_url":"https://github.com/ngekoding/codeigniter-api-query-parser","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcodeigniter-api-query-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcodeigniter-api-query-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcodeigniter-api-query-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngekoding%2Fcodeigniter-api-query-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngekoding","download_url":"https://codeload.github.com/ngekoding/codeigniter-api-query-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238408478,"owners_count":19467099,"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":["codeigniter-library","codeigniter-query-parser","rest-api"],"created_at":"2024-10-11T07:39:37.108Z","updated_at":"2025-10-26T22:31:40.033Z","avatar_url":"https://github.com/ngekoding.png","language":"PHP","readme":"# CodeIgniter API Query Parser\n\nSimple request query parameter parser for REST-APIs based on CodeIgniter framework. Works for both CodeIgniter 3 and CodeIgniter 4.\n\nInspired by [Lumen API Query Parser](https://github.com/ngabor84/lumen-api-query-parser)\n\n## Requirements\n\n- PHP 5.6 or above\n- CodeIgniter 3 or CodeIgniter 4\n- PHPSQLParser ^4.5\n\n## Installation\n\nYou just need to use composer and everything is done.\n\n```sh\ncomposer require ngekoding/codeigniter-api-query-parser\n```\n\n## Usage\n\nHere is the example for CodeIgniter 3 and CodeIgniter 4. Actually there is no different by the use of the library, just different how to create the query builder.\n\n### CodeIgniter 3 Example\n\n```php\n// CodeIgniter 3 Example\n\n// Get a query builder\n// Please note: we don't need to call -\u003eget() here\n$queryBuilder = $this-\u003edb-\u003eselect('p.*, c.name category')\n                    -\u003efrom('posts p')\n                    -\u003ejoin('categories c', 'c.id=p.category_id');\n\n/**\n * The first parameter is the query builder instance\n * and the second is the codeigniter version (3 or 4) \n */\n$queryParser = new \\Ngekoding\\CodeIgniterApiQueryParser\\QueryParser($queryBuilder);\n$result = $queryParser-\u003eapplyParams(); // done\n\nprint_r($result);\n```\n\nThe above example will output an array with `data` and `pagination`:\n\n```\nArray\n(\n    [data] =\u003e Array\n        (\n            [0] =\u003e ...\n            [1] =\u003e ...\n        )\n    [pagination] =\u003e Array\n        (\n            [current_page] =\u003e int\n            [per_page] =\u003e int\n            [from] =\u003e int\n            [to] =\u003e int\n            [total] =\u003e int\n            [last_page] =\u003e int\n            [links] =\u003e Array\n                (\n                    [first] =\u003e string\n                    [prev] =\u003e string or null\n                    [next] =\u003e string or null\n                    [last] =\u003e string\n                )\n        )\n)\n```\n\n### CodeIgniter 4 Example\n\nThe different only by the way to create the Query Builder.\n\n```php\n// CodeIgniter 4 Example\n\n$db = db_connect();\n$queryBuilder = $db-\u003efrom('posts p')\n                   -\u003eselect('p.*, c.name category')\n                   -\u003ejoin('categories c', 'c.id=p.category_id');\n\n$queryParser = new \\Ngekoding\\CodeIgniterApiQueryParser\\QueryParser($queryBuilder);\n$result = $queryParser-\u003eapplyParams(); // done\n\nprint_r($result);\n```\n\n## Query Syntax\n\n### Filtering\n\nQ: /users?filter[]=name:ct:admin    \nR: will return the array of the users whose names contains the `admin` string\n\n**Available filter options**\n\n| Operator      | Description           | Example |\n| ------------- | --------------------- | ------- |\n| ct            | String contains       | name:ct:Peter |\n| nct           | String NOT contains   | name:nct:Peter |\n| sw            | String starts with    | username:sw:admin |\n| ew            | String ends with      | email:ew:gmail.com |\n| eq            | Equals                | level:eq:3 |\n| ne            | Not equals            | level:ne:4 |\n| gt            | Greater than          | level:gt:2 |\n| ge            | Greater than or equal | level:ge:3 |\n| lt            | Less than             | level:lt:4 |\n| le            | Less than or equal    | level:le:3 |\n| in            | In array              | level:in:1,2,3 |\n\n### Sorting\n\nQ: /users?sort[]=name:ASC   \nR: will return the array of the users sort by their `names` ascending\n\n### Pagination\n\nQ: /users?limit=10\u0026page=3   \nR: will return a part of the array of the users (from the 21st to 30th)\n\n## Column Alias\n\nWhen working with SQL expression in selecting data or using join with ambiguous column name, **the library automatically will try to find the original column name or its expression** to use for the filter feature. But, you can still manually define the column alias for better use, expecially to resolving the ambiguous column name when using join.\n\nFor example, joining posts table with categories table in the example above will return an `id` from the posts table. So, when we try to get the data with `id` 1, 2 or 3 (`SQL WHERE IN`) using filter[]=id:in:1,2,3 we get the ambiguous column error.\n\nHere is the **column alias** to solve it.\n\n```php\n$queryParser = new \\Ngekoding\\CodeIgniterApiQueryParser\\QueryParser($queryBuilder);\n\n// Tell that the `id` is `p.id` (posts table id)\n$queryParser-\u003eaddColumnAlias('id', 'p.id');\n\n// Or add multiple aliases at once\n$queryParser-\u003eaddColumnAlias([\n    'id' =\u003e 'p.id',\n    'title' =\u003e 'p.title'\n]);\n\n$result = $queryParser-\u003eapplyParams(); // done\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngekoding%2Fcodeigniter-api-query-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngekoding%2Fcodeigniter-api-query-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngekoding%2Fcodeigniter-api-query-parser/lists"}