public function testFullFluency() { $expected = array('bob' => 'hoskins', 'abc' => 12); $query = new Morph_Query(); $query->limit(10)->skip(12)->property('bob')->equals('hoskins')->property('abc')->equals(12); $this->assertEquals($expected, $query->getRawQuery()); $this->assertEquals(10, $query->getLimit()); $this->assertEquals(12, $query->getSkip()); }
<?php //Create and instance of Morph_Storage passing in the appropriate database $mongo = new Mongo(); $storage = new Morph_Storage($mongo->selectDb('myDB')); //Find a maximum of 10 users that has more than 15 posts, skipping the first 10 $query = new Morph_Query(); $query->limit(10)->skip(10)->property('numberOfPosts')->greaterThan(15); $users = $storage->findByQuery(new User(), $query);
<?php //Initialise Morph_Storage passing in the appropriate database $mongo = new Mongo(); Morph_Storage::init($mongo->selectDb('myDB'));; //Find users with the userName = j.d.moss $user = new User(); $query = new Morph_Query(); $query->property('userName')->equals('j.d.moss'); $users = $user->findByQuery($query);
/** * @return int */ public function getLimit() { return $this->query->getLimit(); }
/** * Loads the stored references * @return void */ private function loadFromReferences() { $ids = array(); foreach ($this->References as $reference) { $ids[] = $reference['$id']; } $query = new Morph_Query(); $query->property('_id')->in($ids); $object = new $this->Type(); //@todo this could get nasty with large collections! $this->Value = $this->Storage->findByQuery($object, $query)->toCollection(); $this->Loaded = true; }
<?php //Create and instance of Morph_Storage passing in the appropriate database $mongo = new Mongo(); $storage = new Morph_Storage($mongo->selectDb('myDB')); $query = new Morph_Query(); $query->property('createdDate')->greaterThan(MongoDate(time() - 604800))->lessThan(new MondoDate(time()))->property('cost')->greaterThanOrEqualTo(12.99)->property('publisher')->in(array('publisherA', 'publisherB', 'publisherC')); /** * This query is roughly equivalent to the sql: * SELECT * FROM `ABook` WHERE * `createdDate` > DATE_SUB(now(), INTERVAL 1 WEEK) * AND `createdDate` < now() * AND `cost` >= 12.99 * AND `publisher` in ('publisherA', 'publisherB', 'publisherC'); */ $users = $storage->findByQuery(new A_Book(), $query);
/** * Adds a new property * * @param string $propertyName * @return Morph_Query_Property */ public function property($propertyName) { return $this->query->property($propertyName); }
<?php //Create and instance of Morph_Storage passing in the appropriate database $mongo = new Mongo(); $storage = new Morph_Storage($mongo->selectDb('myDB')); //Find users with the userName = j.d.moss $query = new Morph_Query(); $query->property('userName')->equals('j.d.moss'); $users = $storage->findByQuery(new User(), $query);
/** * Returns all objects with an _id in $ids * * @param Morph_Object $object * @param array $Ids * @return Morph_Iterator */ public function fetchByIds(Morph_Object $object, array $ids) { $query = new Morph_Query(); $query->property('_id')->in($ids); return $this->findByQuery($object, $query); }
<?php //Initialise Morph_Storage passing in the appropriate database $mongo = new Mongo(); Morph_Storage::init($mongo->selectDb('myDB')); $query = new Morph_Query(); $query->property('createdDate') ->greaterThan(MongoDate(time() - 604800)) //last week ->lessThan(new MondoDate(time())) //today ->property('cost') ->greaterThanOrEqualTo(12.99) ->sort(Morph_Enum::DIRECTION_ASC) ->property('publisher') ->in(array('publisherA', 'publisherB', 'publisherC')); /** * This query is roughly equivalent to the sql: * SELECT * FROM `ABook` WHERE * `createdDate` > DATE_SUB(now(), INTERVAL 1 WEEK) * AND `createdDate` < now() * AND `cost` >= 12.99 * AND `publisher` in ('publisherA', 'publisherB', 'publisherC') * ORDER BY `cost`; */ $book = new A_Book(); $books = $book->findByQuery($query);
<?php //Initialise Morph_Storage passing in the appropriate database $mongo = new Mongo(); Morph_Storage::init($mongo->selectDb('myDB')); //Find a maximum of 10 users that has more than 15 posts, skipping the first 10 $user = new User(); $query = new Morph_Query(); $query->limit(10) ->skip(10) ->property('numberOfPosts') ->greaterThan(15); $users = $user->findByQuery($query);