{"id":23902969,"url":"https://github.com/marcomilon/micro-db","last_synced_at":"2025-02-23T10:45:01.153Z","repository":{"id":62507908,"uuid":"111840398","full_name":"marcomilon/micro-db","owner":"marcomilon","description":"Lightweight ORM library.","archived":false,"fork":false,"pushed_at":"2018-09-12T21:58:53.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-04T22:51:16.510Z","etag":null,"topics":["activerecord","composer","database","lightweight-orm-library","mysql","orm","php","query-builder"],"latest_commit_sha":null,"homepage":"","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/marcomilon.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-11-23T18:35:38.000Z","updated_at":"2018-09-24T21:37:21.000Z","dependencies_parsed_at":"2022-11-02T13:16:15.285Z","dependency_job_id":null,"html_url":"https://github.com/marcomilon/micro-db","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcomilon%2Fmicro-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcomilon%2Fmicro-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcomilon%2Fmicro-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcomilon%2Fmicro-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcomilon","download_url":"https://codeload.github.com/marcomilon/micro-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240304564,"owners_count":19780312,"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":["activerecord","composer","database","lightweight-orm-library","mysql","orm","php","query-builder"],"created_at":"2025-01-04T22:51:21.650Z","updated_at":"2025-02-23T10:45:01.072Z","avatar_url":"https://github.com/marcomilon.png","language":"PHP","readme":"# Micro-db \n\n[![Latest Stable Version](https://poser.pugx.org/fullstackpe/micro-db/v/stable)](https://packagist.org/packages/fullstackpe/micro-db) [![Build Status](https://travis-ci.org/marcomilon/micro-db.svg?branch=master)](https://travis-ci.org/marcomilon/micro-db)\n\nMicro-db is a lightweight ORM library. \n\n### Installation\n\nFirst you need to install Composer. You may do so by following the instructions \nat [getcomposer.org](https://getcomposer.org/download/). \nThen run\n\n\u003e composer require fullstackpe/micro-db\n\nIf you prefer you can create a composer.json in your project folder.\n\n```json\n{\n    \"require\": {\n        \"fullstackpe/micro-db\": \"^1.1\"\n    }\n}\n```\n\nThen run the command \n\n\u003e composer install\n\n### The ActiveRecord Class\n\nIf you have a table called `book`. You need to create an active record Class \ncalled `Book` that extends the Class `micro\\db\\ActiveRecord`. The class `Book` \nneeds to implement two methods: tableName() and dbConnection().\n\n#### Example\n\n```php\nuse micro\\db\\ActiveRecord;\n\nclass Book extends ActiveRecord {\n    \n    public static function tableName() \n    {\n        return 'book';\n    }\n    \n    public static function dbConnection() \n    {\n        $servername = \"127.0.0.1\";\n        $username = \"root\";\n        $password = \"fullstack\";\n        $database = \"mysql\";\n        \n        return new \\micro\\db\\Connection($servername, $username, $password, $database);\n    }\n}\n```\n\nThen you can instantiate the class.\n\n#### Example\n\n```php\n// Create a new book\n$book = new Book();\n$book-\u003etitle('This is the title of my book');\n$book-\u003esave();\n\n// fetchs all books\n$books = Book::find()-\u003eall();\nforeach($books as $book) {\n    echo $book-\u003etitle;\n}\n\n// search for one book\n$condition = [\n    ['=', 'id', '1']\n];\n$book = Book::find()-\u003ewhere($condition)-\u003eone();\necho $book-\u003etitle\n```\n\n### The QueryBuilder Class\n\nThe queryBuilder class builds a Sql statement. \n\n#### Example\n\n```php\n$table = 'home';\n$qB = new \\micro\\db\\QueryBuilder();\n$columns = [\n    'id',\n    'name',\n    'address'\n];\n$sql = $qB-\u003eselect($columns)-\u003efrom($table)-\u003egetRawSql();\n```\n\nThe variable `$sql` is equal to the string \"SELECT `id`, `name`, `address` FROM `home`\".\n\n### Contribution\n\nFeel free to contribute! Just create a new issue or a new pull request.\n\n### License\n\nThis library is released under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcomilon%2Fmicro-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcomilon%2Fmicro-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcomilon%2Fmicro-db/lists"}