https://github.com/formapro/yadm
An efficient way to treat MongoDB in PHP. Extremely fast persistence and hydration.
https://github.com/formapro/yadm
hydration mongodb mongodb-odm persistence php
Last synced: 5 months ago
JSON representation
An efficient way to treat MongoDB in PHP. Extremely fast persistence and hydration.
- Host: GitHub
- URL: https://github.com/formapro/yadm
- Owner: formapro
- License: mit
- Created: 2015-12-10T17:18:39.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T10:40:31.000Z (over 6 years ago)
- Last Synced: 2025-04-07T22:05:22.931Z (7 months ago)
- Topics: hydration, mongodb, mongodb-odm, persistence, php
- Language: PHP
- Homepage:
- Size: 109 KB
- Stars: 85
- Watchers: 6
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mongodb - yadm - Fast schemaless ODM (Libraries / PHP)
- awesome-mongodb - yadm - Fast schemaless ODM (Libraries / PHP)
README
# Yadm is the fastest MongoDB ODM.
[](https://travis-ci.org/formapro/yadm)
The schema less ODM. It gives you the fastest hydration and persistent. Based on [formapro/values](https://github.com/formapro/values) lib.
## Install
```bash
$ composer require formapro/yadm "mikemccabe/json-patch-php:dev-master as 0.1.1"
```
## Storage example
Let's say we have an order model:
```php
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
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](https://github.com/formapro/values) repo you can find examples on how to build simple objects, object trees, hydrate and retrive data from\to object.
## Benchmarks
* [Results](https://docs.google.com/spreadsheets/d/1CzVQuAz6cVAUKZyoQZyagQv48mgA3JAYJ2dNsoALV7A/edit#gid=0)
* [Code](https://github.com/makasim/yadm-benchmark)
## License
MIT