makasim/yadm
Composer 安装命令:
composer require makasim/yadm
包简介
The fastest MongoDB object document mapper.
README 文档
README
The schema less ODM. It gives you the fastest hydration and persistent. Based on formapro/values lib.
Install
$ composer require makasim/yadm
Storage example
Let's say we have an order model:
<?php namespace Acme; use function Formapro\Values\set_value; use function Formapro\Values\get_value; class Price { private $values = []; public function setCurrency(string $value): void { set_value($this, 'currency', $value); } public function getCurrency(): string { return get_value($this, 'currency'); } public function setAmount(int $value): void { set_value($this, 'amount', $value); } public function getAmount(): string { return get_value($this, 'amount'); } }
<?php namespace Acme; use function Formapro\Values\set_value; use function Formapro\Values\get_value; use function Formapro\Values\set_object; use function Formapro\Values\get_object; class Order { private $values = []; public function setNumber(string $number): void { set_value($this, 'number', $number); } public function getNumber(): string { return get_value($this, 'number'); } public function setPrice(Price $price): void { set_object($this, 'price', $price); } public function getPrice(): Price { return get_object($this, 'price', Price::class); } }
<?php namespace Acme; use MongoDB\Client; use Formapro\Yadm\Hydrator; use Formapro\Yadm\Storage; $collection = (new Client())->selectCollection('acme_demo', 'orders'); $hydrator = new Hydrator(Order::class); $storage = new Storage($collection, $hydrator); $price = new Price(); $price->setAmount(123); # 1.23 USD $price->setCurrency('USD'); $order = new Order(); $order->setNumber(1234); $order->setPrice($price); $storage->insert($order); $foundOrder = $storage->find(['_id' => get_object_id($order)]); $foundOrder->setNumber(4321); $storage->update($foundOrder); $storage->delete($foundOrder);
MongoDB special types usage
<?php namespace Acme; use MongoDB\Client; use Formapro\Yadm\Hydrator; use Formapro\Yadm\Storage; use Formapro\Yadm\ConvertValues; use Formapro\Yadm\Type\UuidType; use Formapro\Yadm\Type\UTCDatetimeType; use Formapro\Yadm\Uuid; use function Formapro\Values\set_value; use function Formapro\Values\get_value; $convertValues = new ConvertValues([ 'id' => new UuidType(), 'createdAt' => new UTCDatetimeType(), ]); $collection = (new Client())->selectCollection('acme_demo', 'orders'); $hydrator = new Hydrator(Order::class); $storage = new Storage($collection, $hydrator, null, null, $convertValues); $order = new Order(); set_value($order, 'id', Uuid::generate()->toString()); set_value($order, 'createdAt', (new \DateTime())->format('U')); $storage->insert($order); $id = get_value($order, 'id'); // find by uuid $anotherOrder = $storage->findOne(['id' => new Uuid($id)]); // do not update id if not changed $storage->update($anotherOrder); // update on change set_value($anotherOrder, 'id', Uuid::generate()->toString()); $storage->update($anotherOrder);
Other examples
In formapro/values repo you can find examples on how to build simple objects, object trees, hydrate and retrive data from\to object.
Benchmarks
Run tests
docker-compose up -d
docker-compose exec yadm ./bin/phpunit
License
MIT
makasim/yadm 适用场景与选型建议
makasim/yadm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.65k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mongodb」 「storage」 「odm」 「model」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 makasim/yadm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 makasim/yadm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 makasim/yadm 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates Symfony2 documents, forms and CRUD
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
Knit ties your PHP objects with your database of choice in a simple way.
Xenus integration for the Laravel and Lumen frameworks
A package to allow laravel/passport use with mongodb/laravel-mongodb
统计信息
- 总下载量: 7.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 14
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-11