Example #1
0
 public function testRead()
 {
     $db = $this->getDb();
     $table = new SqlTable($db, 'Foo');
     // Select all
     $selection = new ReadSelectionBuilder($table);
     $db->expects($this->exactly(7))->method('query')->withConsecutive([$this->equalTo('SELECT {Foo}.* FROM {Foo}')], [$this->equalTo('SELECT {Foo}.* FROM {Foo} WHERE group = "user" ORDER BY name DESC')], [$this->equalTo('SELECT {Foo}.* FROM {Foo} GROUP BY group, name HAVING name IN ("foo", "bar", "foobar")')], [$this->equalTo('SELECT {Foo}.* FROM {Foo} LIMIT 10 OFFSET 5')], [$this->equalTo('SELECT f.* FROM {Foo} AS f LEFT JOIN {Foo} AS o ON f.id = o.id')], [$this->equalTo('SELECT DISTINCT a FROM {Foo}')], [$this->equalTo('SELECT {Foo}.*, 2 + 2 AS ans FROM {Foo}')])->willReturn($this->getMockBuilder('Jivoo\\Data\\Database\\ResultSet')->getMock());
     $selection->toArray();
     // Select with a predicate and ordering
     $selection->where('group = "user"')->orderByDescending('name')->toArray();
     // Select with groups
     $selection->groupBy(['group', 'name'], E::e('name IN %s()', ['foo', 'bar', 'foobar']))->toArray();
     // Select with limit and offset
     $selection->limit(10)->offset(5)->toArray();
     // Select with join and alias
     $selection->alias('f')->leftJoin($table, 'f.id = o.id', 'o')->toArray();
     // Select with projection and distinct
     $selection->distinct()->select('a');
     // Select with additional fields
     $selection->with('ans', '2 + 2')->toArray();
 }
Example #2
0
 /**
  * Set alias for selection source.
  *
  * @param string $alias
  *            Alias.
  * @return ReadSelectionBuilder A read selection.
  */
 public function alias($alias)
 {
     $selection = new ReadSelectionBuilder($this->getSource());
     return $selection->alias($alias);
 }