2017 © Pedro Peláez
 

library ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

image

rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  • Thursday, August 6, 2015
  • by rogerthomas84
  • Repository
  • 2 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

View on Packagist, (*2)

OhDM

OhDM is a an ODM which is a simple PHP library that eases the pain of interacting with MongoDB., (*3)

Stability

OhDM is a new project, so some things won't work as expected. It's classified right now as in the early stages, and there is a version 1.0.0 which we're classing as stable., (*4)

Saying that, things will be introduced to help enhance the library further but it'll be versioned accordingly., (*5)

Help Out

The easiest way to help is by forking and raising a PR. All I ask is that you contribute changes back to this repository., (*6)

Changes won't be merged unless you've tested (and written tests) for the changes made. We also strive for high test coverage., (*7)

Right now, we're sitting at 99.33% coverage, and we would really like to stay around there., (*8)

Quick Start

To get started quickly, first you're going to need to setup the configuration object. It's a singleton., (*9)

<?php
Config::init(
    new \MongoClient(
        'mongodb://127.0.0.1',
        array('connect' => false)
    ),
    'pets' // The database name
);

Now you'll need a Collection model. Something like this:, (*10)

<?php
namespace My\Namespace\Name;

use OhDM\Collection;

class Cats extends Collection
{
    public $name = null;

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }
}

Introduction to Queries

Create a document

<?php
$record = new Cats();
$record->setName('fuzzy');
$record->save();

Find By ID

The quickest form of find is when you know an objects _id. OhDM exploits this and implements a quick and easy way to locate them., (*11)

<?php
$record = Cats::findById(
    new \MongoId('53466f2978f7a8bc5c1ae933')
);
if ($record) {
    // $record is instance of Cats
    echo 'My cats name is: ' . $record->getName();
} else {
    // couldn't find it!
}

Find By Query

OhDM supports finding documents by advanced querying which will also return the item in object form. Spoiler alert: it's as easy as it looks below!, (*12)

<?php
$command = array(
    'query' => array('name' => 'kitty'),
    'fields' => array(),
    'skip' => 0,
    'limit' => 100,
    'sort' => array(
        'name' => 1
    )
);
$ohDmCursor = Cats::find($command);
while ($ohDmCursor->hasNext()) {
    $thisCat = $ohDmCursor->getNext(); // it's an instance of Cats
}

Delete

Delete can be called on any saved document and it will be removed from the database., (*13)

<?php
$record = Cats::findById(
    new \MongoId('53466f2978f7a8bc5c1ae933')
);
$record->delete();

Update

As it's an object, just alter the variables and call save() against it., (*14)

<?php
$record = Cats::findById(
    new \MongoId('53466f2978f7a8bc5c1ae933')
);
if ($record) {
    // $record is instance of Cats
    echo 'My cats name was: ' . $record->getName();

    $record->setName('kitty');
    $record->save();

    echo 'My cats name is now: ' . $record->getName();

} else {
    // couldn't find it!
}

The Versions

06/08 2015

dev-master

9999999-dev https://github.com/rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

odm object document mapper ohdm

06/08 2015

dev-release-1.1.0

dev-release-1.1.0 https://github.com/rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

odm object document mapper ohdm

06/08 2015

1.1.0

1.1.0.0 https://github.com/rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

odm object document mapper ohdm

29/05 2014

dev-develop

dev-develop https://github.com/rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-mongo >=1.5.1

 

odm object document mapper ohdm

12/04 2014

dev-release-1.0.1

dev-release-1.0.1 https://github.com/rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-mongo >=1.5.1

 

odm object document mapper ohdm

12/04 2014

1.0.1

1.0.1.0 https://github.com/rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-mongo >=1.5.1

 

odm object document mapper ohdm

11/04 2014

dev-release-1.0.0-alpha

dev-release-1.0.0-alpha https://github.com/rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

odm object document mapper ohdm

11/04 2014

1.0.0-alpha

1.0.0.0-alpha https://github.com/rogerthomas84/ohdm

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

odm object document mapper ohdm