{"id":22666898,"url":"https://github.com/piko-framework/db-record","last_synced_at":"2026-01-11T10:52:19.760Z","repository":{"id":61177802,"uuid":"544922169","full_name":"piko-framework/db-record","owner":"piko-framework","description":"A lightweight Active Record implementation built on top of PDO","archived":false,"fork":false,"pushed_at":"2025-01-20T10:09:47.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T10:13:18.618Z","etag":null,"topics":[],"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/piko-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2022-10-03T13:23:56.000Z","updated_at":"2025-01-20T10:09:48.000Z","dependencies_parsed_at":"2024-12-09T14:49:56.310Z","dependency_job_id":null,"html_url":"https://github.com/piko-framework/db-record","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piko-framework%2Fdb-record","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piko-framework%2Fdb-record/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piko-framework%2Fdb-record/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piko-framework%2Fdb-record/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piko-framework","download_url":"https://codeload.github.com/piko-framework/db-record/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248550633,"owners_count":21122934,"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":[],"created_at":"2024-12-09T14:32:13.699Z","updated_at":"2025-10-26T14:12:40.757Z","avatar_url":"https://github.com/piko-framework.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Piko Db Record\n\n[![build](https://github.com/piko-framework/db-record/actions/workflows/php.yml/badge.svg)](https://github.com/piko-framework/db-record/actions/workflows/php.yml)\n[![Coverage Status](https://coveralls.io/repos/github/piko-framework/db-record/badge.svg?branch=main)](https://coveralls.io/github/piko-framework/db-record?branch=main)\n\nPiko Db Record is a lightweight Active Record implementation built on top of PDO.\n\nIt has been tested and works with the following databases:\n\n- SQLite\n- MySQL\n- PostgreSQL\n- MSSQL\n\n## Installation\n\nIt's recommended that you use Composer to install Piko Db Record.\n\n```bash\ncomposer require piko/db-record\n```\n\n## Documentation\n\nhttps://piko-framework.github.io/docs/db-record.html\n\n## Usage\n\nFirst, ensure you have the necessary autoloading in place:\n\n```php\nrequire 'vendor/autoload.php';\n```\n\n### Define Your Model\n\nUse the `Piko\\DbRecord`, `Piko\\DbRecord\\Attribute\\Table`, and `Piko\\DbRecord\\Attribute\\Column`\nclasses to define your model. For example:\n\n```php\nuse Piko\\DbRecord;\nuse Piko\\DbRecord\\Attribute\\Table;\nuse Piko\\DbRecord\\Attribute\\Column;\n\n#[Table(name:'contact')]\nclass Contact extends DbRecord\n{\n    #[Column(primaryKey: true)]\n    public ?int $id = null;\n\n    #[Column]\n    public $name = null;\n\n    #[Column]\n    public ?int $order = null;\n}\n\n```\n\n### Setup Database Connection\n\nCreate a new PDO instance and set up your database schema:\n\n```php\n// See https://www.php.net/manual/en/class.pdo.php\n$db = new PDO('sqlite::memory:');\n\n$query = \u003c\u003c\u003cEOL\nCREATE TABLE contact (\n  id INTEGER PRIMARY KEY AUTOINCREMENT,\n  name TEXT NOT NULL,\n  `order` INTEGER\n)\nEOL;\n\n$db-\u003eexec($query);\n```\n\n### Perform CRUD Operations\n\n#### Create\n\nCreate a new record and save it to the database:\n\n```php\n$contact = new Contact($db);\n$contact-\u003ename = 'John';\n$contact-\u003eorder = 1;\n$contact-\u003esave();\n\necho \"Contact id : {$contact-\u003eid}\"; // Contact id : 1\n```\n\n#### Read\n\nRetrieve records from the database:\n\n```php\n$st = $db-\u003eprepare('SELECT * FROM contact');\n$st-\u003eexecute();\n$rows = $st-\u003efetchAll(PDO::FETCH_CLASS, Contact::class, [$db]);\n\nprint_r($rows); // Array ([0] =\u003e Contact Object(...))\n\n// Load a single record by primary key:\n$contact = (new Contact($db))-\u003eload(1);\n\nvar_dump($contact-\u003ename); // John\n```\n\n#### Delete\n\nDelete a record from the database:\n\n```php\n\n$contact-\u003edelete();\nprint_r($st-\u003efetchAll()); // Array()\n```\n\n## Support\n\nIf you encounter any issues or have questions, feel free to open an issue on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiko-framework%2Fdb-record","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiko-framework%2Fdb-record","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiko-framework%2Fdb-record/lists"}