{"id":19197018,"url":"https://github.com/jitesoft/wp-dbal","last_synced_at":"2026-04-18T11:31:21.035Z","repository":{"id":76670324,"uuid":"138128918","full_name":"jitesoft/wp-dbal","owner":"jitesoft","description":"Small project intended to create a database abstraction layer between WordPress database and logic. (Mirror)","archived":false,"fork":false,"pushed_at":"2018-06-25T09:03:30.000Z","size":97,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-26T17:26:44.497Z","etag":null,"topics":["dbal","php","php72","wordpress","wp"],"latest_commit_sha":null,"homepage":"https://gitlab.com/jitesoft/open-source/php/wp-dbal","language":"PHP","has_issues":false,"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/jitesoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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}},"created_at":"2018-06-21T06:30:35.000Z","updated_at":"2018-06-25T09:03:31.000Z","dependencies_parsed_at":"2023-03-10T06:30:29.549Z","dependency_job_id":null,"html_url":"https://github.com/jitesoft/wp-dbal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jitesoft/wp-dbal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fwp-dbal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fwp-dbal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fwp-dbal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fwp-dbal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jitesoft","download_url":"https://codeload.github.com/jitesoft/wp-dbal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fwp-dbal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31966901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dbal","php","php72","wordpress","wp"],"created_at":"2024-11-09T12:15:17.288Z","updated_at":"2026-04-18T11:31:21.016Z","avatar_url":"https://github.com/jitesoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP-DB Abstraction\n\n**Observe** This project is currently in development and have no release yet. It is not usable in the way that it is intended to \nbe used when ready.  \nFeel free to contribute or wait for a v1.0.0 release.\n\nThis project is intended to be used as a layer between the database and the logic of the webpage or application created using WordPress.  \n\nThe intention is that all the base database entities should be represented by models, models which can be acquired via repositories, instead of direct queries.\nThe base classes in the project will allow for usage of the WordPress database classes or direct PDO access to both show how simple it can be implemented through the repository pattern\nand to let you start your project without having to create it all yourself.\n\nAs some might notice, the model/entity classes are quite similar to how the `Doctrine` ORM/DBAL works. It uses the same type of annotations\nas you would with doctrine if using the annotations to declare the fields and tables.  \nThis is very much intentional, I even use the Doctrine annotation package for the annotations themselves.  \nThe reason to this is to introduce the concept of Doctrine, a ORM/DBAL that I love, to others, making it easier for them to move\nover to a framework in which the `Model View Controller` or similar pattern is used.\n\nI intend to implement other mapping types similar to the other doctrine mappings, such as YML based and class based, but that is in \nfuture releases.\n\n## Models\n\nThe models, or entities, are classes which represents a single database entry.  \nA model extends the `AbstractModel` class, which gives it a few methods and traits that enables it to integrate with the \nprojects underlying classes.  \nFurther more, to allow the model to be able to interact correctly with the database a few annotations are available to use:\n\n* `Model`\n* `Field`\n\n### Model annotation\n\nThe `Model` annotation is required on a model class, it marks the class as a entity and exposes the database table used by the model through a annotation variable:\n\n```php\n\u003c?php\nuse Jitesoft\\WordPress\\DBAL\\Annotations\\Model;\nuse Jitesoft\\WordPress\\DBAL\\Models\\AbstractModel;\n\n/**\n * @Model(table=\"my_database_table\")\n */\nclass MyModel extends AbstractModel {\n}\n```\n\n_Observe, there is a `primaryKey` annotation in the model annotation which is currently not used, this is reserved for a possible later usage._\n\n### Field annotations\n\nThe model also have to expose fields to the database handler, each field should be marked to be exposed but they do not have to be public.  \nThanks to the use of reflection, the project can access any type of variables in the model, hence it's important that the fields to be\nexported are correctly annotated.\n\nThe annotation for fields is simply `Field`. It exposes two variables: `name`, `hidden`, in which the first is a mapping to the database field name\nand the second marks the field hidden to the json_encode method.\n\n```php\n\u003c?php\nuse Jitesoft\\WordPress\\DBAL\\Annotations\\Model;\nuse Jitesoft\\WordPress\\DBAL\\Models\\AbstractModel;\nuse Jitesoft\\WordPress\\DBAL\\Annotations\\Field;\n/**\n * @Model(table=\"my_database_table\")\n */\nclass MyModel extends AbstractModel {\n  \n  /** @var int\n   *  @Field(name=\"my_database_id_field\")\n   */\n  private $id;\n\n  /**\n   * @var string\n   * @Field(name=\"my_hidden_field\", hidden=true)\n   */\n  private $secret;\n}\n```\n\n### Relation annotations\n\nFinally, the model can define relationships inside the class using three type of annotations:\n\n* `HasOne`\n* `HasMany`\n* `BelongsTo`\n\nUsing those exposes relationship metadata on the model and makes it possible to load related models on database queries.  \nEach of the annotation types exposes `target`, `joinOn` and `load` params, of which the `target` is supposed to point to the target model,\nthe `joinOn` should expose the target key to join on in database queries and the `load` should be set to either `lazy`, `eager` or `never`.\n\nExample:\n\n```php\n\u003c?php\nuse Jitesoft\\WordPress\\DBAL\\Annotations\\Model;\nuse Jitesoft\\WordPress\\DBAL\\Models\\AbstractModel;\nuse Jitesoft\\WordPress\\DBAL\\Annotations\\BelongsTo;\nuse Jitesoft\\WordPress\\DBAL\\Annotations\\HasOne;\nuse Jitesoft\\WordPress\\DBAL\\Annotations\\HasMany;\nuse Models\\AnotherModel;\n\n/**\n * @Model(table=\"my_database_table\")\n */\nclass MyModel extends AbstractModel {\n  \n  /** @var AnotherModel\n   *  @BelongsTo(target=\"AnotherModel\", joinOn=\"child_id\", load=\"eager\")\n   */\n  private $parent;\n\n  /**\n   * @var AnotherModel\n   * @HasOne(target=\"AnotherModel\", joinOn=\"parent_id\", load=\"lazy\")\n   */\n  private $child;\n  \n  /**\n  * @var AnotherModel\n  * @HasMany(target=\"AnotherModel\", joinOn=\"parent_id\", load=\"lazy\")\n  */\n  private $children;\n\n}\n```\n\n### To JSON\n\nAll models will inherit the `JsonSerialize` interface from the  `AbstractModel`, by default, this method will fetch each of the none-hidden properties, all relations and the table name and return a json object with the values.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjitesoft%2Fwp-dbal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjitesoft%2Fwp-dbal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjitesoft%2Fwp-dbal/lists"}