{"id":36294135,"url":"https://github.com/pdscopes/database","last_synced_at":"2026-01-11T10:01:38.680Z","repository":{"id":62521587,"uuid":"83564726","full_name":"pdscopes/database","owner":"pdscopes","description":"Database entities and query builder","archived":false,"fork":false,"pushed_at":"2020-06-26T23:22:36.000Z","size":307,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-13T20:52:51.708Z","etag":null,"topics":["database","entities","migration","php","query-builder"],"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/pdscopes.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":"2017-03-01T14:40:08.000Z","updated_at":"2022-11-24T06:36:09.000Z","dependencies_parsed_at":"2022-11-02T10:45:22.456Z","dependency_job_id":null,"html_url":"https://github.com/pdscopes/database","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/pdscopes/database","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdscopes%2Fdatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdscopes%2Fdatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdscopes%2Fdatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdscopes%2Fdatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pdscopes","download_url":"https://codeload.github.com/pdscopes/database/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdscopes%2Fdatabase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28299709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T08:21:30.231Z","status":"ssl_error","status_checked_at":"2026-01-11T08:21:26.882Z","response_time":60,"last_error":"SSL_read: 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":["database","entities","migration","php","query-builder"],"created_at":"2026-01-11T10:01:28.553Z","updated_at":"2026-01-11T10:01:38.674Z","avatar_url":"https://github.com/pdscopes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MadeSimple - Database\n[![Build Status](https://travis-ci.org/pdscopes/database.svg?branch=master)](https://travis-ci.org/pdscopes/database)\n\nThe database package is a abstraction layer between PHP and an SQL database.\nThe main features of the package are:\n\n1. [Migration control](#migration-control)\n2. [Database Seeding](#database-seeding)\n3. [Query building](#query-building)\n4. [Entities and Relationships](#entities-and-relationships)\n\n## Migration Control\nYou can control migrations of your database through an easy to use, reliable\ncommand line. Possible actions are to install the migrations table, upgrade,\nrollback, uninstall, and refresh. These are all called through `bin/database`.\n\nFor example, on first clone of a package using database:\n```bash\n\u003e composer install\n...\n\u003e vendor/bin/database database:install -e -v\n[notice] Migration table created\n\u003e vendor/bin/database database:upgrade -ep examples/migrations -v\n[notice] Migrated file: \"/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php\"\n[notice] Migrated file: \"/path/to/database/examples/migrations/v1.0.1-ExampleComment.php\"\n```\nor you can use the shortcut:\n```bash\n\u003e composer install\n...\n\u003e vendor/bin/database database:migrate -e -p examples/migrations -v\n[notice] Migration table created\n[notice] Migrated file: \"/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php\"\n[notice] Migrated file: \"/path/to/database/examples/migrations/v1.0.1-ExampleComment.php\"\n```\n\n\nFor example, on rollback a migration:\n```bash\n\u003e vendor/bin/database database:rollback -e -v\nRolling back batch: 1\n[notice] Rolled back file: \"/path/to/database/examples/migrations/v1.0.1-ExampleComment.php\"\n[notice] Rolled back file: \"/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php\"\n```\n\nFor example, on uninstalling:\n```bash\n\u003e vendor/bin/database database:uninstall -e -v\n[notice] Migration table removed\n```\n\nFor example, on refreshing:\n```bash\n\u003e vendor/bin/database database:refresh -e -p examples/migrations/ -s examples/seeds/ -v\n[notice] Migration table already installed\n[notice] Rolled back file: \"/path/to/database/examples/migrations/v1.0.1-ExampleComment.php\"\n[notice] Rolled back file: \"/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php\"\n[notice] Migrated file: \"/path/to/database/examples/migrations/v1.0.0-ExampleInitial.php\"\n[notice] Migrated file: \"/path/to/database/examples/migrations/v1.0.1-ExampleComment.php\"\n[notice] Seeded file: \"/path/to/database/examples/seeds/v1.0.0-ExampleTableSeeder.php\"\n```\n\n## Database Seeding\nYou can create seeds for the database that should be used to populate the\ndatabase with dummy data. This can be called through `bin/database`.\n\nFor example, on seeding that database:\n```bash\n\u003e vendor/bin/database database:seed -e -v -s examples/seeds\n[notice] Seeded file: \"/path/to/database/examples/seeds/v1.0.0-ExampleTableSeeder.php\"\n```\n\n## Query Building\n### Select\n```php\n$connection\n    -\u003eselect()\n    -\u003efrom('table')\n    -\u003ewhere('column', '=', 'value');\n// SELECT * FROM `table` WHERE `columns` = ?\n```\n\n### Update\n```php\n$connection\n    -\u003eupdate()\n    -\u003etable('table')\n    -\u003eset('column', 'new-value')\n    -\u003ewhere('another-column', '=', 'value');\n// UPDATE `table` SET `column`=? WHERE `another-column` = ?\n```\n\n### Insert\n```php\n$connection\n    -\u003einsert()\n    -\u003einto('table')\n    -\u003ecolumns('column1', 'column2')\n    -\u003evalues(5, 'value');\n// INSERT INTO `table` (`column1`,`column2`) VALUES (?,?)\n\n$rows = [\n    ['column1_value1', 'column2_value1'],\n    ['column1_value2', 'column2_value2'],\n    ['column1_value3', 'column2_value3'],\n];\n$connection\n    -\u003einsert()\n    -\u003einto('table')\n    -\u003ecolumns('column1', 'column2')\n    -\u003echunkedQuery($rows, 2);\n// INSERT INTO `table` (`column1`,`column2`) VALUES (?,?),(?,?)\n// INSERT INTO `table` (`column1`,`column2`) VALUES (?,?)\n```\n\n### Delete\n```php\n$connection\n    -\u003edelete()\n    -\u003efrom('table')\n    -\u003ewhere('column', '=', 'value');\n// DELETE FROM `table` WHERE `column` = ?\n```\n\n### Statements\n```php\n$connection-\u003estatement(function (CreateTable $create) {\n    $create-\u003etable('user')-\u003eifNotExists();\n    $create-\u003ecolumn('id')-\u003einteger(10)-\u003eprimaryKey()-\u003eautoIncrement();\n    $create-\u003ecolumn('uuid')-\u003echar(36)-\u003eunique()-\u003enotNull();\n    $create-\u003ecolumn('email')-\u003echar(255)-\u003eunique()-\u003enotNull();\n    $create-\u003ecolumn('password')-\u003echar(255)-\u003enotNull();\n    $create-\u003ecolumn('created_at')-\u003etimestamp()-\u003enotNull()-\u003euseCurrent();\n    $create-\u003ecolumn('updated_at')-\u003etimestamp()-\u003enotNull()-\u003euseCurrent();\n    $create\n        -\u003eengine('InnoDB')\n        -\u003echarset('utf8mb4', 'utf8mb4_general_ci');\n});\n// CREATE TABLE IF NOT EXISTS `user` (\n//   `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n//   `uuid` CHAR(36) NOT NULL UNIQUE,\n//   `email` CHAR(255) NOT NULL UNIQUE,\n//   `password` CHAR(255) NOT NULL,\n//   `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n//   `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP\n// ) ENGINE=InnoDB,DEFAULT CHARACTER SET=utf8mb4,COLLATE=utf8mb4_general_ci\n```\n\n## Entities and Relationships\n```php\nclass User extends \\MadeSimple\\Database\\Entity\n{\n    use \\MadeSimple\\Database\\Entity\\Relational;\n\n    protected static function getMap()\n    {\n        return new \\MadeSimple\\Database\\EntityMap(\n            'user', // Table name\n            ['id'], // Primary key(s)\n            [       // Other columns: database name =\u003e property name\n                'uuid',\n                'email',\n                'password',\n                'created_at' =\u003e 'createdAt',\n                'updated_at' =\u003e 'updatedAt',\n            ]\n        );\n    }\n\n    /**\n     * @return \\MadeSimple\\Database\\Relationship\\ToMany\n     */\n    public function posts()\n    {\n        return $this-\u003etoMany()-\u003ehas(Post::class, 'p', 'user_id');\n    }\n}\nclass Post extends \\MadeSimple\\Database\\Entity\n{\n    use \\MadeSimple\\Database\\Entity\\Relational;\n\n    protected static function getMap()\n    {\n        return new \\MadeSimple\\Database\\EntityMap(\n            'post', // Table name\n            ['id'], // Primary key(s)\n            [       // Other columns: database name =\u003e property name\n                'uuid',\n                'user_id' =\u003e 'userId',\n                'title',\n                'content',\n                'created_at' =\u003e 'createdAt',\n                'updated_at' =\u003e 'updatedAt',\n            ]\n        );\n    }\n\n    /**\n     * @return \\MadeSimple\\Database\\Relationship\\ToOne\n     */\n    public function user()\n    {\n        return $this-\u003etoOne()-\u003ebelongsTo(User::class, 'u', 'user_id');\n    }\n}\n```\n\n## Supported Databases\nSQL databases currently supported are:\n\n* MySQL\n* SQLite\n\n\n# External Documentation\nLinks to documentation for external dependencies:\n* [PHP Docs](http://php.net/)\n* [Logging PSR-3](http://www.php-fig.org/psr/psr-3/)\n\nLinks to documentation for development only external dependencies:\n* [monolog/monolog](https://github.com/Seldaek/monolog)\n* [symfony/console](http://symfony.com/doc/current/components/console.html)\n* [vlucas/phpdotenv](https://github.com/vlucas/phpdotenv)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdscopes%2Fdatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpdscopes%2Fdatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdscopes%2Fdatabase/lists"}