Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 541 Bytes

using-with-recursive-sql-command.md

File metadata and controls

23 lines (19 loc) · 541 Bytes

Using With Recursive SQL Command

<?php
$recursive = \ByJG\MicroOrm\Recursive::getInstance('test')
    ->field('start', 1, 'start + 10')
    ->field('end', 120, "end - 10")
    ->where('start < 100')
;

$query = \ByJG\MicroOrm\Query::getInstance()
    ->withRecursive($recursive)
    ->fields(['start', 'end']);

/*
This will produce the following SQL:

WITH RECURSIVE test(start, end) AS (
    SELECT 1 as start, 120 as end
    UNION ALL SELECT start + 10, end - 10 FROM test WHERE start < 100
) SELECT start, end FROM test
*/