{"id":33952990,"url":"https://github.com/phore/phore-orm","last_synced_at":"2026-04-09T00:31:12.301Z","repository":{"id":247842044,"uuid":"827032473","full_name":"phore/phore-orm","owner":"phore","description":"Flexible Object Relational Mapper","archived":false,"fork":false,"pushed_at":"2024-12-02T15:04:38.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-14T08:47:15.284Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/phore.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-10T22:12:48.000Z","updated_at":"2024-12-02T15:04:36.000Z","dependencies_parsed_at":"2024-07-10T23:55:13.041Z","dependency_job_id":null,"html_url":"https://github.com/phore/phore-orm","commit_stats":null,"previous_names":["phore/phore-orm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/phore/phore-orm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phore","download_url":"https://codeload.github.com/phore/phore-orm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phore%2Fphore-orm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31579819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":[],"created_at":"2025-12-12T19:53:11.536Z","updated_at":"2026-04-09T00:31:12.291Z","avatar_url":"https://github.com/phore.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Phore MiniSql\n\n## Overview\nPhore MiniSql is a lightweight ORM library for PHP, providing an easy-to-use interface for database operations such as create, read, update, delete (CRUD), and schema management. This README provides detailed usage instructions, including entity definitions, handling operations, indexes, foreign keys, and table/connection maintenance.\n\n## Installation\nTo install Phore MiniSql, use Composer:\n\n```bash\ncomposer require phore/minisql\n```\n\n## Defining Entities\nEntities are defined as PHP classes with public properties representing the columns of the corresponding database table. Each entity class must implement a static `__schema` method that returns an `OrmClassSchema` object.\n\n```php\nnamespace App\\Entity;\n\nuse Phore\\MiniSql\\Schema\\OrmClassSchema;\n\nclass User\n{\n    public int $id;\n    public string $name;\n    public string $email;\n\n    public static function __schema(): OrmClassSchema\n    {\n        return new OrmClassSchema(\n            tableName: 'users',\n            primaryKey: 'id',\n            autoincrement: true,\n            columns: [\n                'id' =\u003e 'int',\n                'name' =\u003e 'varchar(255)',\n                'email' =\u003e 'varchar(255)'\n            ]\n        );\n    }\n}\n```\n\n## Usage\n### Connecting to the Database\nTo connect to the database, create an instance of the `Orm` class and provide the DSN and entity classes.\n\n```php\nuse Phore\\MiniSql\\Orm;\nuse App\\Entity\\User;\n\n$orm = new Orm([User::class], 'mysql:host=localhost;dbname=testdb;user=root;password=root');\n$orm-\u003econnect();\n```\n\n### Creating Records\nTo create a new record, instantiate the entity class, set its properties, and call the `create` method.\n\n```php\n$user = new User();\n$user-\u003ename = 'John Doe';\n$user-\u003eemail = 'john.doe@example.com';\n$orm-\u003ecreate($user);\n```\n\n### Reading Records\nTo read a record by its primary key, use the `read` method.\n\n```php\n$user = $orm-\u003ewithClass(User::class)-\u003eread(1);\n```\n\n### Updating Records\nTo update a record, modify its properties and call the `update` method.\n\n```php\n$user-\u003ename = 'Jane Doe';\n$orm-\u003eupdate($user);\n```\n\n### Deleting Records\nTo delete a record, call the `delete` method.\n\n```php\n$orm-\u003edelete($user);\n```\n\n### Listing All Records\nTo list all records of an entity, use the `listAll` method.\n\n```php\n$users = $orm-\u003ewithClass(User::class)-\u003elistAll();\n```\n\n### Selecting Records with Conditions\nTo select records with specific conditions, use the `select` method.\n\n```php\n$users = $orm-\u003ewithClass(User::class)-\u003eselect(['name' =\u003e 'Jane Doe']);\n```\n\n## Indexes\nIndexes can be defined in the `OrmClassSchema` using the `indexes` property.\n\n```php\npublic static function __schema(): OrmClassSchema\n{\n    return new OrmClassSchema(\n        tableName: 'users',\n        primaryKey: 'id',\n        autoincrement: true,\n        columns: [\n            'id' =\u003e 'int',\n            'name' =\u003e 'varchar(255)',\n            'email' =\u003e 'varchar(255)'\n        ],\n        indexes: [\n            'idx_name' =\u003e ['name'],\n            'idx_email' =\u003e ['email']\n        ]\n    );\n}\n```\n\n## Foreign Keys\nForeign keys can be defined in the `OrmClassSchema` using the `foreignKeys` property.\n\n```php\nuse Phore\\MiniSql\\Schema\\OrmForeignKey;\n\npublic static function __schema(): OrmClassSchema\n{\n    return new OrmClassSchema(\n        tableName: 'orders',\n        primaryKey: 'id',\n        autoincrement: true,\n        columns: [\n            'id' =\u003e 'int',\n            'user_id' =\u003e 'int',\n            'product_id' =\u003e 'int'\n        ],\n        foreignKeys: [\n            new OrmForeignKey('user_id', 'users', 'id'),\n            new OrmForeignKey('product_id', 'products', 'id')\n        ]\n    );\n}\n```\n\n## Maintaining Tables and Connections\n### Updating Schema\nTo update the database schema based on the defined entities, use the `updateSchema` method.\n\n```php\n$orm-\u003eupdateSchema();\n```\n\n### Dropping All Tables\nTo drop all tables in the database, use the `dropAllTables` method.\n\n```php\n$orm-\u003egetDriver()-\u003egetSchemaUpdater()-\u003edropAllTables();\n```\n\n## Conclusion\nPhore MiniSql provides a simple and efficient way to manage database operations in PHP. By defining entities and using the provided methods, you can easily perform CRUD operations, manage indexes and foreign keys, and maintain your database schema.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphore%2Fphore-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphore%2Fphore-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphore%2Fphore-orm/lists"}