{"id":16229217,"url":"https://github.com/morris/dop","last_synced_at":"2025-03-19T13:31:40.849Z","repository":{"id":57019905,"uuid":"68929996","full_name":"morris/dop","owner":"morris","description":"An immutable API on top of PDO to compose and execute SQL statements","archived":false,"fork":false,"pushed_at":"2020-05-09T16:27:29.000Z","size":86,"stargazers_count":16,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T07:44:25.180Z","etag":null,"topics":["immutable","pdo","php","sql"],"latest_commit_sha":null,"homepage":"","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/morris.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-22T14:35:02.000Z","updated_at":"2024-09-02T18:10:22.000Z","dependencies_parsed_at":"2022-08-22T20:31:20.989Z","dependency_job_id":null,"html_url":"https://github.com/morris/dop","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morris%2Fdop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morris%2Fdop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morris%2Fdop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morris%2Fdop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morris","download_url":"https://codeload.github.com/morris/dop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244434870,"owners_count":20452273,"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":["immutable","pdo","php","sql"],"created_at":"2024-10-10T12:57:43.101Z","updated_at":"2025-03-19T13:31:40.585Z","avatar_url":"https://github.com/morris.png","language":"PHP","readme":"# DOP\n\n[![Build Status](https://travis-ci.org/morris/dop.svg?branch=master)](https://travis-ci.org/morris/dop)\n[![Test Coverage](https://codeclimate.com/github/morris/dop/badges/coverage.svg)](https://codeclimate.com/github/morris/dop/coverage)\n\nDOP is an immutable API on top of [PDO](http://php.net/manual/en/book.pdo.php)\nto compose and execute SQL statements.\n\n- Extended parameters (`::param` and `??`) allow binding to arbitrary values like arrays, `null` and SQL fragments.\n- Provides helpers for writing common queries, e.g. selects, inserts, updates, deletes.\n- Tested with **SQLite, PostgreSQL, and MySQL.**\n\n## Installation\n\nDOP requires PHP \u003e= 5.3.0 and PDO.\nInstall via [composer](https://getcomposer.org/):\n\n```sh\ncomposer require morris/dop\n```\n\n## Usage\n\n```php\n// Connect to a database\n$pdo = new PDO('sqlite:blog.sqlite3');\n$dop = new Dop\\Connection($pdo);\n\n// Find posts by author IDs using DOP parametrization\n$authorIds = [1, 2, 3];\n$orderByTitle = $dop('ORDER BY title ASC');\n$posts = $dop(\n    'SELECT * FROM post WHERE author_id IN (??) ??',\n    [$authorIds, $orderByTitle]\n)-\u003efetchAll();\n\n// Find published posts using DOP helpers for common queries\n$posts = $dop-\u003equery('post')-\u003ewhere('is_published = ?', [1])-\u003efetchAll();\n\n// Get categorizations of posts using DOP's map function\n$categorizations = $dop(\n    'SELECT * FROM categorization WHERE post_id IN (??)',\n    [$dop-\u003emap($posts, 'id')]\n)-\u003efetchAll();\n\n// Find posts with more than 3 categorizations using a sub-query as a parameter\n$catCount = $dop('SELECT COUNT(*) FROM categorization WHERE post_id = post.id');\n$posts = $dop(\n    'SELECT * FROM post WHERE (::catCount) \u003e= 3',\n    ['catCount' =\u003e $catCount]\n)-\u003efetchAll();\n```\n\nInternally, `??` and `::named` parameters are resolved before statement preparation.\nNote that due to the current implementation using regular expressions,\nyou should *never* use quoted strings directly. Always use bound parameters.\n\n## Reference\n\nSee [API.md](API.md) for a complete API reference.\n\n## Contributors\n\n- [jayaddison](https://github.com/jayaddison)\n\nThanks!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorris%2Fdop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorris%2Fdop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorris%2Fdop/lists"}