2017 © Pedro Peláez
 

library yadm

The fastest MongoDB object document mapper.

image

makasim/yadm

The fastest MongoDB object document mapper.

  • Tuesday, July 24, 2018
  • by makasim
  • Repository
  • 8 Watchers
  • 77 Stars
  • 2,124 Installations
  • PHP
  • 3 Dependents
  • 1 Suggesters
  • 4 Forks
  • 1 Open issues
  • 20 Versions
  • 17 % Grown

The README.md

Yadm is the fastest MongoDB ODM.

Build Status, (*1)

The schema less ODM. It gives you the fastest hydration and persistent. Based on formapro/values lib., (*2)

Install

$ composer require makasim/yadm

Storage example

Let's say we have an order model:, (*3)

<?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., (*4)

Benchmarks

Run tests

docker-compose up -d
docker-compose exec yadm ./bin/phpunit 

License

MIT, (*5)

The Versions

24/07 2018

dev-master

9999999-dev

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

13/07 2018

0.4.0

0.4.0.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

11/06 2018

dev-meta

dev-meta

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

20/02 2018

0.3.12

0.3.12.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

02/02 2018

0.3.11

0.3.11.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

02/02 2018

0.3.10

0.3.10.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

02/02 2018

0.3.9

0.3.9.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

02/02 2018

dev-fetch-database-from-dsn

dev-fetch-database-from-dsn

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

25/10 2017

0.3.8

0.3.8.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

20/10 2017

0.3.7

0.3.7.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

22/03 2017

0.3.6

0.3.6.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

20/03 2017

0.3.5

0.3.5.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

20/03 2017

0.3.4

0.3.4.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

13/03 2017

0.3.3

0.3.3.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

13/03 2017

0.3.2

0.3.2.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

13/03 2017

0.3.1

0.3.1.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

03/03 2017

0.2.0

0.2.0.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

03/03 2017

0.3.0

0.3.0.0

The fastest MongoDB object document mapper.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksym Kotliar

mongodb model odm storage

06/02 2017

0.2.x-dev

0.2.9999999.9999999-dev

The fastest object document mapper. Supports MongoDB

  Sources   Download

MIT

The Requires

  • php ^5.5.0|^7.0

 

The Development Requires

by Maksim Kotlyar

mongodb model odm storage

10/02 2016

0.1.0

0.1.0.0

Yadm is a MongoDB ODM. Schema less. Fast object hydration and persistence.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Maksim Kotlyar

mongodb model