{"id":30699492,"url":"https://github.com/oza75/database","last_synced_at":"2026-05-03T22:33:44.977Z","repository":{"id":57034684,"uuid":"179337326","full_name":"oza75/Database","owner":"oza75","description":"A Database package to deal with your data","archived":false,"fork":false,"pushed_at":"2019-04-04T09:55:15.000Z","size":730,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-31T02:45:49.591Z","etag":null,"topics":["database","database-migrations","database-schema","laravel","orm","php7"],"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/oza75.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":"2019-04-03T17:23:34.000Z","updated_at":"2022-02-12T13:01:39.000Z","dependencies_parsed_at":"2022-08-23T20:50:51.106Z","dependency_job_id":null,"html_url":"https://github.com/oza75/Database","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/oza75/Database","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oza75%2FDatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oza75%2FDatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oza75%2FDatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oza75%2FDatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oza75","download_url":"https://codeload.github.com/oza75/Database/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oza75%2FDatabase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273272720,"owners_count":25076021,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"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":["database","database-migrations","database-schema","laravel","orm","php7"],"created_at":"2025-09-02T11:09:53.895Z","updated_at":"2026-05-03T22:33:44.948Z","avatar_url":"https://github.com/oza75.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"### A Database package to deal with your data\n- Fully Tested With Mysql Driver\n- Contributors Needed\n- Made without any dependency\n### Installation\n```bash\ncomposer require oza/database\n```\n#### Usage\nFirst create a config file with your database configuration in **Application root Folder (IMPORTANT)**\n- Example of config file\n```php \n\u003c?php\n \n return [\n     'driver' =\u003e 'mysql',\n     'name' =\u003e 'db_package',\n     'host' =\u003e 'localhost:3306',\n     \"username\" =\u003e \"root\",\n     \"password\" =\u003e \"\",\n     \"migrations\" =\u003e [\n         \"folder\" =\u003e __DIR__ . '/../migrations/' // path of migrations folder ( #important )\n     ]\n ];\n```\n- Then Register your composer autoloader \n```php\n   \u003c?php\n   // After registered your composer autoloader (e.g: require_one __DIR_.\"/../vendor/autoload.php\"\n   // Register your config files\n   \\OZA\\Database\\Config::instance()-\u003eregister(__DIR__.'/../db.php');\n   \n```\n   The config class is a **singleton** ([Design pattern](https://sourcemaking.com/design_patterns/singleton/php/1))  so you can register all config files you want and \n   access to them anywhere in your application.\n   \n   You can find its documentation here : \n   \n#### Migrations\nMigrations are like version control for your database, allowing your team to easily modify and share the application's database schema. \nMigrations are typically paired with  schema builder to easily build your application's database schema. \nIf you have ever had to tell a teammate to manually add a column to their local database schema, \nyou've faced the problem that database migrations solve.\n- How to create migrations\n\n  * Open your terminal and run \n    \n    ```bash\n        php vendor/bin/database migration:create {name_of_migrations} --table={name_of_table_you_want_to_create}\n    ```\n    \n   * For exampe if I want to create a users table for my application    \n    ```bash\n        php vendor/bin/database migration:create create_users_table --table=users\n    ``` \n    This command will create a new migration file in the migrations folder that you specified in your config file\n    ```php\n    \u003c?php\n    \n    use OZA\\Database\\Migrations\\Interfaces\\MigrationTableInterface;\n    use OZA\\Database\\Migrations\\Schema\\Schema;\n    use OZA\\Database\\Migrations\\Table;\n    \n    class CreateTestUsersMigration implements MigrationTableInterface\n    {\n    \n        /**\n         * Create table\n         *\n         * @param Schema $schema\n         * @return mixed\n         */\n        public function up(Schema $schema): void\n        {\n            $schema-\u003ecreate('users', function (Table $table) {\n    \n                $table-\u003einteger('id')-\u003eautoIncrement()-\u003eindex();\n    \n                $table-\u003etimestamps();\n            });\n        }\n    \n        /**\n         * Called when rollback\n         *\n         * @param Schema $schema\n         * @return mixed\n         */\n        public function down(Schema $schema): void\n        {\n            $schema-\u003edrop('users');\n        }\n    }\n    ```\n    If you are familiar with Laravel, this file looks like as laravel migration with some little difference.\n    I have worked with Laravel and I liked the way They make things simple. \n    \n    `up` method is called when you want to create your table and `down` when you want to rollback.\n    \n    Inside `up` method in `schema-\u003ecreate` closure you can create all type of column you want . For example we gonna add \n    `name`, `email`, `password` columns in your table\n    \n     ```php\n     \u003c?php\n     \n     use OZA\\Database\\Migrations\\Interfaces\\MigrationTableInterface;\n     use OZA\\Database\\Migrations\\Schema\\Schema;\n     use OZA\\Database\\Migrations\\Table;\n     \n     class CreateTestUsersMigration implements MigrationTableInterface\n     {\n     \n         /**\n          * Create table\n          *\n          * @param Schema $schema\n          * @return mixed\n          */\n         public function up(Schema $schema): void\n         {\n             $schema-\u003ecreate('users', function (Table $table) {\n     \n                 $table-\u003einteger('id')-\u003eautoIncrement()-\u003eindex();\n                 $table-\u003estring('name')-\u003eindex();\n                 $table-\u003estring('email')-\u003eindex()-\u003eunique();\n                 $table-\u003estring('password');\n                 $table-\u003etimestamps();\n             });\n         }\n     \n         /**\n          * Called when rollback\n          *\n          * @param Schema $schema\n          * @return mixed\n          */\n         public function down(Schema $schema): void\n         {\n             $schema-\u003edrop('users');\n         }\n     }\n     ```   \n      - See [Column types]()\n      - See [Column Definitions]()\n- when you're satisfy with yours migrations files, commit them to your database\n   \n  In your terminal\n  ```bash\n   php vendor/bin/database migrate\n  ``` \n- If you want to rollback \n       \n  In your terminal\n  ```bash\n   php vendor/bin/database migrate:rollback\n  ``` \n  This will rollback the latest migrations you've committed\n\n### ORM\nThe package comes also with a little ORM\n    \nTo retrieve information in our table your use the QueryBuilder class or Query Facade\n\n```php\n    \u003c?php\n    $user = \\OZA\\Database\\Facade\\Query::table('users')-\u003efind(2);\n```\n\nThere are a lot of methods(`where`, `orWhere`, `whereIn`, `orWhereIn`, `get`, `first`, `limit` etc...) on table that helps you to retrieve your data\nYou can find QueryBuilder Documentation here :  \n\nYou can also create an **UserEntity** which will represents your User\n\n```php\n\u003c?php\n\u003c?php\n\n\nnamespace OZA\\Database\\Tests\\Entities;\n\n\nuse OZA\\Database\\Query\\Entity;\nuse OZA\\Database\\Query\\Relations\\ManyToOne;\n\nclass UserEntity extends Entity\n{\n\n    /**\n     * @param string $value\n     * @return mixed\n     */\n    public function getEmailAttribute(string $value)\n    {\n        return strtoupper($value);\n    }\n\n    public function setNameAttribute($value)\n    {\n        return strtoupper($value);\n    }\n\n    /**\n     * @return ManyToOne\n     */\n    public function posts()\n    {\n        return $this-\u003emanyToOne(PostEntity::class, 'user_id', 'id');\n    }\n}\n```\n\n Then you can fetch users like : \n ```php\n \u003c?php\n // Create new User\n \\App\\Entities\\UserEntity::make([\n     'name' =\u003e 'Aboubacar',\n     'email' =\u003e 'user@email.com'\n])-\u003ecreate();\n \n // Find a User\n \\App\\Entities\\UserEntity::query()-\u003efind(2);\n \n // Count\n  \\App\\Entities\\UserEntity::query()-\u003ecount();\n  \n  // With Where clause\n  \\App\\Entities\\UserEntity::query()-\u003ewhere('name', 'aboubacar')-\u003eget();\n  \n  // First item\n  \\App\\Entities\\UserEntity::query()-\u003ewhere('name', 'LIKE', '%bouba%')-\u003efirst();\n  \n  \\App\\Entities\\UserEntity::query()-\u003ewhere(function (\\OZA\\Database\\Query\\QueryBuilder $builder) {\n     $builder-\u003ewhere('name', 'aboubacar')\n     -\u003eorWhere('name', 'oza')\n     -\u003eget(); \n  });\n ```\n There are plenty methods on QueryBuilder , If you have already work with Laravel\n Just use it like Laravel QueryBuilder.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foza75%2Fdatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foza75%2Fdatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foza75%2Fdatabase/lists"}