Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

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