vakata/orm
Composer 安装命令:
composer require vakata/orm
包简介
An ORM implementation
README 文档
README
A orm abstraction with support for various drivers.
Install
Via Composer
$ composer require vakata/orm
Usage
// first you need a database instance $db = new \vakata\database\DB('mysql://root@127.0.0.1/test'); // then you can create the manager object $manager = new \vakata\orm\Manager($db); // assuming there is a book table with a name column foreach ($manager->book() as $book) { echo $book->name . "\n"; } // you could of course filter and order foreach ($manager->book()->filter('year', 2016)->sort('name') as $book) { // iterate over the books from 2016 } // if using mySQL foreign keys are automatically detected // for example if there is an author table and the book table references it foreach ($manager->book() as $book) { echo $book->author->name . "\n"; } // you can solve the n+1 queries problem like this foreach ($manager->fromQuery($db->book()->with('author')) as $book) { echo $book->author->name . "\n"; } // provided there is a linking table book_tag and a tag table and each book has many tags you can do this foreach ($manager->book()->with('author') as $book) { echo $book->tag[0]->name . "\n"; // the name of the first tag which the current book has } // which means you can do something like this echo $manager->book()[0]->author->book[0]->tag[0]->book[0]->author->name; // as for removing objects $authors = $manager->author(); $author = $authors[0]; $authors->remove($author); // you can also create new objects $book = new \StdClass(); $book->name = 'Test'; $manager->books()->add($book); // you can also use your own classes // just make sure you provide getters and setters for all table columns and relations class Author { protected $data = []; public function __get($key) { return $this->data[$key] ?? null; } public function __set($key, $value) { $this->data[$key] = $value; } } $manager->registerGenericMapperWithClassName('author', Author::class); // you can also add custom mappers (check the docs) $author = $manager->author()[0]; // this is an Author instance // as for changing objects // one way is to do it manually $authors = $manager->author(); $author = $authors[0]; $author->name = "Test"; $manager->getMapper('author')->update($author); // or use the unit of work manager and have all changes automatically saved $manager = new \vakata\orm\UnitOfWorkManager($db, new \vakata\orm\UnitOfWork($db)); $book = new Book(); $book->name = "Book name"; $book->author = $manager->author()->find(1); $tag = new Tag('tag'); $book->tags = $tag; $book->author->name = "Changed name"; $manager->books()->add($book); $manager->tags()->add($tag); // all you need to do is call this line $manager->save();
Read more in the API docs
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email github@vakata.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
vakata/orm 适用场景与选型建议
vakata/orm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 863 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「vakata」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vakata/orm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vakata/orm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vakata/orm 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A random int / string / byte generator
Kinikit - PHP Application development framework MVC component
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
A simple PHP IDS based on Expose / PHPIDS rules
PHP authentication library
A PHP user class
统计信息
- 总下载量: 863
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-29