vakata/orm 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vakata/orm

Composer 安装命令:

composer require vakata/orm

包简介

An ORM implementation

关键字:

README 文档

README

Latest Version on Packagist Software License Build Status Scrutinizer Code Quality Code Coverage

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 vakata/orm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 863
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-29