Releases: rkrx/php-mysql-query-builder
Releases · rkrx/php-mysql-query-builder
The definition of a virtual table can now be set as a closure
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');Added Support for Virtual Tables
You can now use virtual tables, which are basically just sub-selects referenced by a identifier.
First define virtual tables somewhere in your bootstrap:
use Kir\MySQL\Databases\MySQL;
$db = new MySQL($pdo);
$vt1 = $db->select()
->field('a.field1')
->from('a', 'tableA');
$vt2 = $db->select()
->field('a.field1')
->from('a', 'tableA');
$db->getVirtualTables()->add('virt_table1', $vt1);
$db->getVirtualTables()->add('virt_table2', $vt2);Then use it as needed:
$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');Fixed various problems introduced after last release
- Fixed various problems with default parameters after last release
- Fixed
MySQL::dryRunwhere PHP7-\Errors caused rollbacks on transactions - Fixed
MySQL::transactionwhere tries were not handled correctly
Fixed exception-handling and PHPDocs
- Fixed Exception-Handling (Replaced \Exception with more appropriate \RuntimeException)
- Fixed various PHPDocs
Various changes
- Added
$optionsas the second parameter toMySQL::__constructto specify global behavior - Added the ability to set user defined factories for the SIUD-Query-Builders
- Added
$options-Parameter'select-options' > 'preserve-types-default' - Added
$options-Parameter'select-options' > 'fetch-object-class-default'forfetchObject* - Look at the README.md/initialization for more information
RunnableSelect::fetchObject*: Added default-value 'stdClass' for $className
RunnableSelect: Added default-value for$classNameto 'stdClass' for the methodsfetchObject,fetchObjectsandfetchObjectsLazy
PHPDoc now shows that WHERE and HAVING can handle arrays
- Fixed PHPDoc for
WHEREandHAVINGto clarify the possibility to pass arrays as the first parameter
Added a way to define OrderBy by external parameters
- Added
OrderBySpecification - Added a way to define OrderBy by external parameters
$_GET['sort'] = [['field2', 'ASC'], ['field1', 'DESC'], ['field3' => 'ASC']];
echo $db
->field('t.field1')
->field('t.field2')
->from('t', 'test')
->orderBy(new DBExprOrderBySpec(['field1', 'field2' => 'REVERSE(t.field2)'], $_GET['sort']))
->asString();SELECT
t.field1,
t.field2
FROM
test t
ORDER BY
REVERSE(t.field2) ASC,
field1 DESC
Table-Names can now also be arrays
Now you can do this:
$select
->field('a.a')
->field('b.b')
->from('a', [['a' => 1, 'b' => 3], ['a' => 2, 'b' => 2], ['a' => 3, 'b' => 1]])
->joinInner('b', [['a' => 1, 'b' => 3], ['a' => 2, 'b' => 2], ['a' => 3, 'b' => 1]])
Which will result in this:
SELECT
a.a,
b.b
FROM
(SELECT '1' AS `a`, '3' AS `b`
UNION
SELECT '2' AS `a`, '2' AS `b`
UNION
SELECT '3' AS `a`, '1' AS `b`) a
INNER JOIN
(SELECT '1' AS `a`, '3' AS `b`
UNION
SELECT '2' AS `a`, '2' AS `b`
UNION
SELECT '3' AS `a`, '1' AS `b`) b