expression() public method

Create new Expression instance to use in query builder or update operations
public expression ( ) : Expression
return Expression
Example #1
0
 public function testDelete()
 {
     // insert
     $this->collection->batchInsert(array(array('a' => 1), array('a' => 2), array('a' => 3), array('a' => 4), array('a' => 5), array('a' => 6)));
     // delete
     $batch = new BatchDelete($this->collection);
     $batch->delete(array('a' => 2))->delete($this->collection->expression()->where('a', 4))->delete(function (Expression $e) {
         $e->where('a', 6);
     })->execute();
     // test
     $result = $this->collection->findAsArray()->sort(array('a' => 1))->map(function ($data) {
         unset($data['_id']);
         return $data;
     });
     $this->assertEquals(array_values($result), array(array('a' => 1), array('a' => 3), array('a' => 5)));
 }
Example #2
0
 public function testGetDistinct_ExpressionObject()
 {
     $this->collection->createDocument(array('k' => array('f' => 'F1', 'kk' => 'A')))->save();
     $this->collection->createDocument(array('k' => array('f' => 'F1', 'kk' => 'A')))->save();
     $this->collection->createDocument(array('k' => array('f' => 'F1', 'kk' => 'B')))->save();
     $this->collection->createDocument(array('k' => array('f' => 'F2', 'kk' => 'C')))->save();
     // get distinkt
     $distinctValues = $this->collection->getDistinct('k.kk', $this->collection->expression()->where('k.f', 'F1'));
     $this->assertEquals(array('A', 'B'), $distinctValues);
 }
Example #3
0
 public function testPullFromThreeDimensionalUsingExpressionInValue()
 {
     $this->collection->delete();
     // create document
     $doc = $this->collection->createDocument(array('some' => array(array('sub' => array(array('a' => 1), array('b' => 2))), array('sub' => array(array('a' => 3), array('b' => 4))))));
     $doc->save();
     // push array to array
     $doc->pull('some', $this->collection->expression()->where('sub.a', 1));
     $doc->save();
     $this->assertEquals(array(array('sub' => array(array('a' => 3), array('b' => 4)))), $this->collection->getDocument($doc->getId())->some);
 }