Skip to content

The definition of a virtual table can now be set as a closure

Pre-release
Pre-release
Compare
Choose a tag to compare
@rkrx rkrx released this 02 Nov 11:13
· 112 commits to master since this release

The definition of a virtual table can now be set as a closure, which is lazy evaluated:

use Kir\MySQL\Databases\MySQL;

$db = new MySQL($pdo);

$vt1 = $db->select()
->field('a.field1')
->from('a', 'tableA');

$db->getVirtualTables()->add('virt_table1', $vt1);

// Lazy evaluated
$db->getVirtualTables()->add('virt_table2', function () {
	return $db->select()
	->field('a.field1')
	->from('a', 'tableA');
});
$query = $db->select()
->field('t.field1')
->field('vt1.fieldN')
->field('vt2.fieldN')
->from('t', 'test')
->joinInner('vt1', 'virt_table1', 'vt1.field1=t.field1')
->joinInner('vt2', 'virt_table2', 'vt2.field2=t.field2');