{"id":37006651,"url":"https://github.com/xtompie/dao","last_synced_at":"2026-01-14T00:45:46.631Z","repository":{"id":58077565,"uuid":"529891565","full_name":"xtompie/dao","owner":"xtompie","description":null,"archived":false,"fork":false,"pushed_at":"2025-12-10T07:37:21.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-10T09:52:29.238Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xtompie.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-08-28T14:49:25.000Z","updated_at":"2025-12-10T07:37:24.000Z","dependencies_parsed_at":"2024-08-21T23:23:41.854Z","dependency_job_id":"bfa18eaa-9883-4775-9653-ac98bbce2ce2","html_url":"https://github.com/xtompie/dao","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"56bc13b9b2e088ec8af1500da77c9cf842eeb2eb"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/xtompie/dao","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fdao","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fdao/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fdao/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fdao/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtompie","download_url":"https://codeload.github.com/xtompie/dao/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtompie%2Fdao/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406535,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":[],"created_at":"2026-01-14T00:45:45.986Z","updated_at":"2026-01-14T00:45:46.625Z","avatar_url":"https://github.com/xtompie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DAO\n\nDAO - Data Access Object - wrapper over SQL\n\n```php\n/** @var Xtompie\\Dao\\Dao $dao */\n$dao-\u003einsert('user', ['email' =\u003e 'john.doe@exmaple.com', 'created_at' =\u003e time()]);\n$records = $dao-\u003equery(['select' =\u003e '*', 'from' =\u003e 'user', 'limit' =\u003e 10]);\n```\n\n- [DAO](#dao)\n  - [Requiments](#requiments)\n  - [Installation](#installation)\n  - [Docs](#docs)\n    - [Createing Dao instance](#createing-dao-instance)\n    - [Read](#read)\n    - [Read from one table](#read-from-one-table)\n    - [Write](#write)\n    - [Transaction](#transaction)\n    - [Extends AQL](#extends-aql)\n\n## Requiments\n\nPHP \u003e= 8.0\n\n## Installation\n\nUsing [composer](https://getcomposer.org/)\n\n```\ncomposer require xtompie/dao\n```\n\n## Docs\n\n### Createing Dao instance\n\n```php\nuse PDO;\nuse Xtompie\\Aql\\Aql;\nuse Xtompie\\Aql\\PostgreSQLPlatform;\nuse Xtompie\\Dao\\Dao;\n\n$dao = new Dao(\n    adapter: new PdoAdapter(pdo: new PDO('pgsql:host=localhost;dbname=test', 'postgres')),\n    aql: new Aql(platform: new PostgreSQLPlatform()),\n);\n```\n\nAvailable bulid-in adapters `Xtompie\\Dao\\Adapter`:\n\n- `Xtompie\\Dao\\DoctrineAdapter`\n- `Xtompie\\Dao\\PdoAdapter`\n\nUses [AQL](https://github.com/xtompie/aql) format to build sql queries.\n\n\n### Read\n\n```php\nclass Dao\n{\n    public function query(array $query): array {}\n    // returns all selected rows\n\n    public function first(array $query): ?array {}\n    // return first selected row or null\n\n    public function val(array $query): mixed {}\n    // return first field from first selected row or null\n\n    public function any(array $query): bool {}\n    // return true if there is any data for given query else false\n\n    public function count(array $query): int {}\n    // returns number of selected rows, by default uses `COUNT(*)`\n\n    public function stream(array $query): Generator {}\n    // yield records\n}\n```\n\n### Read from one table\n\n```php\nclass Dao\n{\n    public function records(string $table, ?array $where, ?string $order = null, ?int $offset = null, ?int $limit = null): array {}\n    // similiar to `query`\n\n    public function record(string $table, ?array $where = null, ?string $order = null, ?int $offset = null): ?array {}\n    // similar to `first`\n\n    public function amount(string $table, ?array $where = null, ?string $group = null): int {}\n    // similiar to `count`\n\n    public function exists(string $table, array $where): bool {}\n    // similiar to `any`\n\n    public function streamRecords(string $table, ?array $where = null, ?string $order = null, ?int $offset = null, ?int $limit = null): Generator\n    // yield records\n\n}\n```\n\n### Write\n\n```php\nclass Dao\n{\n    public function command(array $command): int {}\n\n    public function insert(string $table, array $values): int {}\n\n    public function insertBulk(string $table, array $bluk): int {}\n\n    public function update(string $table, array $set, array $where): int {}\n\n    public function upsert(string $table, array $set, array $where): int {}\n\n    public function delete(string $table, array $where): int {}\n}\n```\n\nEach method returns the number of affected rows\n\n### Transaction\n\n```php\nclass Dao\n{\n    public function transaction(callable $callback) {}\n    // run callback in transaction\n}\n```\n\n### Extends AQL\n\n\n```php\n\nnamespace App\\Shared\\Dao;\n\nuse Xtompie\\Dao\\Dao as BaseDao;\n\ninterface Paging\n{\n    public function limit(): int;\n    public function offset(): int;\n}\n\nclass Dao extends BaseDao\n{\n    public function aql(array $aql): array\n    {\n        if (isset($aql['paging'])) {\n            $paging = $aql['paging'];\n            unset($aql['paging']);\n            if (!$paging instanceof Paging) {\n                throw new \\Exception();\n            }\n            $aql['offset'] =\u003e $paging-\u003eoffset();\n            $aql['limit'] =\u003e $paging-\u003elimit();\n        }\n        return parent::aql($aql);\n    }\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtompie%2Fdao","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtompie%2Fdao","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtompie%2Fdao/lists"}