Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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 (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T10:40:31.000Z (over 5 years ago)
- Last Synced: 2024-10-30T14:42:36.671Z (about 1 month ago)
- Topics: hydration, mongodb, mongodb-odm, persistence, php
- Language: PHP
- Homepage:
- Size: 109 KB
- Stars: 85
- Watchers: 7
- 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.
[![Build Status](https://travis-ci.org/formapro/values.png?branch=master)](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