{"id":15030083,"url":"https://github.com/leven-framework/dba-common","last_synced_at":"2026-04-09T10:02:41.545Z","repository":{"id":44466652,"uuid":"442423456","full_name":"leven-framework/dba-common","owner":"leven-framework","description":"📑 simple database abstraction interface with OOP query builder and a mock implementation for easy testing","archived":false,"fork":false,"pushed_at":"2022-07-14T08:14:19.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-20T11:17:37.458Z","etag":null,"topics":["adapter","database","database-abstraction","database-layer","dba","dbal","mock","mysql","php","php8"],"latest_commit_sha":null,"homepage":"","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/leven-framework.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-28T10:08:59.000Z","updated_at":"2022-07-14T08:41:43.000Z","dependencies_parsed_at":"2022-08-30T09:50:15.968Z","dependency_job_id":null,"html_url":"https://github.com/leven-framework/dba-common","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leven-framework%2Fdba-common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leven-framework%2Fdba-common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leven-framework%2Fdba-common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leven-framework%2Fdba-common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leven-framework","download_url":"https://codeload.github.com/leven-framework/dba-common/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243349493,"owners_count":20276611,"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":["adapter","database","database-abstraction","database-layer","dba","dbal","mock","mysql","php","php8"],"created_at":"2024-09-24T20:12:24.228Z","updated_at":"2025-12-27T13:16:12.809Z","avatar_url":"https://github.com/leven-framework.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Leven Database Adapter Interface\n\n## Features\n- 🧪 abstract access to the database\n- 🏗 simple query builder with nested conditions support\n- 🔐 automatic escaping of table and column names and values\n\n## Usage examples\n\n### Select\n```php\n$result = $db-\u003eselect('foo_table')\n    -\u003ecolumns('id', 'name') // optional, defaults to all columns\n    -\u003ewhere('id', '\u003e', 1)-\u003eorWhere('age', '\u003e', 22)\n    -\u003eorWhere(fn(\\Leven\\DBA\\Common\\BuilderPart\\WhereGroup $w) =\u003e $w\n        -\u003ewhere('name', 'IN', ['Foo', 'Bar'])\n        -\u003eandWhere('description', 'LIKE', '%foo%')\n    )\n    -\u003eorderDesc('id')-\u003eorderAsc('name')\n    -\u003elimit(1)-\u003eoffset(1)\n    -\u003eexecute();\n\nforeach($result as $row) {} // you can iterate over the rows\n$result-\u003erows; // or access the rows as an array\n$result-\u003ecount; // count of rows returned\n```\n\n### Insert\n```php\n$result = $db-\u003einsert('foo_table', ['name' =\u003e 'Foo']);\n\n$result-\u003elastId; // last inserted id (auto increment) or null\n```\n\n### Update\n```php\n$db-\u003eupdate('foo_table')\n    -\u003eset('name', 'Foo')\n    -\u003ewhere('id', '!=', 3)\n    -\u003elimit(10)\n    -\u003eexecute();\n```\n\n### Delete\n```php\n$db-\u003edelete('foo_table')\n    -\u003ewhere('id', 5)\n    -\u003elimit(11)\n    -\u003eexecute();\n```\n\n## Implementations\n\n### [📦 MySQL](https://github.com/leven-framework/dba-mysql)\n```shell\ncomposer require leven-framework/dba-mysql\n```\n\n```php\nrequire 'vendor/autoload.php';\n\n// all arguments are optional except for database\n$db = new \\Leven\\DBA\\MySQL\\MySQLAdapter(\n    database: 'example',\n    user: 'username',\n    password: 'password',\n    host: 'localhost',\n    port: 3306,\n    charset: 'utf8',\n    tablePrefix: 'prefix_'\n);\n\n// or use an existing PDO instance\n$db = new \\Leven\\DBA\\MySQL\\MySQLAdapter($pdo);\n```\n\n### [📦 Mock](https://github.com/leven-framework/dba-mock)\n```shell\ncomposer require leven-framework/dba-mock\n```\n```php\nrequire 'vendor/autoload.php';\n\n// saving and loading the database in JSON is slow but useful for development\n$db = new \\Leven\\DBA\\Mock\\MockAdapter(\n    fn() =\u003e json_decode(file_get_contents('db.json'), true),\n    fn(\\Leven\\DBA\\Mock\\Structure\\Database $db) =\u003e file_put_contents('db.json', json_encode($db-\u003etoArray(), JSON_PRETTY_PRINT))\n);\n\n// first argument can also be an array representing the database\n$dbArray = [\n    'foo_table' =\u003e [\n        ['id' =\u003e 'int', 'name' =\u003e 'varchar'],\n        [1, 'Foo'],\n        [2, 'Bar'],\n    ],\n];\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleven-framework%2Fdba-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleven-framework%2Fdba-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleven-framework%2Fdba-common/lists"}