{"id":15295769,"url":"https://github.com/clagiordano/weblibs-dbabstraction","last_synced_at":"2026-05-06T22:06:59.313Z","repository":{"id":56953374,"uuid":"49974802","full_name":"clagiordano/weblibs-dbabstraction","owner":"clagiordano","description":"weblibs-dbabstraction is an simple and lightweight Abstraction library for the database and ORM modules.","archived":false,"fork":false,"pushed_at":"2017-02-15T12:03:56.000Z","size":130,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-01T17:38:52.074Z","etag":null,"topics":["backend","database","entity","library","mapper","mysql","orm","orm-modules","pdo","pdo-wrapper"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clagiordano.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":"2016-01-19T18:47:32.000Z","updated_at":"2019-03-27T15:10:50.000Z","dependencies_parsed_at":"2022-08-21T04:10:19.987Z","dependency_job_id":null,"html_url":"https://github.com/clagiordano/weblibs-dbabstraction","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clagiordano%2Fweblibs-dbabstraction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clagiordano%2Fweblibs-dbabstraction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clagiordano%2Fweblibs-dbabstraction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clagiordano%2Fweblibs-dbabstraction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clagiordano","download_url":"https://codeload.github.com/clagiordano/weblibs-dbabstraction/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245394767,"owners_count":20608123,"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":["backend","database","entity","library","mapper","mysql","orm","orm-modules","pdo","pdo-wrapper"],"created_at":"2024-09-30T18:08:06.087Z","updated_at":"2026-05-06T22:06:54.277Z","avatar_url":"https://github.com/clagiordano.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![BuildStatus](https://travis-ci.org/clagiordano/weblibs-dbabstraction.svg?branch=master) ![License](https://img.shields.io/github/license/clagiordano/weblibs-dbabstraction.svg)\n\n# weblibs-dbabstraction\nweblibs-dbabstraction is an simple and lightweight Abstraction library for the database and ORM modules.\n\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/ba8db8b9-1af7-471b-965e-d055f23b6dce/big.png)](https://insight.sensiolabs.com/projects/ba8db8b9-1af7-471b-965e-d055f23b6dce)\n\n## Why use weblibs-dbabstraction ?\nThe purpose of this project is to propose a simple and lightweight alternative solution instead of more big and complex projects such as Doctrine.\n\n## Installation\nThe recommended way to install weblibs-dbabstraction is through [Composer](https://getcomposer.org).\n```bash\ncomposer require clagiordano/weblibs-dbabstraction\n```\n\n## Description of the main components\n\n### Adapter description\nIs a persistence layer which interact with database or other backends.\nAn adapter class must be implements the **DatabaseAdapterInterface** for compatibility with other components.\u003cbr /\u003e\nThe default adapter is the already defined **PDOAdapter** wich simplify the access to PDO object and related methods.\u003cbr /\u003e\nOther specific adapters can be implemented to easily access to other backends.\n\n### Adapter usage\n```php\nnew PDOAdapter(\n    $dbHost,\n    $dbUser,\n    $dbPassword,\n    $dbName,\n    $dbDriver,\n    $dbCharset,\n    $isPersistent\n);\n```\n\nSee PDOAdapterTest class (phpunit test class) for full sample usage into tests folder.\n\n### Entity description\nAn *entity* is an object which expose properties dynamically generated from an array of fields.\nIt is a simple class which have defined the magic methods (__set, __get ... ).\u003cbr /\u003e\nThe entity is automatically used by the *mapper* class for the operations and can be used to gets and sets its properties.\u003cbr /\u003e\n*For more details please see the SampleEntity class into testdata folder.*\n\n### Entity usage\nAn entity class must be extends **AbstractEntity** as:\n```php\n/**\n * Class SampleEntity\n */\nclass SampleEntity extends AbstractEntity\n{\n}\n```\n\nThen can be used:\n```php\n$entityClass-\u003eproperty = \"value\";\necho $entityClass-\u003eproperty;\n```\n\n### Mapper description\nA mapper is a glue between **Entity** and **Adapter** objects which expose high level method to use and persists data.\u003cbr /\u003e\nA mapper class must be extends the **AbstractMapper**:\n```php\n/**\n * Class SampleMapper\n */\nclass SampleMapper extends AbstractMapper\n{\n```\n\nthen must be declare two protected properties to connect database table for persistence\nand the related entity class:\n```php\nprotected $entityTable = 'sample_table';\nprotected $entityClass = 'SampleEntity';\n```\n\ntherefore must be implements the abstract method **createEntity** for the correct mapping between table fields and the desidered entity properties:\n```php\nprotected function createEntity(array $fields)\n{\n    return new SampleEntity(\n        [\n            'id' =\u003e $fields['id'],\n            'code' =\u003e $fields['code'],\n            'brand' =\u003e $fields['brand'],\n            'model' =\u003e $fields['model'],\n            'description' =\u003e $fields['description']\n        ]\n    );\n}\n```\n\nYou can also define additional methods if necessary or override existing ones such as insert, update, delete etc to modify its behavior.\n\n### Mapper usage\nTo improve control and security AbstractMapper's methods can be overrided:\n```php\n/**\n * Sample overrided insert method\n *\n * @param SampleEntity $entity\n * @return mixed\n */\npublic function insert($entity)\n{\n    if (!$entity instanceof SampleEntity) {\n        throw new \\InvalidArgumentException(\n            __METHOD__ . \": Invalid entity type.\"\n        );\n    }\n\n    return $this-\u003eadapter-\u003einsert($this-\u003eentityTable, $entity-\u003etoArray());\n}\n```\n\nAs you can see, this overrided method require explicitly an instance of SampleEntity to works,\nthe same way you can run a validation or additional arguments formatting/sanitizing or whatever you want.\n\n## Legal\n*Copyright (C) Claudio Giordano \u003cclaudio.giordano@autistici.org\u003e*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclagiordano%2Fweblibs-dbabstraction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclagiordano%2Fweblibs-dbabstraction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclagiordano%2Fweblibs-dbabstraction/lists"}