{"id":41214964,"url":"https://github.com/phore/phore-unidb","last_synced_at":"2026-01-22T23:58:46.723Z","repository":{"id":57039235,"uuid":"418445170","full_name":"phore/phore-unidb","owner":"phore","description":"Unified DB Access","archived":false,"fork":false,"pushed_at":"2022-07-07T19:16:35.000Z","size":91,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T21:57:27.613Z","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/phore.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}},"created_at":"2021-10-18T10:09:46.000Z","updated_at":"2021-11-04T13:19:38.000Z","dependencies_parsed_at":"2022-08-23T23:30:57.021Z","dependency_job_id":null,"html_url":"https://github.com/phore/phore-unidb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/phore/phore-unidb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-unidb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-unidb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-unidb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-unidb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phore","download_url":"https://codeload.github.com/phore/phore-unidb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-unidb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28675280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T20:48:19.482Z","status":"ssl_error","status_checked_at":"2026-01-22T20:48:14.968Z","response_time":144,"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-22T23:58:43.970Z","updated_at":"2026-01-22T23:58:46.716Z","avatar_url":"https://github.com/phore.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phore-unidb\nUnified DB Access\n\nFeatures:\n- Easy to use thanks to [PHP8 Named Arguments](https://www.php.net/manual/en/functions.arguments.php) features\n- \n\n## Basic example\n\n```php\n// Setup table structure and driver\n$udb = new UniDb(\n    new SqliteDriver(new \\PDO(\"sqlite::memory:\")),\n    new Schema(\n        [\n            \"User\" =\u003e [\n                \"indexes\" =\u003e [\"user_name\"]\n            ]\n        ]\n    )\n);\n\n// Create the schema (if it does not already exist)\necho $udb-\u003ecreateSchema();\n\n// Select the 'User' Table\n$userTbl = $udb-\u003ewith(\"User\");\n\n// Insert two entities\n$userTbl-\u003einsert([\"user_id\"=\u003e\"user1\", \"user_name\" =\u003e \"Bob\"]);\n$userTbl-\u003einsert([\"user_id\"=\u003e\"user2\", \"user_name\" =\u003e \"Alice\"]);\n\n// Query all datasets with user_name='Bob' OR user_name='Alice'\nforeach ($userTbl-\u003equery(stmt: new OrStmt([\"user_id\", \"=\", \"Bob\"], [\"user_id\", \"=\", \"Alice\"])) as $data) {\n    print_R ($data);\n}\n```\n\n\n## Installation\n\n```bash\ncomposer require phore/unidb\n```\n\n| Driver                  | Class                       | Features                           |\n|-------------------------|-----------------------------|------------------------------------|\n| SqliteDriver            | `SqliteDriver`              | Schema create                      |\n\n\n\n## Defining the schema\n\nUniDb requires basic information about the schema to run queries against.\n\n## Querying data\n\n```php\npublic  UniDb::query(\n    $stmt = null, \n    string $table = null, \n    int $page = null, \n    int $limit = null,\n    string $orderBy = null, \n    string $orderType=\"ASC\",\n    bool $cast = false\n) : \\Generator\n```\n\n| Named Argument  | Description                                                    |\n|-----------------|----------------------------------------------------------------|\n| `stmt`          | The Statement: either class `AndStmt` or `OrStmt`. If null, all data will be queried  |\n| `table`         | Override the default table setting defined using `UniDb::with()`                      |\n| `cast`          | If `true` it will cast the structure into the Object defined                          |\n\n***Accessing the data using generators***\n\nThe easies way to access the data is to use generators:\n\n```php\nforeach ($odb-\u003equery(table: \"User\") as $user) {\n    print_r ($user); // Will output\n}\n```\n\n***Accessing full Result Set / Limit results / Page offsets***\n\n```php\n$odb-\u003equery(table: \"User\", limit: 10, page: 1);\nprint_r ($odb-\u003eresult-\u003egetResult());\n```\n\n[See output / full example](doc/doc_result_set.md)\n\n\n***Using Object Casting / Entities***\n\nUniDb can work with Objects and therefor uses [phore/hydrator](https://github.com/phore/phore-hydrator) to \ncast the result set into objects. Activate this feature by specifying `cast: SomeClass::class` in Argument list.\n\n\u003e To use casting functionality you have to add package `phore/hydrator` to your composer.json requirements\n\n```php \nforeach ($odb-\u003equery(table: \"User\", cast: User::class) as $obj) {\n    print_r ($obj); // Instance of User class\n}\n```\n\n[See details manual page for Object casting](doc/doc_object_casting.md)\n\n\n***Quering all data of a table***\n\n```\n$odb-\u003equery(table: \"User\")\n```\n\n***Sorting the data***\n\n\n## Statements\n\nTo be compatible to as well SQL and NoSql Databases, UniDb uses Statements to query data.\nBy default statements will be chained by AND statements.\n\n***AND Statement***\n\n```php \nnew AndStmt([\"name\", \"=\", \"Bob\"], [\"user_name\", \"=\", \"bob1\"]);\n// =\u003e SELECT ... WHERE name='Bob' AND name='Alice'\n```\n\n***OR Statement***\n\n```php \nnew OrStmt([\"name\", \"=\", \"Bob\"], [\"name\", \"=\", \"Alice\"]);\n// =\u003e SELECT ... WHERE name='Bob' OR name='Alice'\n```\n\n***Nested Statements***\n\n```php \nnew AndStmt([\"name\", \"=\", \"Bob\"], new OrStmt([\"name\", \"=\", \"Bob\"], [\"name\", \"=\", \"Alice\"]));\n// =\u003e SELECT ... WHERE name='Bob' AND ( name='Bob' OR name='Alice' )\n```\n\n\n***Operators***\n\n| Operator       | Expected Value         | Description                                  |\n|----------------|------------------------|----------------------------------------------|\n| `=`            | string|int|bool|null   | Equals operator                              |\n| `\u003c\u003e`            | string|int|bool|null  | Not Equals operator                         |\n| `\u003e`            | string|int|bool        | Bigger than operator                         |\n| `\u003c`            | string|int|bool        | Smaller than operator                        |\n| `~`            | string                 | Like operator                                |\n| `IN`           | array                  | \n\n\n## CRUD Operations\n\n## Batch Update\n\nUniDb comes with buildin syncronisation methods to initialize and update records \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphore%2Fphore-unidb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphore%2Fphore-unidb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphore%2Fphore-unidb/lists"}