auraphp / Aura.SqlQuery

Independent query builders for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server.
MIT License
452 stars 86 forks source link

CTEs #130

Open mathroc opened 7 years ago

mathroc commented 7 years ago

Hi,

now that mysql will support WITH queries too, is there plan to add support for Common Table Expressions ?

maybe something along those lines :

$select = $query_factory->newSelect();

$cte = $query_factory->newSelect();
$cte->cols('zim')->from('table2');

$select->with('cte1', $cte);

$select->cols(array('foo', 'bar AS barbar'))
       ->from('table1')
       ->from('cte1')
       ->where('cte1.zim = 99');
pmjones commented 7 years ago

This is an excellent idea. It may mess up Atlas.Orm, which uses with() to eager-load relationships -- but since Atlas is alpha, it can change to use eager() or something like that instead of the WITH keyword.

@mathroc send along a PR as soon as you can, for the databases that support WITH, and I'll review!